Figure out where the command comes from
The easy way
Occasionally you can figure out which package contains the macro you're looking for directly with latexdef --find
, find
, grep
, or
simply searching on Google/Startpage (something I took a lot of time to figure out: DuckDuckGo is particularly bad at this, unfortunately)
See also
The hard way
You should know where the command (macro, environment, control sequence) is defined.
For quick reference:
If there's some \usepackage
/ nonstandard \documentclass
at the top, read the documentation of that package. latexdef --find
can handle this one.
Otherwise, if a macro consist of @
, read macros2e.pdf
(short summary) or source2e.pdf
(full documentation). (also read documentation of \makeatletter
)
See also Where can I find help files or documentation for commands like \@startsection for LaTeX?.
If a macro consist of _
and/or :
, read interface3 at CTAN documentation for l3kernel
→ The LaTeX3 interfaces. (also read expl3 before that)
Otherwise, it should be in one of those
LaTeX2e unofficial reference manual or...
LaTeX Documentation (there are multiple PDF files! Remember to search through them all. E.g. \DeclareMathAlphabet
is in fntguide.pdf
, \NewHook
is in lthooks-doc.pdf
-- although this one can also be found in source2e.pdf)
Note that reading this alone is most likely insufficient...
LaTeX books: "LaTeX: A document preparation system, User’s guide and reference manual" & "The LaTeX Companion" (etc.), which are basically the "official reference manual".
There are some packages that is merged into the format, e.g. xparse
which contains \NewDocumentCommand
.
source2e.pdf
contains the documentation of some "new" commands as well, such as \MakeRobust
.
ε-TeX manual (etex_man.pdf
) for ε-TeX extensions, such as \detokenize
, \currentiflevel
, and \scantokens
.
Documentation of TeX engines for engine-specific extensions (as well as "shared" extensions i.e. engine-specific extensions, but implemented in all engines, such as \expanded
or \ifincsname
):
The TeXBook (get at a bookstore. Source code is published on CTAN, but only for an example how TeX source looks like, it must not be compiled because of copyright reasons) -- cover both TeX primitives and plain TeX macros.
Alternatively there's TeX by Topic and TeX in a nutshell -- covers TeX primitives such as \mathsurround
, but not necessarily plain TeX macros such as \mathpalette
or \underbrace
.
Some more obscure primitives are "documented" in the source code only.
E.g.
\endwrite
in TeX source code -- texdoc tex
(see also Accessing TeX's internal tokens),
\synctex
in PDFTeX/XeTeX being an extension added by TeX Live from the original PDFTeX/XeTeX program
would be in texdoc pdftex-changes
-- refer to
Addition: What are all these layers?
Also read What is the difference between TeX and LaTeX? and the first comment there which points to https://www.tug.org/levels.html .
First, there's the core, TeX, which has some 300 primitives.
They're all documented in the TeXBook (you have to buy this one. See Is it actually illegal to TeX `texbook.tex`?
for the legal details -- warning: users on this site are not necessarily lawyers!), and (mostly) TeX by Topic.
(I remember seeing some command in the TeXBook but not in TeX by Topic, but perhaps it's in Plain TeX instead of a primitive.)
There's also an engine extension (e-TeX).
Then, there are the TeX engines (tex, pdftex, xetex, luatex).
(analogy: gcc, clang, tcc, Microsoft Visual C++ compiler for C++; or CPython, PyPy, Jython for Python)
It's fairly rare to see an engine-specific command/syntax (such as \directlua
or ^^^^
), but if it's then reading the documentation of the engine works.
Then, there's a TeX format (set of macros predefined). The (not necessarily common) formats are "virgin" TeX, Plain TeX, LaTeX, ConTeXt, OpTeX.
(analogy: legacy C headers/C++ standard library/Boost for C++. There isn't a good analogy, as most languages only have one "standard library")
Now that the default format for LaTeX is LaTeX3, both LaTeX2e macros and LaTeX3 macros are automatically loaded.
Understanding how to use the command
Most of the time, you only need to know how to use the command.
For that, reading the documentation of the package is sufficient. See How to find the documentation for a package? .
Note: If you decide to be lazy and not read through the whole TeXBook/TeX by Topic first, you risk not understanding some concepts to make sense of the documentation. In that case
search for the concepts recursively (for example, you can find those in The TeXBook: what is a token? What is category code (catcode)? What is a box's depth/height/width?)
Patch the command
Also most of the time, you don't need to know how the command is defined to patch it.
You can do something like this
\NewCommandCopy{\oldemph}{\emph}
\renewcommand{\emph}[1]{\textbf{\oldemph{#1}}}
(details in egreg's answer to "Can I redefine a command to contain itself?")
If you really need to know how the command is defined, it's usually beneficial to read through the
command's source documentation (the .dtx
file compiled to a .pdf
file) if available,
(otherwise read the source code, instead of the .sty
file, which is a stripped-comment version)
which usually contains explanation on how particular things are defined.
For instance, for the unicode-math
package, it can be accessed at "Documentation of the source code" link
in CTAN page.
Note
Also an answer to:
- How can I know how to use this command/macro/environment?
- Where can I look up LaTeX commands?
- How can I understand what this answer found on the site/snippet of code I found somewhere is doing?
Related questions:
enumitem
, it'll provide everything you need for creating new itemize like environments or change the appearance of the old ones.