TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does anyone have a syntax pattern for TeXworks’s syntax-patterns.txt that will correctly highlight Expl3 code? I.e., something that will recognize that the entirety of \cs_new:Npn is a command sequence—although highlighting the :Npn suffix differently might not be a bad idea.

share|improve this question
nice idea (even though texworks wouldn't be my first choice when writing code :-) ) – Frank Mittelbach Aug 3 '12 at 20:40
See also tex.stackexchange.com/q/129439/17423 – Sean Allred Feb 22 '15 at 21:02
up vote 7 down vote accepted

I use a colour scheme based loosely on that from WinEdt's DTX submode (I used to use WinEdt). This is for editing .dtx files, and nowadays includes support for l3docstrip's @@ convention:


# comments
red        Y    \^\^A.*

# Guards
orange         N    %<(?:[A-Za-z0-9!\|]+|.)>
limegreen      N    %<\*(?:[A-Za-z0-9!\|]+|.)>
crimson        N    %</(?:[A-Za-z0-9!\|]+|.)>
darkviolet     N    %<@@=(?:[A-Za-z]+|.)>

# special characters
darkred        N    \^\^\^\^\^[0-9a-z]{5}
darkred        N    \^\^\^\^[0-9a-z]{4}
darkred        N    \^\^\^[0-9a-z]{3}
darkred        N    \^\^[0-9a-z]{2}
darkred        N    [$#^_{}&]
gray        N    ^%%.*
gray        N    ^%

# Macrocode
green        N    \\(?:begin|end)\{macrocode\}

# LaTeX environments
darkgreen    N    \\(?:begin|end)\s*\{[^}]*\}

# control sequences
blue        N    \\(?:[A-Za-z@:_]+|.)

The key line here is the last one, which does the highlighting request. Of course, this is just a case of getting the regular expression right (if only this were easy!).

share|improve this answer
I’d been using a version of this (without the @@-highlighting) based on an earlier answer of yours, and didn’t realize it already covered expl3. Thank you! – J. C. Salomon Aug 5 '12 at 4:08

Your Answer


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.