Re: [NTG-context] placefigure, usetikzlibrary and readfile

2021-08-02 Thread Hans Hagen via ntg-context

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
___


[NTG-context] placefigure, usetikzlibrary and readfile

2021-08-01 Thread Jigé via ntg-context
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
___