Serkan Kasapbaşı
Serkan Kasapbaşı

Reputation: 409

How can I get a list of available commands on a latex document?

I don't know much about latex itself. All I need is list of available commands. All standard commands and that come from "usepackage" declarations.

I'm currently focused on MiKTeX, so if MiKTeX do provide, it is of course great, otherwise I do get the idea of parsing some .sty or .def files. But I don't understand the syntax behind those files. What should I look for in those files, if parsing is the only solution?

Upvotes: 2

Views: 1819

Answers (4)

Damien Pollet
Damien Pollet

Reputation: 6598

It's not clear from your question if you want a list for use in a program, or just documentation for yourself?

In the latter case, recent TeX distributions include the command texdoc which will locate and open the documentation for whatever you ask it, e.g texdoc hyperref. It has aliases defined for convenience: texdoc koma will find and open the koma-script manual even though the actual file is named scrguien.pdf.

Upvotes: 0

Jouni K. Seppänen
Jouni K. Seppänen

Reputation: 44132

Parsing TeX code is by no means the only way to get a list of all control sequences. Other possibilities include:

  • cause TeX to dump its data structures after loading the relevant package, then parse the dump file; when you run the latex command, what really happens is that the tex binary loads the latex.fmt dump file, which was generated by having the same binary parse all the built-in code of LaTeX and dumping its data structures;

  • modify the source code of TeX to output something every time a control sequence gets defined;

  • run TeX in a scriptable debugger, insert a breakpoint where the sequence is inserted to the hash table, and have a script output the name of the sequence.

None of these is likely to be a particularly easy solution, but probably easier than writing a TeX-equivalent parser yourself. To get started, look at TeX: The Program, and your TeX system's source code.

If your goal is to provide "intellisense" in an editor, a mere list of command sequences is not going to be much help: when the user types \ref{, you should offer a list of labels defined in the document (bonus points if typing Chapter~\ref{ results in a list of chapter labels, not all labels); for \settowidth{, a list of length commands; for \begin{, a list of environments; etc.

You could see what AUCTeX (an Emacs mode) does; it has a limited, regexp-based parser that handles the common case, and a bunch of package-specific libraries that extend the functionality.

Upvotes: 3

Rook
Rook

Reputation: 62548

Seems to me, you could use something like a "cheat sheet". There is one here, but there's bound to be more of them lying around.

Upvotes: 1

Marco van de Voort
Marco van de Voort

Reputation: 26376

latex is a macro package, and macro systems (some hygenienic ones excepted) are notoriously difficult to parse.

The fact that there is no decent latex to html converter after all these years proves that.

But anyway, the existing ones could give you an example how to proceed, search for latex2html (in Perl), tex2ht and hevea

Upvotes: 0

Related Questions