# How can I find the definition of latex macros? [duplicate]

So I've started to become more familiar with LaTeX, still a beginner but comfortable enough to try out the scary patchcmd from the etoolbox package. What has me mystified though is how people find out what the definition of the original macros, especially native latex macros, look like so they can patch it.

For example, I've been shown that one can modify the built in \listoftables in a fashion similar to this:

\documentclass{report}

\usepackage{etoolbox}
\usepackage{float}

\floatstyle{ruled}
\newfloat{algorithm}{tbp}{loa}
\providecommand{\algorithmname}{Algorithm}
\floatname{algorithm}{\protect\algorithmname}

\let \listofalgorithms\listoftables
\patchcmd{\listofalgorithms}{\listtablename}{\algorithmname}{}{}
\patchcmd{\listofalgorithms}{\listtablename}{\algorithmname}{}{}
\patchcmd{\listofalgorithms}{\listtablename}{\algorithmname}{}{}
\patchcmd{\listofalgorithms}{lot}{loa}{}{}

\begin{document}
\listofalgorithms
\begin{algorithm}
Step 1: Do something complicated \\
Step 2: Do something even more complicated \\
\caption{Complicated algorithm}
\label{algo:complicated}
\end{algorithm}
\end{document}


Through some experimentation I've found out that the first patchcmd-line seems to be changing the title of the list, but I've no idea what the other two does as I don't know the original definition of \listoftables.

Apart from the mandatory google search I have checked:

• the files in my MikTeX distribution for the string listoftables but didn't manage to find anything that seemed to define the macro.

• the LateX2e documentation but only found references no definition

• read a few answers here on the site, such as Werner's and yo's

I've foud out that there is a package called texdef which can be used (in terminal), but for some reason the following commands:

latexdef -c report listoftables -s
latexdef -c report section -s


both yield undefined as an answer.

• My uneducated guess would be that \patchcmd only does one string at a time, so that you need three invocations to take care of three \listtablenames within \listofalgorithms. Jan 10, 2018 at 18:46
• Does this answer your question? Where do I find out how a command/environment is defined? Dec 10, 2021 at 7:03

There are a few commands one can use in a latex document to show the source of a macro:

• \show\listoftables will print the definition of listoftables to the log
• \meaning\listoftables will print it in the document
• More can be found in this answer by Leo Liu

To get texdef to work I had to specify the TeX format with the flag -t, and in doing so I also had to install the currfile package in MikTeX. I removed the -s (for viewing original source code) as this was unnecessary for my purposes.

latexdef -t latex -c report -f listoftables


The documentation for texdef can be found here. I also found the definitions of a lot of latex macros in the latex base particularly in the classes documentation.

Typing texdoc source2e will give you over 600 pages containing all the basic LaTeX code definitions. For the macro definitions used within packages and other classes texdoc class/package will often show the code for them, depending on the documentation provided by the authors.