34

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?

5
  • There are some commands defined by more than one package...
    – Seamus
    Oct 5, 2010 at 11:42
  • 1
    @Seamus, of course, but it would still be nice to have a list of all the packages that provide a particular command. Oct 5, 2010 at 12:12
  • best source so far google: e.g. \scalebox ctan very rarely it fails. Dec 8, 2010 at 15:17
  • 2
    Related question.
    – Raphael
    Jun 11, 2014 at 14:49
  • There's also latexdef --find but it only works if you already know which package you should include, so doesn't apply here.
    – user202729
    Dec 11, 2022 at 8:02

6 Answers 6

15
$ grep -r '\\commandname' $TEXMF/tex/latex
9
  • 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. Oct 5, 2010 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 5, 2010 at 22:06
  • 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 6, 2010 at 14:50
  • 2
    @Lev, how do I do this for MacTeX? Please add to the answer.
    – Kit
    Oct 22, 2010 at 14:26
  • 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 ;-) Dec 8, 2010 at 11:53
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.

4

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.

8
  • I have just updated TL23 (Linux) which installed the binary, but texfindpkg query \includegraphics didn't yield something useful.
    – AlexG
    Apr 12 at 8:02
  • @AlexG The tool is new, maybe it needs some refinements, I'll tell the author
    – CarLaTeX
    Apr 12 at 8:05
  • Yes, I tested with commands from other packages which produced correct positives. Something noteworthy: In a Linux shell, the backslash of a command needs to be doubled in order to escape it properly. (Maybe it is mentioned in the docs already, didn't check.)
    – AlexG
    Apr 12 at 8:09
  • @AlexG I don't see it in the readme, I tell the author for it, too
    – CarLaTeX
    Apr 12 at 8:13
  • 1
    I reported everything to the author, thank you!
    – CarLaTeX
    Apr 12 at 8:17
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.)

0

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

2
  • 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 6, 2010 at 6: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". Oct 6, 2010 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.

1
  • IMHO, this answer is as useful as "read the manual" :D
    – CarLaTeX
    Apr 12 at 8:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .