35

Often I'm trying to use a command in my document and it doesn't compile, because I haven't included the package I need for it. Of course, I know, that I can try to google it, but Google often finds some manuals and usage examples without package information (but this is probably because I don't know, how to google better). In all the cases I've succeeded in determining of the package name, but wasted more than 30 minutes in many of them.

Which ways would you advise to search for package name? Which hints would you suggest?

fiktor
  • 1,953

7 Answers7

15
$ grep -r '\\commandname' $TEXMF/tex/latex
Lev Bishop
  • 45,462
  • It seems to be a nice idea. I've tested it for "\scalebox" and I see, that it is in "graphicx" package. This is a new way to search for a package for me. – fiktor Oct 05 '10 at 19:58
  • 2
    Heh, my scalebox comes from graphics. In any case, would it be better if you searched for '\def\commandname' instead? Searching for scalebox gives me a whole lotta other packages that use scalebox but not define it. – Willie Wong Oct 05 '10 at 20:08
  • 4
    @Willie Wong: Then you'd miss e.g. \newcommand\commandname or \let\commandname. On the other hand, you'll always miss \expandafter\def\csname command\@empty name\endcsname. @All: you might try grep -IRF, then you don't have to double backslashes and binary files are ignored. – Philipp Oct 05 '10 at 22:06
  • @Willie Wong. Yes, "graphics". It was my mistake. I just checked the place, where I've found this, and it is "graphics", not "graphicx". \def\scalebox was found in graphics.sty. – fiktor Oct 06 '10 at 07:37
  • 5
    Instead of grep -r I suggest using ack, I find it much faster and the results easier to "understand". There is even a nice TextMate bundle for that... – topskip Oct 06 '10 at 14:50
  • 2
    @Lev, how do I do this for MacTeX? Please add to the answer. – Kit Oct 22 '10 at 14:26
  • @Kit: I don't have access to MacTeX so I can't answer. Something very similar ought to work, but perhaps a MacTeX user can suggest exactly what. – Lev Bishop Oct 22 '10 at 14:40
  • 4
    Nice, although 1) it won't work on non-UNIX-based systems, 2) it requires you to have that package installed already. But still, nice ;-) – Anthony Labarre Dec 08 '10 at 11:53
  • Actually grep -r '\\commandname' `kpsewhich --var-value TEXMF`/tex/latex is the "more correct" answer on modern TeX distributions for Unix systems. – egreg Jun 19 '12 at 16:59
8

If the command is for a symbol, I would look it up in the comprehensive symbols list or in Detexify, both let you know which package you need to load in order to get the symbol.

If the command is for a specific topic or feature, I would try to google for “latex feature” or even “ctan feature” instead of searching for the particular command.

David Carlisle
  • 757,742
Juan A. Navarro
  • 62,139
  • 32
  • 140
  • 169
6

Since April 2023 there is TeXFindPkg, a tool that does it!

On your terminal type:

texfindpkg query [<name>]

where <name> could be a file name, a command name, or an environment name.

The tool was created to install TeX packages and their dependencies by file names, command names, or environment names.

Its general usage is

texfindpkg <action> [<name>]

where <action> could be install or query, and <name> could be what is listed above.
For example:

texfindpkg install array.sty
texfindpkg install \fakeverb
texfindpkg install {frame}
texfindpkg query array.sty
texfindpkg query \fakeverb
texfindpkg query {frame}

TeXFindPkg supports both TeXLive and MiKTeX distributions.

More info on https://ctan.org/pkg/texfindpkg.

CarLaTeX
  • 62,716
2

in general, ctan doesn't have this information (except in the sources of the packages themselves, of course). the catalogue package descriptions (already mentioned) do occasionally mention command names, but they're not a reliable source of this information.

there's no particular reason why ctan shouldn't hold the information, but collecting it would take absolutely ages. one would have to be careful about duplicates (mentions above of graphics vs graphicx for the same command, for example), and the simple volume of packages is going to make it an unwieldy operation.

