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 -----------------------------------------------------------------