Цель состоит в том, чтобы разделить счетчик SharedCTR1
между средами описания. Следующий код работает только с одной средой описания, но не с обеими.
\documentclass{report}
\begin{document}
{\newcounter{SharedCTR}
\def\SharedCTR1{\stepcounter{SharedCTR}\arabic{SharedCTR}}
\section{Section one}
\begin{description}
\item[desc \SharedCTR1.] text text.
\item[desc \SharedCTR1.] text text text.
\item[desc \SharedCTR1.] text text text text.
\end{description} %% In original doc: extra curly bracket was here.
\section{Section two}
\begin{description}
\item[desc \myUseCaseCTR1.] text text. % Fails on this line.
\item[desc \myUseCaseCTR1.] text text text.
\item[desc \myUseCaseCTR1.] text text text text.
\end{description}
\end{document}
Сначала я думал, что проблема в номере 1
в имени, но если я его уберу, все равно не заработает. Ошибка следующая:
! Undefined control sequence.
<argument> desc \myUseCaseCTR
1.
l.20 \item[desc \myUseCaseCTR1.]
text text. % Fails on this line.
[править] В исходном (длинном) документе в какой-то момент было написано, \end{description}}
. Была лишняя фигурная скобка }
, которая вызывала ошибку через несколько строк, когда переменная снова использовалась в другой среде описания. Мне потребовалось некоторое время, чтобы обнаружить проблему.
решение1
Я удалил лишнее {
, но это не было главной проблемой. Вы не определили второе определение ( \myUseCaseCTR
), если вы внимательно посмотрите, имя отличается от ( \SharedCTR
). Я использовал \let
команду, чтобы определить его, см. строку номер 7.
Прилагаю рабочий пример и предварительный просмотр.
\documentclass{report}
\pagestyle{empty}
\begin{document}
%{ % Deleted
\newcounter{SharedCTR}
\def\SharedCTR1{\stepcounter{SharedCTR}\arabic{SharedCTR}}
\let\myUseCaseCTR=\SharedCTR
\section{Section one}
\begin{description}
\item[desc \SharedCTR1.] text text.
\item[desc \SharedCTR1.] text text text.
\item[desc \SharedCTR1.] text text text text.
\end{description}
\section{Section two}
\begin{description}
\item[desc \myUseCaseCTR1.] text text. % Failed on this line.
\item[desc \myUseCaseCTR1.] text text text.
\item[desc \myUseCaseCTR1.] text text text text.
\end{description}
\end{document}