Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is an array how it could be implemented in LaTeX:</p> <pre><code>\documentclass{article} \begin{document} \newcounter{mycounter} \setcounter{mycounter}{1} % ary is any prefix you want, it should not exist as a command. \expandafter\newcommand\csname ary\the\value{mycounter} \endcsname{myfirstelement} \stepcounter{mycounter} \expandafter\newcommand\csname ary\the\value{mycounter} \endcsname{mysecondelement} \csname ary1 \endcsname or \newcounter{index} \setcounter{index}{2} \csname ary\the\value{index} \endcsname \end{document} </code></pre> <p>Run this through LaTeX (latex mydoc.tex or pdflatex mydoc.tex) and you see the output.</p> <p>A short explanation: this creates two commands (with newcommand): ary1 and ary2. The <code>\expandafter</code> is needed because <code>newcommand</code> should not define <code>\csname</code> but the command created by <code>\csname</code> ... <code>\endcsname</code>. <code>\expandafter</code>jumps over the next token, in this case the control sequence <code>\newcommand</code> and executes the next command before TeX sees the <code>\newcommand</code>. That means, the first thing in the newcommand-lines TeX sees is the <code>\csname</code>...<code>\endcsname</code> construct, TeX executes it and then executes <code>\newcommand</code> with the result of the <code>\csname</code>...<code>\endcsname</code> construct. <code>\csname foo\endcsname</code> is the same as <code>\foo</code>, but you can use any character or even spaces in the command created by <code>\csname</code>...<code>\endcsname</code>.</p> <p>This is not trivial. See the great book "TeX by topic" from Victor Eijkhout: <a href="http://eijkhout.net/texbytopic/texbytopic.html" rel="noreferrer">http://eijkhout.net/texbytopic/texbytopic.html</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload