The explicit code
\documentclass{standalone}
\usepackage[french]{babel}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{babel}
\begin{document}
\begin{tikzpicture}
\begin{semilogxaxis}[
xmin=1e-1,
xmax=1e4,
ymin=0,
ymax=1
]
\draw[thick,blue,dashed] (axis cs:1,0) -- (axis cs:100,1);
\end{semilogxaxis}
\end{tikzpicture}
\end{document}
works but if I use a new environment, it fails to compile
\documentclass{standalone}
\usepackage{pgfplots,environ}
\usepackage[french]{babel}
\usetikzlibrary{babel}
\pgfplotsset{compat=1.18}
\NewEnviron{MyEnv}[3][]{
\begin{tikzpicture}
\begin{semilogxaxis}[
xmin={#2},
xmax={#3},
ymin=0,
ymax=1
]
\BODY
\end{semilogxaxis}
\end{tikzpicture}
}
\begin{document}
\begin{MyEnv}[]{1e-1}{1e4}
\draw[thick,blue,dashed] (axis cs:1,0) -- (axis cs:100,1);
\end{MyEnv}
\end{document}
The second example compiles correctly if I comment out the babel package.
Any ideas on how to fix this? The shorthandoff suggestions in answers to other similar questions do not seem to work here.
bodeplotpackage a while ago, and at the time, I could not figure out how to handle the argument macros correctly using the usual\newenvironmentcommand. I was able to get it to work using\newenvironfrom theenvironpackage.The functionality I wanted was the ability to pass
– Rushi Jan 10 '24 at 23:24tikzcommands andpgfkeys to environments inside the newly created environment. For example, write something like\begin{MyEnv}[tikz/{},axes/{}]...and pass thetikzoptions totikzpictureandaxesoptions toaxis. I got that to work using\newenviron.environ,unfortunately, I am better at control theory than LaTeX :-) I'll try to rewrite my package again withoutenviron,but just wanted to see if anyone has any quick fixes in the meantime... – Rushi Jan 11 '24 at 03:01environto get externalization to work right. I followed this answer that suggested theenvironpackage – Rushi Jan 11 '24 at 06:24\AddToHook{env/MyEnv/begin}{\shorthandoff{;}}. Btw: the environ package is no longer needed, a current LaTeX has the functionality in-built.\NewDocumentEnvironment{MyEnv}{omm+b}{...}{}. Use#4instead of\BODYin the content. – Ulrike Fischer Jan 11 '24 at 09:12\NewDocumentEnvironment{MyEnv}{O{}mm}{\begin{tikzpicture}\begin{semilogxaxis}[xmin={#2},xmax={#3},ymin=0,ymax=1]}{\end{semilogxaxis}\end{tikzpicture}, no need to grab the contents. – Skillmon Jan 11 '24 at 11:06AddToHookwithNewDocumentEnvironmentworks like a charm. A question if you do not mind. I thought instead ofAddToHook, I could passhandle active characters in codeto thetikzpictureenvironment. That did not work, but I do not understand why. Could you help me understand? I tried thetikzkey so that the user will still be able to use French text inside node labels and such. I assume if I useAddToHook, then all semicolons in the entire environment can no longer be modified bybabel? – Rushi Jan 11 '24 at 17:23externallibrary. Using an empty{}for the fourth argument and adding the body contents along with the environment end commands to the third argument ofNewDocumentEnvironment, like @UlrikeFischer suggested, solves issues with externalization. – Rushi Jan 11 '24 at 17:30