It is a simple question to which I am not able to find the answer:
Given a LaTeX command, how do I find out what package(s) it belongs to or comes from?
For example, given the \qquad
horizontal spacing command, what package does it come from? Especially troublesome since it works without including any package!
The best place to find packages for LaTeX is the Comprehensive TeX Archive (CTAN). Sometimes, package files from CTAN consist of an . ins and . dtx file only.
Packages required by a document are called in the preamble of your LaTeX document, i.e. before the \begin{document} statement. The syntax to do so is \usepackage{ } , with the name of the package included in the brackets.
CTAN has currently over 4,000 packages.
A package is a file or collection of files containing extra LaTeX commands and programming which add new styling features or modify those already existing. There are two main file types: class files with . cls extension, and style files with . sty extension.
Given a LaTeX command, how do I find out what package(s) it belongs to or comes from?
Consult your references:
latex.ltx
or in one of the standard class files, not in a package.find /usr/share/texmf -name '*.sty'
, but be prepared for a painful exercise.You can search http://www.ctan.org/tex-archive/info/symbols/comprehensive/ for that information and more.
Remember that LaTeX is a macro language on top of TeX, and all the macros are made up of TeX which doesn't need to be imported. \qquad
is in that category.
As far as I know, there is no really good general answer to this. But there are a number of techniques you might try for any given command. In the case of \qquad
, it's part of basic TeX. Remember that you can always use TeX in interactive mode:
$ tex '\show\qquad' This is TeX, Version 3.141592 (Web2C 7.5.6) > \qquad=macro: ->\hskip 2em\relax . \show\qquad ? x No pages of output.
Some macros are added by LaTeX on top of TeX, such as \begin
:
$ tex '\show\begin' This is TeX, Version 3.141592 (Web2C 7.5.6) > \begin=undefined. \show\begin ? x No pages of output.
whereas
$ latex '\show\begin' This is pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6) %&-line parsing enabled. entering extended mode LaTeX2e Babel and hyphenation patterns for english, usenglishmax, dumylang, noh yphenation, greek, monogreek, ancientgreek, ibycus, pinyin, loaded. > \begin=macro: #1->\@ifundefined {#1}{\def \reserved@a {\@latex@error {Environment #1 undefine d}\@eha }}{\def \reserved@a {\def \@currenvir {#1}\edef \@currenvline {\on@line }\csname #1\endcsname }}\@ignorefalse \begingroup \@endpefalse \reserved@a . \show\begin ? x No pages of output.
Everything else comes from packages. If you really wanna know which package a macro comes from (other than by google or grepping your texmf tree), you can check after each package you load whether it's defined. Try defining this before any \usepackage
commands:
\let\oldusepackage\usepackage \renewcommand\usepackage[1]{ \oldusepackage{#1} \ifcsname includegraphics\endcsname \message{^^Jincludegraphics is defined in #1^^J} \let\usepackage\oldusepackage \fi}
Then when you run latex
on your .tex
file, look for a line in the output that says includegraphics is defined in graphicx
. It's not likely, but some devious packages might do bad things with \usepackage
so there's a chance this might not work. Another alternative would be to simply define the command you're interested in before loading any packages:
\newcommand\includegraphics{}
Then you might get an error message when the package that defines the command is loading. This is actually less reliable than the former approach, since many packages use \def
and \let
to define their macros rather than \newcommand
, bypassing the "already-defined" check. You could also just insert a check by hand in between each load:
\ifcsname includegraphics\endcsname\message{^^Jdefined after graphicx^^J}\fi
Due to lack of reputation I cannot comment on Steve's answer, which was very helpful to me, but I would like to extend it a bit.
First, in his second approach (fiddling with usepackage
) the case where usepackage
has optional arguments is not dealt with. Secondly, packages are often loaded by other packages via RequirePackage
which makes it hard to find the actual place of definition of a command. So my refinement of Steve's answer is:
\usepackage{xargs}
\let\oldusepackage\usepackage
\let\oldRequirePackage\RequirePackage
\renewcommandx{\usepackage}[3][1,3]{
\oldusepackage[#1]{#2}[#3]
\ifcsname includegraphics\endcsname
\message{^^Jincludegraphics is defined in #2^^J}
\let\usepackage\oldusepackage
\let\RequirePackage\oldRequirePackage
\fi}
\renewcommandx{\RequirePackage}[3][1,3]{
\oldRequirePackage[#1]{#2}[#3]
\ifcsname includegraphics\endcsname
\message{^^Jincludegraphics is defined in #2^^J}
\let\usepackage\oldusepackage
\let\RequirePackage\oldRequirePackage
\fi}
The xargs
package is used here to get the unusual options of usepackage
right (first and third parameter are optional).
Putting this directly after documentclass
should tell where includegraphics
is defined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With