[texworks] Highlighting for LaTeX3 and LuaTeX

Paul A Norman paul.a.norman at gmail.com
Wed Aug 10 01:53:32 CEST 2011

Dear Arno,

There may be some limitations to the current syntax highlighting
regime in TeXworks, I already know that the period . breaks it when
using it for TeXwork's QtScript.

You can add sections like [Lua] in the syntax-patterns.txt
and manually switch to them at present or write script to use a hook
to recognise when a different type of document has been opened (either
by file extension or through internal investigation).

Have you looked at the help information in the manual for writing your
own syntax sections in syntax-patterns.txt?  Appendix section "A.1
Syntax highlighting" gives a good overview.

You can access your syntax-patterns.txt through your TeXworks menu>
Scripts / Scripting TeXworks / Show Scripts Folder then go up one
folder and find the folder  "configuration"

Any thing that you need that does not already work (for example _ or :
may break the syntax highlighting regime as does . already mentioned),
you may want to write an issue up (perhaps do a search there first) on


On 10 August 2011 00:00, Arno Trautmann <Arno.Trautmann at gmx.de> wrote:
> Hi all,
> after LuaTeX and LuaLaTeX have been accepted as engines, I wonder if it is
> possible to also add the necessary highlighting support for them. However, I
> have some more requests regarding highlighting, so this mail will be a bit
> lengthy, sorry:
> First the request for LaTeX3 source highlighting:
> The normal (La)TeX highlighting does not cover this, as LaTeX3 control
> sequence names can have _ as well as : in their names, like:
> \cs_new:Npn
> Everything left of the : is the command (or function, in l3 terms) name, and
> the right-hand part specifies the arguments, in this case 3 arguments are
> needed. Long story short, it should be sufficient to add _ and : to the list
> of allowed characters for a control sequence. Is this possible?
> Now the Lua part: First, there should be a “Lua documents” choice in the
> “Files of type: …” drop-down menu, as most of the LuaTeX code is stored in
> external Lua files. In such files, basic highlighting for Lua should be
> offered. A bit more complicated is the use of \directlua, \latelua or the
> luacode environment, as then we have Lua code inside a .tex file … In a
> perfect world, TeXworks would recognize these structures and apply the
> correct highlighting.
> The most complicated case, however, are .dtx files, at least in the way I
> like to use them. Consider the following piece of a package:
> ——
> \cs_new:Npn\unuppercasecolor
> {\directlua{luatexbase.remove_from_callback("post_linebreak_filter","uppercasecolor")}}
> %    \end{macrocode}
> % Now the setup for the |\text|-versions. We utilize Lua\TeX s
> % attributes to mark all nodes that should be manipulated. The macros
> % should be |\long| to allow arbitrary input.
> %\iffalse
> %</package>
> %<*lua>
> %\fi
> %    \begin{macrocode}
> Hhead = node.id("hhead")
> RULE = node.id("rule")
> ——
> Here we have:
> • (La)TeX(3) code (\cs_new:Npn …) that should go to the final .tex file and
> thus is not commented, needs normal (l3) highlighting, but containing Lua
> code in a \directlua statement.
> • Commented code that should go to the documentation; for the editor,
> everything is just a comment and is not highlighted at all. Here, TeXworks
> should recognize that it is a .dtx file, and not handle everything after a
> single % as a comment.
> • Tags for the driver file that are neither TeX nor Lua style. <tags> should
> be quite easily highlightable?
> • plain Lua code that goes to the final Lua helper file.
> Now, my feature request is: Implement correct highlighting so that I can
> write my package using TeXworks.
> ok, just joking … but how much of the highlighting do you think could be
> done? How much should be done, considering that not too many users of
> TeXworks will hack LaTeX3 syntax into a dtx to create LuaTeX code?
> Thanks for your time,
> cheers
> Arno

More information about the texworks mailing list