правка: Первоначально этот пост назывался «Почему siunitx выбрасывает \endcsname внутри newcommand?», но, по-моему, переименование лучше отражает суть вопроса.
Почему этот код (отследил его до \unit
команды siunitx) выдает \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}