# Where do I find out how a command/environment is defined?

Say I want to redefine the itemize environment, or make a modified version of it. I want to know how it is currently defined. Where do I find this information? If it's some particular package command, I can just look at the .sty file for that package, but if it's something more basic, I don't know where to look...

Is there a reference manual of where all this stuff is explained? Or is there a file in the depths of my texmf tree I should poke around in?

• – Raphael Jun 11 '14 at 14:50
• You might want to look into the package enumitem, it'll provide everything you need for creating new itemize like environments or change the appearance of the old ones. – MaxNoe Oct 21 '15 at 6:55

LaTeX itself is documented in source2e.pdf (texdoc source2e) and the standard classes (article, book, report, etc) are documented in classes.pdf (texdoc classes).

• Isn't source2e more relevant for those of us who don't live on the bleeding edge? – Harald Hanche-Olsen Oct 20 '10 at 13:04
• Heh. Oops. Fixed :) – Will Robertson Oct 20 '10 at 13:35
• I don't know where to find source2e.pdf or the file texdoc. I am using MiKTeX. – ahorn Jul 14 '16 at 6:43
• texdoc is a program you use from the Command Prompt. You can easily google for source2e.pdf but be warned some of it is not for the faint-hearted. – Will Robertson Jul 14 '16 at 12:48

To know how a command is defined, you can use the \show command:

\documentclass{article}
\begin{document}
\show\itemize
\end{document}


The log wfile will show:

> \itemize=macro:
->\ifnum \@itemdepth >\thr@@ \@toodeep \else \advance \@itemdepth \@ne \edef \@
itemitem {labelitem\romannumeral \the \@itemdepth }\expandafter \list \csname     @itemitem \endcsname {\def \makelabel ##1{\hss \llap {##1}}}\fi .
l.3 \show\itemize


To locate the file containing the definition the script texgrepis useful, which I posted answering this topic: Grepping through an entire texmf tree.

There is now the (la)texdef script on CTAN which can be used to display (La)TeX definitions. The current version also support to display the package which defines the macro, however you need to state a list of packages to be loaded. For itemize the usage would be

latexdef -f itemize


or, if only texdef was installed by your distro (latexdef is only a symlink to texdef which activates LaTeX mode):

texdef -t latex -f itemize


which prints:

\itemize is defined by (La)TeX.

\itemize:
macro:->\ifnum \@itemdepth >\thr@@ \@toodeep \else \advance \@itemdepth \@ne \edef \@itemitem {labelitem\romannumeral \the \@itemdepth }\expandafter \list \csname \@itemitem \endcsname {\def \makelabel ##1{\hss \llap {##1}}}\fi


To display the definition of any macro from any package use:

latexdef -p package macro


See latexdef --help for more information.

With v1.6 from 2012/05/02 you can also get the original source code for most macros using the -s/--source option:

$latexdef -f itemize -s -E % latex.ltx, line 4556: \def\itemize{% \ifnum \@itemdepth >\thr@@\@toodeep\else \advance\@itemdepth\@ne \edef\@itemitem{labelitem\romannumeral\the\@itemdepth}% \expandafter \list \csname\@itemitem\endcsname {\def\makelabel##1{\hss\llap{##1}}}% \fi} % latex.ltx, line 4565: \let\enditemize =\endlist % latex.ltx, line 4422: \def\endlist{% \global\advance\@listdepth\m@ne \endtrivlist}  Here -E tells that itemize is an environment. As a complement to Stefan's answer: If you don't want to peruse the logfile, but to typeset a command's definition directly in the document, use \meaning instead of \show: \documentclass{article} \usepackage[T1]{fontenc} \begin{document} \meaning\itemize \end{document}  Note: \usepackage[T1]{fontenc} is necessary for correctly typesetting backslashes and braces. Environments are nearly always defined using either pairs \def\env..., \def\endenv... (used mainly in the Latex base code) or \newenvironment{env} (used mainly in the classes), so grepping the dtx source files might narrow you in to the code you want that bit faster, e.g., on a unixlike with TEXMF the root of a Texlive install, fgrep -e "\\itemize"$TEXMF/texmf-dist/source/latex/base/*.dtx shows the file and text where itemize is defined.

• My distribution does not have a base subfolder in $TEXMF/texmf-dist/source/latex/... – kavadias Jun 16 '17 at 0:45 Reading source code is a great way to learn TeX programming but it's not for the weak of stomach. If you just want to modify an environment you can try the etoolbox package or some of the other answers on the UK TeX FAQ. Oh, and one more thing: \show\cmd in a TeX file will interrupt processing to tell you the definition of \cmd. • Reading TeX source makes my brain hurt. But it's good for me, I guess... – Seamus Oct 21 '10 at 16:25 None of the answers were as conveniently to use as I'd like, so I put together a small script that basically greps through the whole LaTeX (in my case, TeX Live, hence the name) installation and looks for a single command/environment name. It recognises some (not all) ways to define commands and environments (cf the comments). This sounds like an awful amount of work, but it's indeed blazingly fast. Which makes you wonder why LaTeX "IDE"s don't do something similar. For instance, on a full TeX Live installation, you'd get ~$ tlwhich todo
Files that define command todo:
easy-todo.sty
lilyglyphsStyle.sty
todonotes.sty
todo.sty
tudscrdoc.cls
udesoftec.cls

Files that define environment todo:
ed.sty

Files that provide a package with similar name:
easy-todo.sty
fixmetodonotes.sty
todonotes.sty
todo.sty


Regular expressions (as compatible with grep) are possible:

~\$ tlwhich "align(\*|ed)?"
Files that define command align(\*|ed)?:
amstex.sty
divers.sty
dprogress.sty
euro.sty

Files that define environment align(\*|ed)?:
amsmath.sty
amstex.sty

Files that provide a package with similar name:
asyalign.sty


If it does not find something it should, please drop me a comment (or ticket on Github).

Just concerning itemize: This is defined in the basic latex file latex.ltx. It is redefined,e.g. in the enumitem package, i.e, in enumitem.sty.

• source2e.pdf has an annotated version of latex.ltx. – Matthew Leingang Oct 21 '10 at 3:12

i would say that merely looking at the output of \show isn't going to get you very far: itemize is a refinement of trivlist so you need to read that definition too.

so, either read source2e.pdf (as others have recommended) or (if you're old and crumbly like me, and find typeset code confusing) read ltlists.dtx in the latex source distribution.