9

I'm writing a LaTeX commands highlighter in C#, for this I need all or most of the LaTeX commands. I've searched the web and found many lists of commands but all of them are with comments and explanations that I don't need. Before I'll spend entire week deleting the unnecessary comments leaving only the commands. I would like to ask you, is there somewhere a simple text list of the commands, like this:

...
\backslash
\bar
\baselineskip
\baselinestretch
... 
5
  • 6
    There is no such list. Most people do highlighting using TeX's own rules: a command is \ followed by one non-letter or one or more letters. (That's assuming you are not also wanting internal commands, which in traditional TeX may also contain @ as a 'letter'.)
    – Joseph Wright
    Commented Jan 16, 2013 at 19:51
  • As that is useful to you, I'll post as a slightly expanded 'proper' answer.
    – Joseph Wright
    Commented Jan 16, 2013 at 20:16
  • 2
    Don't use regex for this. Regex is for processing text, not structured languages. There are tons of good parser-combinator libraries for .NET, the best of which, in my opinion, is FParsec (though that requires F#). Using a parser means your code is readable, reusable, maintainable, and improvable. A parser allows you to capture the semnatic content. Regex allows you to capture characters.
    – GregRos
    Commented Jan 16, 2013 at 20:37
  • Not familiar with F# at all. Just heard that it exists.
    – MaD
    Commented Jan 16, 2013 at 20:48
  • 1
    To underline @Greg's point, here is my earlier try at some TeX rexps.
    – morbusg
    Commented Jan 16, 2013 at 21:04

1 Answer 1

11

While it is possible to list all TeX primitives or all LaTeX kernel commands, there is no list of all possible LaTeX commands as new ones can be added by packages. As such, most people use an approach of searching for the same pattern as TeX does: \ followed by either one non-letter or one or more letters: this is the pattern for 'document commands'.

(It is possible for commands not to start with \, but this is used for internal coding and not in documents. Similarly, internal commands often use one or more extra 'letters': @ is traditional while LaTeX3 uses _ and :. However, for the purposes of highlighting in a document these cases can be ignored.)

5
  • How is this particular RegExp looks like? Having difficulty to create such myself :(
    – MaD
    Commented Jan 16, 2013 at 20:21
  • 8
    \\([^a-zA-Z]|[a-zA-Z]+) Commented Jan 16, 2013 at 20:40
  • @David Carlisle Thought about it but it seems that I also catch illegal commands such as chapter\ instead of \chapter
    – MaD
    Commented Jan 16, 2013 at 20:46
  • No it means literal \ followed by the choice group of a single non letter [^a-zA-Z] or 0-more letters [a-zA-Z]+ so would not match chapter\ Commented Jan 16, 2013 at 20:49
  • + is 1 or more (which is what you want) not 0 or more as I mis-wrote above Commented Jan 16, 2013 at 21:07

You must log in to answer this question.

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