0

for simple use I've written an environment wrapping the tikzpicture environment. So far no trouble. Now I realized I've got a huge amount of tikzpictures in my document and I've read once about tikz externalization, so I thought that would be a good idea. So I've got this code

\documentclass{article}

\usepackage{tikz}

% place in preamble and add "--shell-excape" to latex-run (for cluttex --shell-escape) \usetikzlibrary{external} \tikzexternalize[prefix=figures/] % activate and define figures/ as cache folder

\newenvironment{step}{ \newcommand{\myCmd}[1]{\node[draw] {##1};} \tikzpicture[] \scope[local bounding box=output] }{ \endscope \endtikzpicture }

\begin{document} \begin{step} \myCmd{lore ipsum} \end{step} \end{document}

which spits out

(/usr/share/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg)))
Runaway argument?

! File ended while scanning use of \tikzexternal@laTeX@collect@until@end@tikzpi cture. <inserted text> \par <*> main.tex

?

I think this ia related to 53.2 (Requirements) of the tikz manual. Is there a way for me to still use externalization but don't give up the simplicity of the environment declaration?

(on each picture I draw some nodes in the beginning, put all of the things from inside my step env in a tikz-scope and draw some nodes after the termination of the scope. Replacing all step-env occurrences with that declaration (which actually is always the same) would be ...unpleasant)

EDIT: Some way to e.g. use \begin{tikzpicture}[myTikz] which in turn will automatically put my things at the beginning/end of the tikzpicture content would suffice too, but I'm not sure if there's a way to do that with tikz.

Sebastiano
  • 54,118
atticus
  • 557
  • 1
    Not sure if there's an easier way, but there's always the way of grab the whole environment verbatim, transform it accordingly, then output the code of a tikzpicture environment again. Are you using LuaLaTeX? – user202729 Dec 10 '21 at 10:52
  • 1
    Or easier (to program, not to type) (but may or may not be acceptable depends on your use case), redefine/override the tikzpicture environment itself. – user202729 Dec 10 '21 at 11:02
  • Yes I'm indeed using LuaLaTeX. Is directlua expanded before the search for begin/endtikzpicture? (otherwise the problem of not having the literal begin/end tikzpicture statements would remain, at least from what I know of). – atticus Dec 10 '21 at 11:58
  • Redefining tikzpicture sounds a bit weird to be and has the big disadvantage of not being able to use the plain tikzpicture anymore so I'd try to avoid this. But when no other way works I'd be interested in this possibility as well. – atticus Dec 10 '21 at 11:59
  • 1
  • 1
    Okay, good thing that tikzpicture isn't verbatim. The answer linked in in the above does answer this question (in fact this question is a subset). – user202729 Dec 10 '21 at 12:16
  • Oh that looks just what I needed. Just one final question, what was the way you thought of which just works with LuaLaTeX? – atticus Dec 10 '21 at 12:28
  • 1
    Use the method linked previously https://tex.stackexchange.com/questions/361738/how-to-handle-verbatim-material-in-lualatex to grab the whole content of the environment verbatim, process it, then tex.sprint back. (not necessary in this case, but that would be the easiest one that works with verbatim or catcode-changing environments) – user202729 Dec 10 '21 at 12:29
  • Alright thanks for helping. So I think I'll mark this one a duplicate since I actually is the other question (which I didn't found on my own) – atticus Dec 10 '21 at 12:31
  • Took me quite some while, but I discovered that in my case the environ solution has the problem that the detection of change doesn't really work anymore (using the diff option of tikzexternal showed that only \begingroup \toks 0={macro:->[font=\scriptsize ] \scope [local bounding box=output] \BODY \endscope }\xdef \tikzexternallastkey {\the \toks 0 }\endgroup % is stored which makes kinda sense since the expansion in this stage is limited). So I decided to go with https://tex.stackexchange.com/questions/361738/how-to-handle-verbatim-material-in-lualatex (without this whole catcode stuff) – atticus Mar 11 '22 at 21:15
  • Oh and in that post I think there is an \ missing in "\noexpand\\EndVerbatim" (lua part) and an \noexpand missing in }% \EndVerbatim \printverbatim (tex part) – atticus Mar 11 '22 at 21:17

0 Answers0