# list of all used commands in compiled *.tex-documents

Is it possible to get a list of all the commands used in the compiled documents? I mean, if I use in my various .tex-documents commands such as \emph, \section, \cite, \begin, \documentclass, \footnote, and \MyCommandX, can I generate a list similar to the following?

\begin
\cite
\documentclass
\emph
\footnote
\MyCommandX
\section

• You just mean the commands used explicitly in the source, not used in definitions? Any editor ought to be able to show that I'd have thought. Jan 19, 2016 at 9:07
• Yes, that's what I mean. I am using TexShop. It never occurred to me that this might be a feature of the editor. In any case, I don't see anything similar in TexShop. Any other editors which have that feature on mac? Jan 19, 2016 at 9:09

Taking a file, xyz.tex, I just used as an answer to another question

\documentclass[12pt]{report}
\usepackage{array}
\usepackage{amsmath}
\begin{document}
\begin{tabular}{| >{$}c<{$} | c | c | c | c | c | c |c |}
\cline{2-8}
\multicolumn{1}{c|}{}&\multicolumn{7}{c|}{\rule{0mm}{0.4cm}{figure1 put here}}\\ \hline
\rule[-.5cm]{0mm}{1.2cm} x & -0.01 & -0.001 & -0.0001 & 0 & 0.0001 & 0.001 & 0.01 \\\hline
\rule[-.5cm]{0mm}{1.2cm} f(x) & 1.99499 & 1.9995 & 1.99995 & ? & 2.00005 & 2.0005 & 2.00499\\\hline
\multicolumn{1}{c|}{}&\multicolumn{7}{c|}{\rule{0mm}{0.4cm}\text{figure2 put here}}\\\cline{2-8}
\end{tabular}
addsomething with \emph{\$and \^{a}} \end{document}  Then a simple command line such as  egrep -o '\\[a-zA-Z]+|\\[^a-zA-Z]' xyz.tex | sort | uniq  produces \$
\\
\^
\begin
\cline
\documentclass
\emph
\end
\hline
\multicolumn
\rule
\text
\usepackage


That's using unix-ish tools (although I'm on windows) but any editor ought to be able to do the same thing.

• that was quick -- and seems so simple. Jan 19, 2016 at 9:28
• @ClintEastwood You'll feel that often when you see these command line tools. Apr 1, 2016 at 7:31

I stumbled on this question and thought that it would be amusing to list the control sequences within the document itself. Of course, it suffices to input verbatim the listing produced by D.C.’s answer, but let’s say we want to do it all in a single run; this can be done in the following way:

\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}

\newcommand*{\meta}[1]{$$\langle\textit{#1}\rangle$$}

\title{The \TeX\ control sequences\\
used in this document}
\author{A.~U.~Thor}

\begin{document}

\maketitle

What follows is an alphabetized list of the names of all the \TeX\ control
sequences used in this same document:

\begin{flushleft}
\ttfamily
\catcode\^ = 12
\catcode$= 0 \catcode\\ = 12$obeylines
$input{|"egrep -o '\\[a-zA-Z]+|\\[^a-zA-Z]'$jobname.tex | sort | uniq"}
\catcode\\ = 12
$gdef$CommandLine #1{%
egrep  -o '\\[a-zA-Z]+|\\[^a-zA-Z]' #1.tex | sort | uniq%
}
$endgroup \begin{document} \maketitle What follows is an alphabetized list of the names of all the \TeX\ control sequences used in this same document: \ListMyOwnCSNames Note that \verb*|\ | is handled correctly, but \verb|\|\CR\ is not. (We have included a \verb|\|\CR\ right here:~$\to$\ !) Note also that the alfabetical ordering used by \texttt{sort} is somewhat questionable, and that, of course, control sequences beginning with non-standard escape characters, like \verb|$gdef| or \verb|$endgroup|, are not recognized. Let's try a few special characters. It costs 100\$.  Procter \& Gamble.  You
are the~\#1!.  De~l'H\^{o}pital.  A variable named \textit{total\_cost}.
A~10\%~discount.  \emph{Muchas gracias, se\~{n}orita!} (I~hope the Spanish is
correct!)

Moreover: let $$P = \{\,x\mid\mbox{x is prime}\,\}$$, and\\a line break.

\end{document}


Please note that I wouldn’t have dared to write an answer like this, hadn’t the question already been catalogued under the “fun” tag.

• A comment to myself: other “special” characters should be \catcoded 12 too. Imagine the document uses \_, \%, etc. Also, it’s better to switch to an indirect approach, in order to “decouple” the \catcode regime: define a macro in the preamble, etc.; shall fix tomorrow. BTW: \\$` does work as the code stands, but produces a somewhat unexpected result: can you guess what it is?
– GuM
Mar 20, 2016 at 23:58