Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
... 
share|improve this question
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 Jan 16 '13 at 19:51
    
Got it. Thanks for the answer –  MaD Jan 16 '13 at 20:10
    
As that is useful to you, I'll post as a slightly expanded 'proper' answer. –  Joseph Wright Jan 16 '13 at 20:16
1  
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. –  Greg Ros Jan 16 '13 at 20:37
1  
To underline @Greg's point, here is my earlier try at some TeX rexps. –  morbusg Jan 16 '13 at 21:04

1 Answer 1

up vote 9 down vote accepted

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.)

share|improve this answer
    
How is this particular RegExp looks like? Having difficulty to create such myself :( –  MaD Jan 16 '13 at 20:21
7  
\\([^a-zA-Z]|[a-zA-Z]+) –  David Carlisle Jan 16 '13 at 20:40
    
@David Carlisle Thought about it but it seems that I also catch illegal commands such as chapter\ instead of \chapter –  MaD Jan 16 '13 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\ –  David Carlisle Jan 16 '13 at 20:49
    
@David_Carlisle thanks for the help. –  MaD Jan 16 '13 at 21:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.