# 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 at 14:50

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

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

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. - 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. - 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 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
\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{%
\endtrivlist}


Here -E tells that itemize is an environment.

-
(+1) Good to know. –  chl May 10 '11 at 7:43

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.

-

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.

-
I like this better! Thanks. –  Memming Feb 1 '13 at 23:20

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).

For instance, on a full TeX Live installation, you'd get

~$tlwhich todo Files that define environment todo: ed.sty Files that define command todo: lilyglyphsStyle.sty easy-todo.sty udesoftec.cls todonotes.sty todo.sty  Regular expressions (as compatible with grep) are possible: ~$ tlwhich "align(\*|ed)?"
Files that define environment align(\*|ed)?:
amstex.sty
amsmath.sty

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


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

-