3

Is it possible to write a definition with a counter value?

I have many definitions with a Roman numeral:

\def\abcI{} ..
\def\abcII{} ..
\def\abcIII{} .. 

But this is not possible:

\newcounter{myabc}
\addtocounter{myabc}{1}

\abc\Roman{myabc}
\stepcounter{myabc}

Is there another way to do this?

6

You can do this:

\newcommand*\abcRoman[1]{\csname abc\Roman{#1}\endcsname}

...

\abcRoman{myabc}
\stepcounter{myabc}

Well, I suspect that this may not be what you really need, however, that depends on knowing what you want to use your code for.


As egreg suggests, if you can use lowercase roman numerals for your macros, you can get on the safer side:

\newcommand\abci{...}
\newcommand\abcii{...}
\newcommand\abciii{...}
\newcommand*\abcroman[1]{\csname abc\romannumeral\value{#1}\endcsname}

...

\newcounter{myabc}
\setcounter{myabc}{1}

\abcroman{myabc}
\stepcounter{myabc}
  • While \Roman is safe in ordinary conditions, it may give wrong results (aka puzzling errors) when certain babel languages are loaded. – egreg Dec 28 '14 at 0:12
  • What do you suggest -- \rommannumeral\csname c@#1\endcsname? (Damn, I can't even test things now, I'm on Windoze :( ) – yo' Dec 28 '14 at 0:13
  • 1
    If one wants to be on the safe side, it's better to use lowercase Roman numerals and \romannumeral (but after \csname, of course. \csname abc\romannumeral\value{#1}\endcsname would do, preserving expandability. – egreg Dec 28 '14 at 0:17

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.