Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Possible Duplicate:
macro names with special characters

When I use \yyy defined bellow it does not print yyy, but if I use \xxx it prints xxx. How can I make \yyy work?

\def\P1{yyy}
\def\PA{xxx}
\def\yyy{\csname P1\endcsname}
\def\xxx{\csname PA\endcsname}
share|improve this question

marked as duplicate by Stephen, egreg, Stefan Kottwitz Jan 25 '13 at 20:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5  
Macro names can't have numbers in them. See tex.stackexchange.com/questions/68201/… for a workaround. –  Ethan Bolker Jan 25 '13 at 19:44
    
See also the TeX FAQ entry about non-letters in macro names –  cgnieder Jan 25 '13 at 19:56
    
Humm, I see. Thanks –  mljrg Jan 25 '13 at 19:56
    
@cgnieder: very instructive that link; in fact, I did something like the final recommendation in that link before I read it. Thanks –  mljrg Jan 25 '13 at 20:01
    
Please notice that there's a standard way how duplicates are marked, and this should not be modified. –  tohecz Jan 26 '13 at 10:20
add comment

1 Answer 1

up vote 3 down vote accepted

There are ways around this:

  • Use roman numerals rather than arabic ones. For example:

    \def\Pi{yyy}
    \def\Pii{xxx}
    \def\yyy{\Pi}
    \def\xxx{\Pii}
    
  • Use the \csname...\endcsname directive for all things non-letter. For example (note the required expansion):

    \expandafter\def\csname P1\endcsname{yyy}
    \def\PA{xxx}
    \def\yyy{\csname P1\endcsname}
    \def\xxx{\PA}
    
  • Use \@namedef and \@nameuse. For example:

    \makeatletter
    \@namedef{P1}{yyy}
    \def\PA{xxx}
    \def\yyy{\@nameuse{P1}}
    \def\xxx{\PA}
    \makeatother
    

Regardless, I think one can always get away with not using numerals in control sequences.

share|improve this answer
    
Those are interesting workarounds, but as you say, the first option seems to be the better. Thanks –  mljrg Jan 26 '13 at 9:56
add comment

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