TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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. – Andrey Vihrov Sep 16 '11 at 7:21
up vote 14 down vote accepted

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 (has you should already have for you 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.

share|improve this answer
Thanks for including Klingon in your example, that's exactly the language I wanted to write documentation for! – ℝaphink Sep 16 '11 at 8:52
@Raphink: The Vulcans will be disappointed if you don't include them :-) – Martin Scharrer Sep 16 '11 at 8:57
For the record, I will accept the answer as soon as I find the time to test and apply it. – ℝaphink Sep 20 '11 at 14:54

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

share|improve this answer
Do you mind elaborating on this? – N.N. Sep 16 '11 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 Sep 16 '11 at 9:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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