I am using \csdef{} to define a meaning to a given open/close bracket:
\csdef{Bracket Meaning \CsToStr{\lvert}}{Left |}
\csdef{Bracket Meaning \CsToStr{\rvert}}{Right |}
\csdef{Bracket Meaning \CsToStr{(}}{open (}
\csdef{Bracket Meaning \CsToStr{)}}{close )}
The first two and the last seem to work just fine, but the third one has an issue. When I attempt to access these via #1~\csuse{Bracket Meaning \CsToStr{#1}} (where #1 is one of the four given brackets \lvert, \rvert, ( and ), the output is:
I had expected the one highlighted in red to be ( open (.
So, what is going on here, and how should I restructure this to obtain the desired result for the ( bracket?
Code:
\documentclass{article}
\usepackage{etoolbox}
\usepackage{amsmath}
\usepackage{xcolor}
%% Following package not needed with newer binaries
\usepackage{expl3}% \cs_to_str:N
\ExplSyntaxOn
%% https://tex.stackexchange.com/a/100543/4301
\newcommand{\CsToStr}[1]{\cs_to_str:N #1}%
\ExplSyntaxOff
\csdef{Bracket Meaning \CsToStr{\lvert}}{Left |}
\csdef{Bracket Meaning \CsToStr{\rvert}}{Right |}
\csdef{Bracket Meaning \CsToStr{(}}{open (}% FAILS !!
\csdef{Bracket Meaning \CsToStr{)}}{close )}
\newcommand{\ShowBracketMeaning}[1]{%
#1~
\ifcsdef{Bracket Meaning \CsToStr{#1}}{%
\csuse{Bracket Meaning \CsToStr{#1}}%
}{\text{No Meaning Defined}}%
}%
\begin{document}
$\ShowBracketMeaning{\lvert}$
$\ShowBracketMeaning{\rvert}$
{\color{red}%
$\ShowBracketMeaning{(}$% <---- ????? This should show "open ("
}
$\ShowBracketMeaning{)}$
\end{document}


\ifControlSequence{}equivalent macro that I can use in\ShowBracketMeaningto determine if I am going to use\csuse{Bracket Meaning \CsToStr{#1}}or\csuse{Bracket Meaning #1}– Peter Grill Feb 02 '23 at 08:33\token_if_cs:NTF, so you can branch. And I'd avoid mixingexpl3withetoolbox. – egreg Feb 02 '23 at 09:05\UseNameis just a\csuse{}? I also found using\detokenize{}yields the desired results, but wondering if there is a problem with that approach. – Peter Grill Feb 02 '23 at 20:16\UseNameis the kernel version of\csuse. About\detokenize, it's\tl_to_str:ninexpl3, for multiple tokens, whereas\token_to_str:Nis for a single token. – egreg Feb 02 '23 at 22:42