2

Assume a situation that I have predefined some macros like \abc, \aotherc, ... etc. The macro is just like \a#1c, and #1 is defined by \x.

In other words, I don't know which of \abc, \aotherc, ... to be used, but all these macros have been defined. then how can I write \a\xc with \x expanded first, and then the whole macro expands to the correct content?

It is my naming convention that causes this problem. Adjusting the order of the subnames just fix it. But I wonder if there is a way to solve this.

\def\abc{abc}
\def\aotherc{aotherc}
\def\x{b}

My attemp

\expandafter\a\csname \x\endcsname c

The first comment is right. Write like this

\csname a\x c\endcsname

then it will expand correctly. My last run came with other problem.

9
  • 1
    Use \csname a\x c\endcsname. Nov 14, 2019 at 15:22
  • tex.stackexchange.com/a/464656/197451
    – js bibra
    Nov 14, 2019 at 15:24
  • @DavidCarlisle Looking forward to seeing tabularz.
    – user194703
    Nov 14, 2019 at 15:25
  • @ZhiyuanLck I think you were using \csname a\x c\endcsname a lot in your package already. So maybe you can explain a bit more the context.
    – user194703
    Nov 14, 2019 at 15:26
  • 1
    @Schrödinger'scat it is my naming convention that causes the macro which is to be expanded surrouding by another one. Adjust the order of the subname can fix this problem, but I wonder if there is a way to solve this.
    – ZhiyuanLck
    Nov 14, 2019 at 15:31

1 Answer 1

4

enter image description here

is the output from the plain TeX file:

\def\abc{abc}
\def\aotherc{aotherc}



1:
\def\x{b}
\csname a\x c\endcsname

2:
\def\x{other}
\csname a\x c\endcsname

\bye

Which shows that in each case, first \x was expanded to construct the csnames \abc (in the first case) or \aotherc (in the second) and then that constructed csname was expanded to produce the appropriate text.

1
  • You can add a third case: \def\x\{foo}\csname a\x\c\endcsname with no result... and no error (like ! Undefined control sequence.). Nov 14, 2019 at 17:51

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.