# inputenc, active catcode and \csnsame

with this MWE, with a non utf-8 engine (like pdflatex)

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}

\expandafter\def\csname a\endcsname{toto}

\expandafter\def\csname ᾧ\endcsname{toto}

\end{document}


\expandafter\def\csname a\endcsname{toto} works, \expandafter\def\csname ᾧ\endcsname{toto} fails. I suppose because ᾧ should contains bytes made active.

My question is:is it possible to let ᾧ be read without any active character, but like a series of 1 byte character?

If there is no solution, it's ok. But I was just asking, because maybe some TeX guru could help me.

If there is one solution, is possible ᾧ as argument of a macro like:

\def\bar#1{
#1%Here #1 should use active code inside
\expandafter\def\csname #1\endcsname{toto}%Here, it should not.
}
\bar{ᾧ}

• Can we use e-TeX? It's trivial if we can. – Joseph Wright May 12 '15 at 13:37
• yes we can ! (nothing to do with Obama, anywhere) – Maïeul May 12 '15 at 13:40

If all we are worried about is potentially active tokens, e-TeX's \detokenize will sort things out.

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}

\expandafter\def\csname a\endcsname{toto}

\expandafter\def\csname \detokenize{ᾧ}\endcsname{toto}
\expandafter\show\csname \detokenize{ᾧ}\endcsname
\end{document}


This applies to all of the bytes of the awkward multi-byte sequence here so does the job nicely. Without e-TeX we can achieve the detokenization using \meaning or the LaTeX wrapper \@onelevel@santize

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}

\expandafter\def\csname a\endcsname{toto}

\makeatletter
\def\@tempa{ᾧ}
\@onelevel@sanitize\@tempa
\expandafter\def\csname \@tempa\endcsname{toto}
\expandafter\show\csname \@tempa\endcsname
\makeatother
\end{document}


(Note that XeTeX has or at least has had issues with \detokenize and non-BMP chars. Since we are using an 8-bit engine here we should be fine.)

• and so, with command inside – Maïeul May 12 '15 at 14:00
• \def\tutu#1{ \expandafter\def\csname \detokenize{#1}\endcsname{toto} } – Maïeul May 12 '15 at 14:00
• it seems to work. Now, I have to 1) try in reality 2) make exception when using XeTeX – Maïeul May 12 '15 at 14:01
• @Maïeul You'll be very unlucky to run into the XeTeX bug: it's only seen with non-BMP chars – Joseph Wright May 12 '15 at 14:03
• ok. But one more test is better than an imprevious bug. I don't see why eledmac users would use non-BMP chars, but it still surprising. And as I don't need \detokinize with XeTeX. – Maïeul May 12 '15 at 14:07

I'm not sure what the use of this would be. But you can stringify the UTF-8 sequence:

\documentclass{article}
\usepackage[utf8]{inputenc}

\newcommand{\utfcsdef}[1]{%
\expandafter\def\csname\stringify#1\endcsname
}

\def\stringify#1{%
\ifx#1\endcsname
\expandafter\endcsname
\else
\string#1%
\expandafter\stringify
\fi
}

\newcommand{\utfcsuse}[1]{%
\csname\stringify#1\endcsname
}

\utfcsdef{ᾧ}{toto}

\begin{document}

\utfcsuse{ᾧ}

\end{document}

• the use is for a feature of eledmac, \sameword. – Maïeul May 12 '15 at 13:51
• see github.com/maieul/ledmac/issues/301. The solution of Joseph Wright some to be simpler. I will test it. – Maïeul May 12 '15 at 13:52
• @Maïeul Notably, this is expandable without e-TeX: my approach isn't. – Joseph Wright May 12 '15 at 13:56
• @JosephWright yes, but as eledmac need e-TeX in any case.... – Maïeul May 12 '15 at 13:56