Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

8 Answers

up vote 30 down vote accepted

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

share|improve this answer
2  
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
add comment

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.

share|improve this answer
    
source2e.pdf has an annotated version of latex.ltx. –  Matthew Leingang Oct 21 '10 at 3:12
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
1  
Reading TeX source makes my brain hurt. But it's good for me, I guess... –  Seamus Oct 21 '10 at 16:25
add comment

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.

share|improve this answer
    
(+1) Good to know. –  chl May 10 '11 at 7:43
add comment

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.

share|improve this answer
add comment

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}

enter image description here

Note: \usepackage[T1]{fontenc} is necessary for correctly typesetting backslashes and braces.

share|improve this answer
    
I like this better! Thanks. –  Memming Feb 1 '13 at 23:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.