# Some TeX Developments

Coding in the TeX world

## Working with dtx files

I’ve talked a bit about the dtx file format and given an example of a skeleton dtx file. I thought I’d talk next about working with sources, which will be a bit of a scattered post but will hopefully be interesting!

# Editing dtx files

As with any TeX source, you don’t have to have a special editor to work with dtx files, but it can be helpful. Many people say that Emacs (using AUC-TeX) has the best dtx editing mode of all: I’ve only tried it briefly, but the AUC-TeX homepage has the details. On Windows, WinEdt has a pretty strong DTX Submode which does similar things. As I mainly use TeXworks, I’ve made a few modifications to get something similar to those two ‘leaders’: at the moment I use the following settings for syntax highlighting:

[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}

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

# Macrocode
green		N	^%[\s]{4}\\(?:begin|end)\{macrocode\}

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

# LaTeX packages
darkblue	N	\\usepackage\s*(?:$[^]]*$\s*)?\{[^}]*\}

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

# Non-code
grey		Y	%.*

which is certainly helping me to improve my understanding of regex writing! There are a few things I can’t seem to get working quite as I’d ideally like, but for the moment I’m happy.

For auto-completion, I’ve had to make some assumptions about the beginnings of lines, to get the % characters correct:

%%!TEX encoding = UTF-8 Unicode
arg:=\Arg{#INS#}
bcode:=    \begin{macrocode}#RET##INS##RET#%    \end{macrocode}#RET#•
benv:=\begin{environment}{#INS#}#RET#%•#RET#%\end{environment}#RET#%•
bmac:=\begin{macro}{#INS#}#RET#%•#RET#%\end{macro}#RET#%•
cc:=\changes{#INS#}{•}{•}#RET#•
cmd:=\cmd{#INS#}
cs:=\cs{#INS#}
denv:=\DescribeEnv{#INS#}
dmac:=\DescribeMacro{#INS#}
dopt:=\DescribeOption{#INS#}
ecode:=    \end{macrocode}#RET##INS#%    \begin{macrocode}#RET#•
eenv:=\end{environment}#RET#
emac:=\end{macro}#RET#
m:=\meta{#INS#}
meta:=\meta{#INS#}
pkg:=\pkg{#INS#}
\Arg{#INS#}
\changes:=\changes{#INS#}{•}{•}#RET#•
\cmd{#INS#}
\cs{#INS#}
\meta{#INS#}
\pkg{#INS#}`

I’d be interested to hear how other people find TeXworks for writing TeX code, and of course for any contributions to my configuration ideas.

Written by Joseph Wright

April 12th, 2009 at 10:20 am

Posted in TeXworks