I made a package that caches stuff (robust-externalize) and my goal now is to compile automatically many images into a single document to save the loading time of the preamble during the first compilation. So I was planning to write in a file something like:
\documentclass[varwidth,margin=5mm]{standalone}
\usepackage{tikz}
\usepackage{amsmath}
\NewDocumentEnvironment{robExtNewPage}{}{}{}
\standaloneenv{robExtNewPage}
\begin{document}
\begin{robExtNewPage}
\gdef\test{I should be removed after this page}
\begin{minipage}{1.0\linewidth}
\begin{align}
1+1
\end{align}
\end{minipage}
\end{robExtNewPage}
\begin{robExtNewPage}
This should give an error:
\test
See, equations are also not correctly numbered (I want to reset the number):\
\fbox{\begin{minipage}{1.0\linewidth}
\begin{align}
1+3
\end{align}
\end{minipage}}
\end{robExtNewPage}
\end{document}
where each image is inside robExtNewPage. This should work more or less as expected, but I would like to enforce purity as much as possible, and in particular I do not want stuff from image 1 to leak to image 2, or I would get non-deterministic results. So is it possible to save the state at the end of \begin{document}, and restore it at the beginning of any robExtNewPage, so it is (more or less) impossible to signal between images? I guess that local variables are automatically reset, so I guess my question concerns rather the global variables/macros.
\gdefinside the environment, but the reason to use\gdefis precisely to make the definition global, so doing so will result in unexpected behaviour (from the user's perspective). [I hope redefining\gdefis an obviously bad idea but, in case it isn't, it is a bad idea.] – cfr Sep 19 '23 at 02:37\gdef. Actually, I don't mind to change a bit the context (of course we need to save the saved state), but in a minimal way. Or is it maybe possible (outside of the latex code), to run an interactivepdflatexthat save its internal state right after the preamble, and gets as input some stuff to typeset and typeset them with that same state at every request? I remember web-tikz to do something like that, but in a browser. – tobiasBora Sep 19 '23 at 10:02set placeholder eval={__thepage__}{\thepage}: in that case the picture will be rebuilt only of the current page changes. – tobiasBora Sep 19 '23 at 10:07\globaldefsis relevant here, but be careful with that register. – Udi Fogiel Sep 19 '23 at 12:57\refstepcounterfor a counter used later in the document? I don't see what resetting the value of the counter gets you except a problem. That is, what problem are you trying to solve? What 'impurities' are you concerned about? – cfr Sep 19 '23 at 23:05hashofpicture-out.tex(cf\writeRobExt{}) the latex code to change the value, with something like:\immediate\write\writeRobExt{\string\refstepcounter{somecounter}}: this file will be automatically loaded before including the pdf file (cf doc section 3.9). We use for instance this to know the depth of the picture to include it properly. – tobiasBora Sep 19 '23 at 23:32