Closed rlkamalapurkar closed 4 months ago
I’ve answered this question in stackexchange, with a guess. I’m not sure how tikz
deals with active characters and there isn’t a full MWE. I’m closing this issue, but we can continue in stackexchange.
@jbezos And example would be this. It errors because the active chars in {(t>100)?0.2:0.5}
are expanded when pgfplots parses the math. And with (crude) protected definitions it doesn't error:
\documentclass{article}
\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}
}{}
\usepackage[french]{babel}
\begin{document}
\let\oriq?
\let\oricolon:
\protected\def?{\ifincsname\string?\else\oriq\fi} %comment to see error
\protected\def:{\ifincsname\string:\else\oricolon\fi} %comment to see error
\section{Sec: Sec?}\label{sec:blub}
%\csname @safe@activestrue\endcsname
text: text?
\begin{MyEnv}[]{1e-1}{1e4}
\node at (1,0.5) {text?};
\draw[thick,blue,dashed] (axis cs:1,0) -- (axis cs:100,1);
\addplot[variable=t,domain=1e-1:1e4] {(t>100)?0.2:0.5};
\end{MyEnv}
\end{document}
Related: #196.
@u-fischer the protection you outlined above seems to be incompatible with the babel
tikz
library. Adding \usetikzlibrary{babel}
to your MWE above gives me
! File ended while scanning use of \path.
I can confirm that the "collect all shorthands in a macro and disable them" approach, suggested by @jbezos on StackExchange, works fine with or without the babel
library.
I do not know enough about TeX
to understand why, but I figured letting you know would help!
Glad it helped. As I said in stackexchange, a more user friendly way to switch all shorthands on or off can be useful. (Added to my todo list.)
I asked this question on StackExchange, and a suggestion was to reach out to you to see if shorthands can be protected.
In the
bodeplot
package, I defined new environments using (defined like this to avoid issues with externalization oftikz
graphics)I want users to be able to use the new environment to do things like this
All of this works out for English language documents. However, if a user uses
babel
with any language that uses some characters in#4
as a shorthand, the document cannot be compiled. For example, if I addto the preamble, I get compilation errors. The errors persist even if I add
\csname @safe@activestrue\endcsname
.I managed to make it work for the French language by checking for
frenchbsetup
and usingif it is detected. However, doing something like this for every shorthand in every language seems like the wrong approach to solve this issue.
Is there a better way detect and manage shorthands in macros like this that will work with all languages supported by
babel
?