I would like to redefine a value during runtime. More precisely, I'm creating my own environment and in the preamble I would like to change a value and set it back afterward.

\def\@thmcounterend{new}%In this environment, @thmcounterend has a new value
\def\@thmcounterend{old}%We reset @thmcounterend to its previous value. 

Obviously this code doesn't work since the \def is not executed when the environment is created but later.

Any idea?

  • You use the word "counter" but a \def means to use it as a macro. If @thmcounterend is, in fact, a pre-existing counter from another package, for example, the proper use of counters is not with \def, but with \setcounter{@thmcounterend}{value}. With your question, there is not enough information to definitively help. – Steven B. Segletes May 23 '14 at 10:30

\makeatletter and \makeatother are given much too late. The category codes are important at the definition time of the environment, when \@thmcounterend gets tokenized:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.