(note that commands in latex itself aren't a problem, in that they appear at least twice on the web anyway.)

anon
  • 231
0

You can try searching here for the command name in the package descriptions on CTAN.

Mark Meckes
  • 17,791
  • 1
    Searching for “scalebox”, e.g., gives no results. Remember that you are searching only in the packages’ descriptions, not in the packages’ files. Searching for “scalebox” in the documentation search box, on the other hand, gives 59 results, so you still don’t know where the command might come from. – domwass Oct 06 '10 at 06:11
  • 1
    @domwass: I don't claim this will always or even usually be successful; it's just another thing to try. As you point out, documentation searches will usually give too many hits, but sometimes the description will say something like "provides the foo command". – Mark Meckes Oct 06 '10 at 14:46
0

Succinctly: Go back to where you learned about the command for the first time (be it a person or a web page) and see if he/she/it can tell you.

More verbosely (since I got a downvote on this answer I'm guessing it's because I came off as glib, sorry): you put that command in the document for a reason. Either somebody suggested it or you found a code snippet on a web page somewhere. That same person/page should also know what package needs to be included to make it work.

Example 1 You are following the advice of your colleague, let's call him...Martin. But because the conversation took place in the hallway you couldn't write down the actual code required.

"Hey, Martin, you remember how you told me I could use \snarfbbf to snarf the bumblefrack?"

"Yeah."

"Well, it doesn't work. It says the control sequence is undefined."

"Did you include the bbfrack package?"

"Oh, I get it. Thanks."

Example 2 Somebody (let's call him...Stefan) writes a blog post about snarfing bumblefracks in TeX documents. You copied-and-pasted a code snippet from part of the post. But because you didn't copy the preamble you have missed the required packages.

Go back to that web page, where either the complete document or a note about which packages are required should be there. If not, ask the blogger.

Matthew Leingang
  • 44,937
  • 14
  • 131
  • 195
0

Starting 2023, there is texfindpkg:

$ texfindpkg query -e itemize
[tfp] you are using texlive
[tfp] ================================================
[tfp] found package file latex.ltx with environment {itemize}
[tfp] building dependency tree for latex.ltx:
[tfp] ------------------------
[tfp] latex.ltx (from latex)
[tfp] ------------------------
[tfp] texlive package needed: latex
[tfp] this package is already installed
[tfp] ================================================
[tfp] found package file IEEEtran.cls with environment {itemize}
[tfp] building dependency tree for IEEEtran.cls:
[tfp] ------------------------
[tfp] IEEEtran.cls (from ieeetran)
[tfp] |- newtxmath.sty (from newtx)
[tfp]    |- amsmath.sty (from amsmath)
[tfp]       |- amstext.sty (from amsmath)
[tfp]          |- amsgen.sty (from amsmath)
[tfp]       |- amsopn.sty (from amsmath)
[tfp]          |- amsgen.sty (from amsmath)
[tfp]    |- ifthen.sty (from latex)
[tfp]    |- etoolbox.sty (from etoolbox)
[tfp]    |- ifxetex.sty (from iftex)
[tfp]       |- iftex.sty (from iftex)
[tfp]    |- ifluatex.sty (from iftex)
[tfp]    |- xkeyval.sty (from xkeyval)
[tfp]    |- centernot.sty (from oberdiek)
[tfp]    |- amsthm.sty (from amscls)
[tfp] ------------------------
[tfp] texlive packages needed: ieeetran newtx amsmath latex etoolbox iftex xkeyval oberdiek amscls
[tfp] these packages are already installed
[tfp] ================================================
[tfp] found package file IEEEtrantools.sty with environment {itemize}
[tfp] building dependency tree for IEEEtrantools.sty:
[tfp] ------------------------
[tfp] IEEEtrantools.sty (from ieeetran)
[tfp] ------------------------
[tfp] texlive package needed: ieeetran
[tfp] this package is already installed
[tfp] ================================================
[tfp] found package file beamerbaselocalstructure.sty with environment {itemize}
[tfp] building dependency tree for beamerbaselocalstructure.sty:
[tfp] ------------------------
[tfp] beamerbaselocalstructure.sty (from beamer)
[tfp] |- enumerate.sty (from tools)
[tfp] ------------------------
[tfp] texlive packages needed: beamer tools
[tfp] these packages are already installed
[tfp] ================================================
[tfp] found package file enumitem.sty with environment {itemize}
[tfp] building dependency tree for enumitem.sty:
[tfp] ------------------------
[tfp] enumitem.sty (from enumitem)
[tfp] ------------------------
[tfp] texlive package needed: enumitem
[tfp] this package is already installed
[tfp] ================================================
[tfp] found package file paralist.sty with environment {itemize}
[tfp] building dependency tree for paralist.sty:
[tfp] ------------------------
[tfp] paralist.sty (from paralist)
[tfp] ------------------------
[tfp] texlive package needed: paralist
[tfp] this package is already installed
[tfp] ================================================
[tfp] found package file powerdot.cls with environment {itemize}
[tfp] building dependency tree for powerdot.cls:
[tfp] ------------------------
[tfp] powerdot.cls (from powerdot)
[tfp] |- xkeyval.sty (from xkeyval)
[tfp] |- geometry.sty (from geometry)
[tfp] |- ifxetex.sty (from iftex)
[tfp]    |- iftex.sty (from iftex)
[tfp] |- hyperref.sty (from hyperref)
[tfp]    |- kvsetkeys.sty (from kvsetkeys)
[tfp]    |- pdfescape.sty (from pdfescape)
[tfp]       |- ltxcmds.sty (from ltxcmds)
[tfp]       |- pdftexcmds.sty (from pdftexcmds)
[tfp]          |- infwarerr.sty (from infwarerr)
[tfp]    |- letltxmacro.sty (from letltxmacro)
[tfp]    |- kvoptions.sty (from kvoptions)
[tfp]       |- keyval.sty (from graphics)
[tfp]       |- ltxcmds.sty (from ltxcmds)
[tfp]       |- kvoptions-patch.sty (from kvoptions)
[tfp]    |- url.sty (from url)
[tfp]    |- bigintcalc.sty (from bigintcalc)
[tfp]    |- atveryend.sty (from atveryend)
[tfp]    |- nameref.sty (from hyperref)
[tfp]       |- refcount.sty (from refcount)
[tfp]          |- ltxcmds.sty (from ltxcmds)
[tfp]          |- infwarerr.sty (from infwarerr)
[tfp]       |- ltxcmds.sty (from ltxcmds)
[tfp]    |- backref.sty (from hyperref)
[tfp]       |- ltxcmds.sty (from ltxcmds)
[tfp]       |- rerunfilecheck.sty (from rerunfilecheck)
[tfp]          |- infwarerr.sty (from infwarerr)
[tfp]          |- uniquecounter.sty (from uniquecounter)
[tfp]    |- color.sty (from graphics)
[tfp] |- graphicx.sty (from graphics)
[tfp]    |- trig.sty (from graphics)
[tfp] |- pstricks.sty (from pstricks)
[tfp]    |- pgffor.sty (from pgf)
[tfp]       |- pgfrcs.sty (from pgf)
[tfp]          |- everyshi.sty (from everyshi)
[tfp]       |- pgfmath.sty (from pgf)
[tfp]    |- pst-calculate.sty (from pst-calculate)
[tfp]       |- siunitx.sty (from siunitx)
[tfp]          |- translations.sty (from translations)
[tfp]             |- etoolbox.sty (from etoolbox)
[tfp]          |- xspace.sty (from tools)
[tfp]       |- xparse.sty (from l3packages)
[tfp]    |- colortbl.sty (from colortbl)
[tfp]       |- array.sty (from tools)
[tfp]    |- pdfcolmk.sty (from pdfcolmk)
[tfp] |- pst-ovl.sty (from pst-ovl)
[tfp] |- xcolor.sty (from xcolor)
[tfp]    |- pdfcolmk.sty (from pdfcolmk)
[tfp] |- enumitem.sty (from enumitem)
[tfp] |- verbatim.sty (from tools)
[tfp] |- powerdot-default.sty (from powerdot)
[tfp]    |- pifont.sty (from psnfss)
[tfp] |- pdfbase.sty (from media9)
[tfp] |- powerdot-aggie.sty (from powerdot)
[tfp]    |- times.sty (from psnfss)
[tfp]    |- pst-grad.sty (from pst-grad)
[tfp] |- powerdot-BerlinFU.sty (from powerdot-fuberlin)
[tfp]    |- calc.sty (from tools)
[tfp]    |- tabularx.sty (from tools)
[tfp]    |- ragged2e.sty (from ragged2e)
[tfp]       |- footmisc.sty (from footmisc)
[tfp]    |- helvet.sty (from psnfss)
[tfp] |- powerdot-bframe.sty (from powerdot)
[tfp]    |- pst-blur.sty (from pst-blur)
[tfp] |- powerdot-ciment.sty (from powerdot)
[tfp] |- powerdot-elcolors.sty (from powerdot)
[tfp] |- powerdot-fyma.sty (from powerdot)
[tfp]    |- pst-grad.sty (from pst-grad)
[tfp] |- powerdot-horatio.sty (from powerdot)
[tfp] |- powerdot-husky.sty (from powerdot)
[tfp]    |- times.sty (from psnfss)
[tfp]    |- pst-grad.sty (from pst-grad)
[tfp] |- powerdot-ikeda.sty (from powerdot)
[tfp] |- powerdot-jefka.sty (from powerdot)
[tfp] |- powerdot-klope.sty (from powerdot)
[tfp]    |- pst-slpe.sty (from pst-slpe)
[tfp]       |- pst-xkey.sty (from xkeyval)
[tfp] |- powerdot-paintings.sty (from powerdot)
[tfp]    |- times.sty (from psnfss)
[tfp] |- powerdot-pazik.sty (from powerdot)
[tfp]    |- pst-char.sty (from pst-text)
[tfp]    |- pst-grad.sty (from pst-grad)
[tfp]    |- type1cm.sty (from type1cm)
[tfp] |- powerdot-sailor.sty (from powerdot)
[tfp]    |- amssymb.sty (from amsfonts)
[tfp]       |- amsfonts.sty (from amsfonts)
[tfp]    |- pst-grad.sty (from pst-grad)
[tfp] |- powerdot-simple.sty (from powerdot)
[tfp] |- powerdot-tuliplab.sty (from powerdot-tuliplab)
[tfp] |- powerdot-tycja.sty (from powerdot)
[tfp]    |- pst-grad.sty (from pst-grad)
[tfp] |- powerdot-upen.sty (from powerdot)
[tfp]    |- pst-grad.sty (from pst-grad)
[tfp] ------------------------
[tfp] texlive packages needed: powerdot xkeyval geometry iftex hyperref kvsetkeys pdfescape ltxcmds pdftexcmds infwarerr letltxmacro kvoptions graphics url bigintcalc atveryend refcount rerunfilecheck uniquecounter pstricks pgf everyshi pst-calculate siunitx translations etoolbox tools l3packages colortbl pdfcolmk pst-ovl xcolor enumitem psnfss media9 pst-grad powerdot-fuberlin ragged2e footmisc pst-blur pst-slpe pst-text type1cm amsfonts powerdot-tuliplab
[tfp] these packages are already installed
[tfp] ================================================
[tfp] texlive packages not yet installed in total:

(Yes, it stops after the :)

koppor
  • 3,252