
明確程式碼
\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}
有效,但如果我使用新環境,則無法編譯
\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}
如果我註解掉該babel
包,第二個範例將正確編譯。
有想法該怎麼解決這個嗎?其他類似問題的答案中的建議shorthandoff
在這裡似乎不起作用。
答案1
編輯:更好的方法是產生當前簡寫列表,然後停用所有簡寫,請參閱這個答案。如果不是簡寫,手動停用簡寫;
可能會導致錯誤(請參閱下面的評論)。;
原始答案:正如@UlrikeFischer 在評論中建議的那樣,
\AddToHook{env/MyEnv/begin}{\shorthandoff{;}}
處理活動角色作品。該environ
套件用於避免與tikz
external
庫發生衝突。該xparse
包也可以用來代替environ.
\documentclass{standalone}
\usepackage[french]{babel}
\usepackage{xparse}
\usetikzlibrary{babel,external}
\tikzexternalize[prefix=figure]
\pgfplotsset{compat=1.18}
\AddToHook{env/MyEnv/begin}{\shorthandoff{;}}
\NewDocumentEnvironment{MyEnv}{O{}mm+b}{
\begin{tikzpicture}
\begin{semilogxaxis}[xmin={#2},xmax={#3},ymin=0,ymax=1]
#4
\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}