# Editors/IDEs for LaTeX documented source (.dtx) files [duplicate]

Similar to the question "Latex Editors/IDEs," I'm curious if there are any editors or add-ons that directly support the LaTeX documented source (.dtx) format.

I imagine such an editor would support syntax highlighting for both the implementation as well as the documentation, perhaps with different backgrounds to increase contrast between sections. Just as most editors will preserve indentation on newlines, it would also be helpful to preserve the leading % in documentation mode. Extra bonuses to support for Doc-specific macros.

Does such a thing exist? Do enough people actually edit .dtx files for there to be sufficient demand?

-

## marked as duplicate by Paul Gessler, Christian Hupfer, Papiro, Malipivo, Adam LiterJan 12 at 17:59

Thanks @Joseph. I'm still trying to figure out the vocabulary for all the different flavors of TeX. :) –  Matt B. Feb 11 '11 at 16:27
No problem, that's what the experienced people are here for. The .dtx format is not limited to LaTeX, but as it's something the LaTeX Project came up with that's where the major use is. –  Joseph Wright Feb 11 '11 at 16:30

Several editors have a dedicated .dtx mode. Speaking from personal experience, the one for WinEdt is very good if you want a 'heavy-weight' editor. As an alternative, TeXworks is easy to customise with new syntax highlighting styles. I use a custom regex set with TeXworks for my .dtx editing:

[LaTeX DTX]

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@:_]+|.)  Another common choice, but one I've not used, is AUC-TeX, which plugs into Emacs. (I've covered some detail about .dtx editing in my blog in the past: the list of editors I give there is the same as the one I've given here.) - I just tested if WinEdit runs under Linux inside Wine. It does, and can call the Win32 binaries of TeXLive! – Martin Scharrer Feb 11 '11 at 17:17 You can do this with Vim. It disables the '%' comments for .dtx files. You can reactivate it for all code inside the {macrocode} environments or even switch the language. This is shown by Vim Tip 857. I used this for svn-multi-pl.dtx which actually describes a Perl script. - I guessed as Emacs has something then Vim would ... – Joseph Wright Feb 11 '11 at 16:50 @Joseph: :-) ... – Martin Scharrer Feb 11 '11 at 16:51 As another option, I just threw together a solution for TextMate. It isn't terribly complicated, but some trickery is required to use the existing LaTeX language grammar for both the implementation and the documentation. It has a few issues. Most notably, many .dtx files do funny things with the catcode of , and as such, TextMate will furiously try to match all s, even when there isn't a matching pair. Since some .dtx files can exceed 30k lines, this can lock up the parser for quite some time (in addition to parsing everything wrong after the ). I forked directly from the official latex.tmbundle on GitHub, but it could easily be integrated into the other branches. Here's the language as a plain-text format plist: { scopeName = 'text.tex.latex.dtx'; firstLineMatch = '^%\s*\\iffalse\s+(?:meta-)?comment'; fileTypes = ( '.dtx' ); patterns = ( { name = 'text.tex.latex.dtx.implementation'; begin = '(?:^(%) (\\begin){macrocode}|^(%)\s*(\\iffalse\b)(.*)\n)'; end = '(?:^(%) (\\end){macrocode}|^(%)\s*(\\fi)\b)'; beginCaptures = { 1 = { name = 'comment.block.tex.latex.dtx'; }; 2 = { name = 'keyword.control.tex'; }; 3 = { name = 'comment.block.tex.latex.dtx'; }; 4 = { name = 'keyword.control.tex'; }; 5 = { name = 'comment.block.tex.latex.dtx'; }; }; endCaptures = { 1 = { name = 'comment.block.tex.latex.dtx'; }; 2 = { name = 'keyword.control.tex'; }; 3 = { name = 'comment.block.tex.latex.dtx'; }; 4 = { name = 'keyword.control.tex'; }; }; patterns = ( { match = '^(%)(<[\*/]?(?:[A-Za-z0-9!\|]+|.)>)'; captures = { 1 = { name = 'comment.block.tex.latex.dtx'; }; 2 = { name = 'entity.name.selection.tex.latex.dtx'; }; }; }, { include = 'text.tex.latex'; }, ); }, { name = 'comment.block.tex.latex.dtx'; match = '^%'; }, { name = 'text.tex.latex.dtx.documentation'; begin = '(\\CharacterTable)\b'; end = '(?<!\$$}';
beginCaptures = { 1 = { name = 'keyword.control.tex'; }; };
patterns = (
{   name = 'comment.block.tex.latex.dtx';
match = '^%';
},
{   name = 'markup.raw.charactertable';
match = '.';
},
);
},
{   include = 'text.tex.latex'; },
);
}

-