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.

David Carlisle
  • 757,742
ZhiyuanLck
  • 4,516
  • 1
    Use \csname a\x c\endcsname. – Paul Gaborit Nov 14 '19 at 15:22
  • https://tex.stackexchange.com/a/464656/197451 – js bibra Nov 14 '19 at 15:24
  • @DavidCarlisle Looking forward to seeing tabularz. –  Nov 14 '19 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. –  Nov 14 '19 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 '19 at 15:31
  • Could you perhaps explain why @PaulGaborit does not work for you. (I still do not fully understand the question.) –  Nov 14 '19 at 15:59
  • the code in the first comment is the answer isn't it? I do not understand your comment about the name convention, nor do I understand the edit what space "can not be removed" Please do not post disconnected fragments, post a small complete plain tex test file, and say what output you expected. – David Carlisle Nov 14 '19 at 16:03
  • What space "cannot be removed"? – Steven B. Segletes Nov 14 '19 at 16:03
  • I am sorry about that. It was my fault. The first comment is right. Sorry for confusing you all. – ZhiyuanLck Nov 14 '19 at 16:06

1 Answers1

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.

gernot
  • 49,614
David Carlisle
  • 757,742
  • You can add a third case: \def\x\{foo}\csname a\x\c\endcsname with no result... and no error (like ! Undefined control sequence.). – Paul Gaborit Nov 14 '19 at 17:51