Shared counter (between description environments) results in "undefined control sequence"

The objective is to share the counter SharedCTR1 across the description environments. The following code works with only one description environment, but not with both.

\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} 

I first thought the problem was the number 1 in the name but it still won't work if I remove it. The error is the following:

! Undefined control sequence. <argument> desc \myUseCaseCTR                                1. l.20   \item[desc \myUseCaseCTR1.]                                    text text.          % Fails on this line. 


[edit] In the original (long) document it was written, at some point, \end{description}}. There was an extra curly bracket } which was causing the error a few lines later when the variable was being used again in a different description environment. It took me awhile to spot the problem.

Replay

I deleted an extra {, but that wasn't the major problem. You haven't defined the second definition (\myUseCaseCTR) if you check it closely, the name is different from (\SharedCTR). I have used the \let command to define it, see line number 7.

I enclose a working example and a preview.

\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}

Shared counter (between description environments) results in "undefined control sequence"

Category: errors Time: 2014-03-24 Views: 1

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.231 (s). 12 q(s)