In answering another question, I ran into some issues trying to use a combination of \def
and \char
. Consider the following example:
\documentclass{minimal}
\usepackage{etoolbox}
\usepackage{xstring}
\makeatletter
\def\title@A{a A}
\def\title@B{b B}
\def\gettitle#1{
\IfInteger{#1}{%
\def\@tmp{\char#1}%
\ifcsundef{title@\@tmp}{\@tmp}{\csname title@\@tmp\endcsname}%
}{%
\ifcsundef{title@#1}{#1}{\csname title@#1\endcsname}%
}
}
\begin{document}
\gettitle{65} \gettitle{A}
\gettitle{66} \gettitle{B}
\gettitle{67} \gettitle{C}
\end{document}
Output:
A a A
B b B
C C
It seems like \@tmp
does not expand to be a single character, but instead expand to \char 65
, which then doesn't work in \csname ... \endcsname
. I thought that using \edef\@tmp{\char#1}
would work, but it seems like \char
is one of those functions that does not get expanded.
So in the end, is it possible to have \@tmp
expand to A
and not \char 65
?