In the bodeplot package, I defined new environments using (defined like this to avoid issues with externalization of tikz graphics)
\documentclass{standalone}
\usepackage{pgfplots,xparse}
\pgfplotsset{compat=1.18}
\NewDocumentEnvironment{MyEnv}{O{}mm+b}{
\begin{tikzpicture}
\begin{semilogxaxis}[xmin={#2},xmax={#3},ymin=0,ymax=1]
#4
\end{semilogxaxis}
\end{tikzpicture}
}{}
I want users to be able to use the new environment to do things like this
\begin{document}
\begin{MyEnv}[]{1e-1}{1e4}
\draw[thick,blue,dashed] (axis cs:1,0) -- (axis cs:100,1);
\addplot[variable=t,domain=1e-1:1e4] gnuplot {(t>100)?0.2:0.5};
\end{MyEnv}
\end{document}
All of this works out for English language documents. However, if a user uses babel with any language that makes some characters in #4 active, the document cannot be compiled. For example, if I add
\usepackage[french]{babel}
\usetikzlibrary{babel}
to the preamble, I get compilation errors.
I managed to make it work for the French language work by checking for frenchbsetup and using
\AddToHook{env/MyEnv/begin}{\shorthandoff{;:!?}}
if it is detected. However, doing something like this for every active character in every language seems like the wrong approach to solve this issue.
Is there a better way detect and manage active characters in macros like this that will work with all languages supported by babel?
bis functionally similar to the workaround suggested here to enable externalization. If there is a way to make the\NewDocumentEnvironment{MyEnv}{...}{\begin{tikzpicture}...} {...\end{tikzpicture}}syntax play nice with externalization, I am all for it! – Rushi Feb 03 '24 at 00:27\csname @safe@activestrue\endcsname. Or ask the babel maintainer to make the shorthands protected. – Ulrike Fischer Feb 03 '24 at 17:19\csname @safe@activestrue\endcsnameto the preamble, but the error remains the same. I will try to reach out to the `babel' maintainer. – Rushi Feb 05 '24 at 01:38\csname @safe@activestrue\endcsnamein a current texlive. (But you should set that only locally in your environment). – Ulrike Fischer Feb 05 '24 at 19:56lualatexorxelatex, but not if I usepdflatexorlatex. Weirdly, this is true with or without@safe@activestrue. The error disappears altogether if I uselualatexorxelatex. – Rushi Feb 06 '24 at 04:54babellibrary using\usetikzlibrary{babel}, then I get compilation errors with or without\csname @safe@activestrue\endcsname. If the library is not loaded, then the compilation errors go away when\csname @safe@activestrue\endcsnameis set. – Rushi Feb 06 '24 at 16:48