# Pavel's Boring Notes

## LaTeX Tips: Indexed List

Provides an excerpt on how to use indexed lists in LaTeX documents. #latex

For me it was surprisingly difficult to find out how to create an indexed list in LaTeX. In terms of programming I am a newbie in LaTeX. Thus, I did not know about LaTeX3. And I did not want to use LuaTeX: it is a bit overkill in my scenario.

So what is the problem? Quite basic:

• Initialize a list of something.
• Fill the list with elements (at arbitrary place in document).
• Reference an element of the list by numerical index.

Using LaTeX3 notation we can solve it in the following way.

At first, we define methods in the preamble to create a list, append an element to list and display an element from list:

``````\ExplSyntaxOn%
\NewDocumentCommand{\definesomethinglist}{}
{
\clist_clear_new:N \l_something_clist
}
\NewDocumentCommand{\appendtosomethinglist}{m}
{
\clist_put_right:Nn \l_something_clist { #1 }
}
\NewDocumentCommand{\getsomethinglistitem}{m}{%
\textbf{\clist_item:Nn \l_something_clist { #1 }}
}
\ExplSyntaxOff%
``````

Then we initialize a list before `begin{document}`:

``````\definesomethinglist%
``````

Now we can append elements to the list somewhere in the document body:

``````\appendtosomethinglist{a note of interest}%
``````

Displaying an element of interest:

``````\getsomethinglistitem{1}
``````

Works for me. :–)