I would like to define macros whose names contain numbers, not just letters:
\def\var1{A}
\def\var2{B}
They would be used to print their values as in the following example:
\documentclass{article}
\begin{document}
\var1
\var2
\end{document}
However, LaTeX does not allow multi-character macro names to contain numbers.
Following the answer of @jan-hlavacek at Defining commands/abbreviations that contain numbers I thought about a creating a \newcommand that conditionally defines a variable:
\newcommand\definevar[1]{
\ifnum #1 = 1
\def\var{A}
\fi
\ifnum #1 = 2
\def\var{B}
\fi
}
But, then there should be some way to access the variable \var nested in \definevar in the outer code. Any ideas?

\newcommand\varA{..}and\newcommand\varB{..}in the end that is likely to be far the simplest solution. – David Carlisle Dec 17 '17 at 21:44\varto take one argument the number, and return the result. If you just have 100 values that you need to store, use\varAA, \varAB, ..\varZZor perhas simpler use roman numerals\vari,\varii, ...\varc– David Carlisle Dec 17 '17 at 21:49\var{42}would be more complicated than\var42. Anyway, the use example is quite mystifying. – egreg Dec 17 '17 at 23:34\var{1}? – egreg Dec 17 '17 at 23:46