I would like to know if it is possible to make \csname
ignore subscript symbols. Below is a MWE of what I mean by that:
\documentclass[a4paper,11pt]{book}
% I have several commands with the same prefix
\newcommand{\fooT}{T}
\newcommand{\fooS}{S}
% I want to call these commands from another command with respect to the given parameter
\newcommand{\fooL}[1]{L_{\csname foo#1\endcsname}}
\begin{document}
Without subscript $\fooL{T}$ gives the same thing than $L_{\fooT}$.
With subscript $\fooL{T_j}$ is different from $L_{\fooT_j}$.
\end{document}
From what I understood this behaviour is to be expected since \csname
will expand everything to a single command named \fooT_j
with _
considered as a part of the name and not the subscript character. Is it possible to change this behaviour such that \csname
returns the command \fooT
with the subscript _j
? In other words I want $\fooL{T_j}$
to give the same thing than $L_{\fooT_j}$
.
I tried to play around with the \detokenize
and \scantokens
commands:
\newcommand{\fooL}[1]{L_{\expandafter\scantokens{\expandafter\detokenize{\csname foo#1\endcsname}}}}
but I did not manage to obtain something satisfying. The idea was to break down the command and then reconstruct it.
I am aware that I could change the syntax of the commands to obtain the desired result but it would be more convenient for me to keep the same syntax.