Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am writing a documentation for a software environment which will be composed of several subfile put together using the \include command.

The thing is, I would like to be able to output different version of the file so that I can print it for different kind of readers without actually modifying the overall documentation.

For example, I would like to be able to generate a version of the file for the programmers, another for the risk analyst, another for the DB admin, each of them having access to different section.

I know I could create several tex files, each including the right subsections, but I think I saw somewhere a way to do it using a parameter at compile-time.

Anyway, I'm looking for suggestions.


If possible, I would like that the document created for each type of reader looks like it is the complete piece (correct chapter numbering etc...)

share|improve this question
You can use the comment package to define environments which can be enabled and disabled e.g. depending on a macro set in the command line. There are some answer around here showing this. (looking ...) –  Martin Scharrer Jul 7 '11 at 13:36
Found it: Have a look at Whether it's possible to keep translation together with original text? (my answer there shows the use of the comment package). That question is very similar to yours just about text in different languages not different content –  Martin Scharrer Jul 7 '11 at 13:38
charlietanksley.net/philtex/… –  N.N. Jul 7 '11 at 13:42
For passing an option to the document to select which version should be compiled, see Passing parameters to a document. –  Martin Scharrer Jul 7 '11 at 13:45
@Martin Sharrer: thanks. So basically you suggest I use pass a string parameter to the compiler, and the using \if I decide which environment to include. Correct? –  SRKX Jul 7 '11 at 13:54

4 Answers 4

up vote 11 down vote accepted

If the versions differ only for the \included files, you can put in your preamble something like


Compile the whole document, so every reference is correct. In order to produce the "programmers version", call pdflatex as

pdflatex "\nofiles\AtBeginDocument{\programmers}\input{doc.tex}"

(assuming your main document is doc.tex). Similarly for the other categories. The \nofiles is used to avoid clobbering the already final .aux files.

This method has limitations: the page numbers reflect the presence of the omitted chapters, for example.

Different implementation with the comment package




The first line after loading comment will define the environments. As before you can produce the "programmers" version by saying from the command line

pdflatex "\AtBeginDocument{\programmers}\input{doc.tex}"

and similarly for the other versions. This will renumber chapters and pages. If you don't want to clobber the aux files, you can assign a different job name:

pdflatex --jobname=doc-programmers "\AtBeginDocument{\programmers}\input{doc.tex}"
share|improve this answer
Ok thanks! If I want to remove the page breaks between the includes, to you see any reason why I shouldn't use "newclude" –  SRKX Jul 7 '11 at 14:05
As far as I can tell it may break cross references. See also edit. –  egreg Jul 7 '11 at 14:10
"See also edit"? –  SRKX Jul 7 '11 at 14:12
Note, that @egreg's solution will mean that even in the programmers version the chap3 will be labelled as "chapter 3", and there will be a gap in the page numbering where chapter 2 would have gone. Sometimes this is what is wanted, where it's as though the different versions have some pages deleted but otherwise are identical (you can \ref{} to an item that is in an excluded chapter, etc). It's not clear from the question if this is what JSmaga is looking for, though. –  Lev Bishop Jul 7 '11 at 14:16
You have to use a different approach, with the comment package. I'll work to it. –  egreg Jul 7 '11 at 14:54

Tags might come in handy for this use case and luckily there is a LaTeX package (now, v1.0 is from August 2011) called tagging for that. Check out the following mini example.




\tagged{programmers}{Include programmers section}

\tagged{riskanalyst}{Include riskanalyst section}

\tagged{DBadmin}{Include DBadmin section}



LATEX_COMPILER := pdflatex

.PHONY: all
all: Manual_programmers.pdf Manual_programmers.pdf Manual_DBadmin.pdf

    $(LATEX_COMPILER) --jobname="$(basename $@)" "\AtBeginDocument{\usetag{programmers}}\input{main}"

    $(LATEX_COMPILER) --jobname="$(basename $@)" "\AtBeginDocument{\usetag{riskanalyst}}\input{main}"

    $(LATEX_COMPILER) --jobname="$(basename $@)" "\AtBeginDocument{\usetag{DBadmin}}\input{main}"
share|improve this answer

I prefer to have the decision of whether a chapter is included at the point where the chapter is actually included. Something like:


You can use more conditionals as per this question., and options on passing parameters to a document can be found in this question.

share|improve this answer
This requires multiple \ifdefined conditionals in case a chapter needs to be included for more than one version. –  egreg Jul 7 '11 at 19:22
Yep, I realized that after I posed it, and the link to the conditionals should help. This method also allows for a combinations: such as a book for both programmers and DBadmins. –  Peter Grill Jul 7 '11 at 20:23

It may be worth noting that the other way to do this is to maintain your document in XML, where you can define (or use existing) mechanisms to do exactly what you describe. The output dependencies are called effectivities, and XML vocabularies like DocBook have explicit features to handle them. Transformation from XML to LaTeX can be done with XSLT, so you can create unlimited multiple parallel output formats from a single master document.

The downside is that you have to learn how to do it, find a good XML editor, and learn how to write XSLT to generate the LaTeX outputs. Worth it if you have a very large project, or you are already familiar with the basics, or there is money involved :-)

share|improve this answer

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.