Absolutely basic \csname question

Your problem is the space between the name and the \endcsname.

jimmy

This works:

\documentclass[10pt]{article}

\usepackage[T1]{fontenc}

\setlength\parindent{0pt}

\begin{document}

\expandafter\def\csname v0\endcsname{Jimmy}

-\csname v0\endcsname-

\end{document}

There is a difference between \csname v0 \endcsname and \csname v0\endcsname. You defined the former, but used the latter:

-Jimmy-

\documentclass{article}

\begin{document}

\expandafter\def\csname v0 \endcsname{Jimmy}

-\csname v0 \endcsname-

\end{document}

Within \csname ... \endcsname even spaces are valid. So you'll have to match it exactly in your usage. Moreover, \csname ... \endcsname doesn't cause an error if the macro isn't defined. Instead, it defines it to \relax. Here's an example:

\csname v1\endcsname

\expandafter\show\csname v1\endcsname

The output in your .log/terminal is

\v1=\relax

Tags:

Macros