I know dtx file is literate programming style file. I also know that I can compile it with pdflatex to generate pdf file. But I wonder could I just extract the tex code to a independent file? I think I can learn some thing from the tex source.
[Tex/LaTex] convert a dtx file to tex file
dtx
Related Solutions
You can use the rsync
interface of the three main archive servers. Then use the correct rsync
option to only include .dtx
files:
rsync -aP --prune-empty-dirs --include='*/' --include='*.dtx' --exclude='*' rsync://rsync.dante.ctan.org/CTAN alldtxs
However, in my manually installed TeXLive2010 tree the DTX files are included.
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.
Best Answer
A DTX file is already a LaTeX file (sometimes called
.tex
file), however it uses some special things. It contains the description as comment lines and the package source code. It contains a "driver" preamble and body which includes the same file again with the%
comment character disabled, so that the originally commented-out part is now read as normal LaTeX code. You can have a look at the description part simply by looking at the file, if you don't mind the comment style.If you want to turn it into a normal LaTeX file, simply remove the comment
%
characters from the code and completely delete the implementation part. Then I would change the "driver" head part to not include the file but place the description body directly there by removing the\DocInput{..}
and moving the\end{document}
to the end of the file.So basically change:
to:
You can and should still use the
ltxdoc
class.