The DTX format allows to generate both the package code (.sty file) and documentation (.pdf file) from a single dtx file.

Is it possible to generate several PDFs (for example for different languages) from a single dtx file?

  • I think dtx is good for producing multiple package files, but it will require a lot of work to maintain multiple document files similarly, because you will have to use <*option> … </option> everywhere. I'd go with a different approach. Commented Sep 16, 2011 at 7:21

2 Answers 2


My answers is split in two parts: first I show how DTX files, i.e. docstrip tags, can be used to extract different parts for different language and then I discuss the issue that you have in a real DTX file for a package.

In general you can use the docstrip tags <*lang1> ... </lang1> to mark all file sections which contain the text for the first language etc., e.g. <*de> .. </de> for German. Then use a INS file (as you should already have for your DTX file) to extract this parts to a TEX file which can then be compiled separately. A "DTX" file which only holds these texts would look something like:

Common part

Then have a INS file like this:

\input docstrip.tex

And compile it as follows:

tex <name>.ins
latex <name>-en
latex <name>-de
latex <name>-klingon

However, note that the normal documentation in a DTX file is commented out, so that it is not (and cannot) be extracted. If you want to have multiple languages in one DTX file you could use some if-switches in the documentation part and then have a small wrapper which sets this if-switch accordantly. I did something like this for my adjustbox package.

There I have at the beginning of the DTX file, just before \documentclass the following code which define the if-switch if it doesn't exists and sets it to true:

\expandafter\ifx\csname ifenglish\endcsname\relax
    \expandafter\newif\csname ifenglish\endcsname

In the document I use it like this:

   Do you wish a cup of tea?    % (British) English
   Wie willst du deinen Kaffee? % German (we drink coffee!)

Then at the end I have the following wrapper code which sets the if-switch to false which enables the German parts and simply inputs the DTX file. For this to work you need to use an explicit name in \DocInput{<name>.dtx} and not \jobname.

% \iffalse
%% Wrapper to set language to German.
\expandafter\newif\csname ifenglish\endcsname
% \fi

The INS file contains instructions to extract this to to a TEX file:

\input docstrip.tex

Then to compile the manual in English run latex <name>.dtx, to extract the STY and other TEX file use: tex <name>.ins and then latex <name>-de to compile the German manual.

  • 6
    Thanks for including Klingon in your example, that's exactly the language I wanted to write documentation for!
    – raphink
    Commented Sep 16, 2011 at 8:52
  • 3
    @Raphink: The Vulcans will be disappointed if you don't include them :-) Commented Sep 16, 2011 at 8:57
  • For the record, I will accept the answer as soon as I find the time to test and apply it.
    – raphink
    Commented Sep 20, 2011 at 14:54

You can use .dtx file to generate several .tex files, and compile them separately. Then you'll get multiple documents.

  • 3
    Do you mind elaborating on this?
    – N.N.
    Commented Sep 16, 2011 at 7:02
  • @N.N. Martin has done for that. After all, it is not very difficult to do that for package developers. My answer is more a notation than a full solution.
    – Leo Liu
    Commented Sep 16, 2011 at 9:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .