ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* placefigure, usetikzlibrary and readfile
       [not found] <2124563290.2578631.1627849624292.ref@mail.yahoo.com>
@ 2021-08-01 20:27 ` Jigé via ntg-context
  2021-08-02  7:02   ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 2+ messages in thread
From: Jigé via ntg-context @ 2021-08-01 20:27 UTC (permalink / raw)
  To: ntg-context; +Cc: Jigé

Hello all.

It seems that \usetikzlibrary is sometimes read, sometimes not, and I don't understand why. 

Rationale:

I would like, using one file, to use it to produce a picture, as with LaTeX's Standalone class,
but to be able to include it in a calling document as well, for better management of fonts, etc.
Thus this is most convenient. I have everything in the main document and I can quickly reuse any figure elsewhere.


What I did:

I use \readfile in a main ConTeXt file document.tex to include the file included.tex .
The file included.tex should contain *just* the TikZ picture and what is needed to compile it "standalone".


The issue:

It seems I can call the file with the TikZ picture description multiple times, with \readfile,
from within the very same \placefigure.

However, if I call it by using two successive \placefigure commands,
the \usetikzlibrary[blabla] in the included file doesn't seem to be recognised.
E.g. with the provided example below, the key "right angle" is not understood, as if \usetikzlibrary[angles] was not there.

One workaround would be to use \usetikzlibrary[allTheLibrariesISupposeMightEverBeNeeded]
in the calling file. But I don't like it. I would rather have only the TikZ libraries relevant to some picture included in the corresponding file.

I'm quite startled by the fact that :
  >  \placefigure[here][]{This is a figure}{
  >    \readfile{included}{}{File not found.}
  >    \readfile{included}{}{File not found.}
  >  }
compiles but
  >  \placefigure[here][]{This is a figure}{
  >    \readfile{included}{}{File not found.}
  >  }
  >  \placefigure[here][]{This is a figure}{
  >    \readfile{included}{}{File not found.}
  >  }
does not.


All the best!


Example:

%%%% Begin document.tex

\usemodule[tikz]

\starttext

\usetikzlibrary[angles] % Doesn't compile if this is commented out.

%\placefigure[here][]{This is a figure}{
%  \readfile{included}{}{File not found.}
%  \readfile{included}{}{File not found.}
%}

\placefigure[here][]{This is a figure}{
  \ReadFile{included}{}
}
\placefigure[here][]{This is a figure}{
  \ReadFile{included}{}
}

\stoptext
%%%% End document.tex

%%%% Begin included.tex
\usemodule[tikz]
\usetikzlibrary[angles]
%\doifnotmode{*text,*bodypart}{ \startTEXpage[fit] }
\doifnotmode{*text,*bodypart}{ \startTEXpage[fit] \usemodule[tikz] \usetikzlibrary[angles] }
\hbox{\starttikzpicture[]
  \draw[]
       (0,0) coordinate (A) node[left] {$A$}
    -- (4,0) coordinate (B) node[right] {$B$}
    -- (0,3) coordinate (C) node[left] {$C$}
    -- cycle
    pic [draw, angle radius=0.5cm] {right angle = B--A--C} ;
\stoptikzpicture}
\doifnotmode{*text,*bodypart}{ \stopTEXpage }
%%%% End included.tex

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: placefigure, usetikzlibrary and readfile
  2021-08-01 20:27 ` placefigure, usetikzlibrary and readfile Jigé via ntg-context
@ 2021-08-02  7:02   ` Hans Hagen via ntg-context
  0 siblings, 0 replies; 2+ messages in thread
From: Hans Hagen via ntg-context @ 2021-08-02  7:02 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Hans Hagen, Jigé

On 8/1/2021 10:27 PM, Jigé via ntg-context wrote:
> Hello all.
> 
> It seems that \usetikzlibrary is sometimes read, sometimes not, and I don't understand why.
> 
> Rationale:
> 
> I would like, using one file, to use it to produce a picture, as with LaTeX's Standalone class,
> but to be able to include it in a calling document as well, for better management of fonts, etc.
> Thus this is most convenient. I have everything in the main document and I can quickly reuse any figure elsewhere.
> 
> 
> What I did:
> 
> I use \readfile in a main ConTeXt file document.tex to include the file included.tex .
> The file included.tex should contain *just* the TikZ picture and what is needed to compile it "standalone".
> 
> 
> The issue:
> 
> It seems I can call the file with the TikZ picture description multiple times, with \readfile,
> from within the very same \placefigure.
> 
> However, if I call it by using two successive \placefigure commands,
> the \usetikzlibrary[blabla] in the included file doesn't seem to be recognised.
> E.g. with the provided example below, the key "right angle" is not understood, as if \usetikzlibrary[angles] was not there.
> 
> One workaround would be to use \usetikzlibrary[allTheLibrariesISupposeMightEverBeNeeded]
> in the calling file. But I don't like it. I would rather have only the TikZ libraries relevant to some picture included in the corresponding file.
> 
> I'm quite startled by the fact that :
>    >  \placefigure[here][]{This is a figure}{
>    >    \readfile{included}{}{File not found.}
>    >    \readfile{included}{}{File not found.}
>    >  }
> compiles but
>    >  \placefigure[here][]{This is a figure}{
>    >    \readfile{included}{}{File not found.}
>    >  }
>    >  \placefigure[here][]{This is a figure}{
>    >    \readfile{included}{}{File not found.}
>    >  }
> does not.
modules are loaded only once so you just have to call it in the main 
document (more efficient than reloading each time anyway)

loading some module inside a figure is actually problemantic because you 
can end up with a mix of global and local definitions depending on how a 
module is set up (and tikz being pretty large it might be that at some 
point you can expect problems, apart from loading taking time)

you can try to do \input {m-tikz.mlxl} or whatever but don't expect much 
help when there is an isseu due to multiple loading of tikz

if there's a lot of extra tikz stuff then you can put that in a privane 
module or environment (these are also loaded once) and load that one

if you use the project structure you can actually share environments and 
again these are then loaded once

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-02  7:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <2124563290.2578631.1627849624292.ref@mail.yahoo.com>
2021-08-01 20:27 ` placefigure, usetikzlibrary and readfile Jigé via ntg-context
2021-08-02  7:02   ` Hans Hagen via ntg-context

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).