21

DTX files are based on LaTeX comments, which means that any editor that can highlight LaTeX code will print most of the DTX files - all the documentation - as a comment and thus not highlight the code.

I found that Emacs can handle that problem, however I rather do not want to learn how to use Emacs just because of that. WinEdt should be able to handle the problem as well, but that is not Open Source. TeXworks does not handle it (I am using Window). I read that gedit should be able to do it, but it also only highlights standard LaTeX Code.

In Editors/IDEs for LaTeX documented source (.dtx) files a script for highlighting in TeXworks was introduced, but I have not idea how to tell TeXworks to use that. The settings dialog does not allow to do it.

16

I use TeXworks for editing .dtx files: I'll explain how I set it up.

On Windows, the 'vanilla' TeXworks stores its settings in C:\Users\<user>\TeXworks\configuration (Windows 7)/ C:\Documents and Settings\<user>\TeXworks\configuration (Windows XP). There, you will find a file called syntax-patterns.txt, which is best edited using TeXworks itself (the line ending are *nix, so Notepad will mess the formatting up). I have added a section to that file which reads

[LaTeX DTX]

# comments
red        Y    \^\^A.*

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

# 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@:_]+|.)

Adding this, and restarting TeXworks, adds a new option to the Format -> Syntax Coloring menu. When I edit .dtx file, I use these highlighting settings.

If you are using TeXworks installed by TeX Live, the settings are in C:\Users\<user>\.texlive<year>\texmf-config\texworks\configuration (pick your year as appropriate).

For Mac users, the settings live in ~/Library/TeXworks/configuration, while on Linux they are in ~/TeXworks/configuration: other set up details remain the same.

An alternative to TeXworks on Windows is WinEdt. It has a pretty advanced 'DTX mode', available from the community support site. The colour scheme in my settings above is based on those from WinEdt's DTX mode: I used to use WinEdt before switching to TeXworks.

10

VIM recognizes .dtx files out of the box.¹ It does not treat lines beginning with % and %% as comments and highlights the code correctly. In the same time, ^^A (the comment character inside the \DocInputed part of the .dtx) is recognized as a proper comment character.


¹ What else did you expect from VIM? ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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