編集: この投稿の元々の名前は「siunitx が newcommand 内で \endcsname をスローするのはなぜですか?」でしたが、名前の変更によって質問の意図がよりよく反映されるようになったと思います。
このコード (siunitx コマンドまで追跡\unit
)が をスローするのはなぜですか\endcsname
? newcommand の一般的な落とし穴は何ですか?
\documentclass{article}
\usepackage{pgfplots}
\usepackage{siunitx}
\pgfplotsset{compat=1.18}
\begin{document}
\newcommand{\axissettings}{ymin=-1, xlabel={Test with $\unit{\celsius}$}}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[grid, \axissettings]
\addplot coordinates {(0,0)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
ありがとう
答え1
これはそれほど面倒だとは思いません。リンクされた回答の残りの部分を見て、戸惑いましたか?
\documentclass{article}
\usepackage{pgfplots}
\usepackage{siunitx}
\pgfplotsset{compat=1.18}
\pgfplotsset{yourcustomaxissettings/.style={ymin=-1, xlabel={Test with $\unit{\celsius}$}}}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[grid,yourcustomaxissettings,ymax=1,xmin=-1,xmax=1]
\addplot coordinates {(0,0)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}