Where do I find out how a command/environment 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.


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.


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