Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get conditional inclusion in TeX / LaTeX

1,562 views
Skip to first unread message

David Allen

unread,
Oct 4, 1994, 10:48:25 AM10/4/94
to
I want to get fine-grained "conditional compilation" of LaTeX source
to produce slightly different documents from the same text. My best
effort so far is:

\newif\if@design \@designfalse
\def\moduledesign{\@designtrue}
\def\design#1{\if@design{#1}\fi}

...

\design{Hello world}

which inserts "Hello world" if \moduledesign has been included.
However, this fails if the conditional text spans more than one
paragraph:

! Argument of \@xdblarg has an extra }.
<inserted text>
\par
<to be read again>
}
\design #1->\if@design {#1}
\fi
l.412 \section
{Implementation}
? x

I tried ifthen.sty, but

\ifthenelse{1 = 0}{
\section{Next}

Para 6.
}

includes the text. Ideally I would like

\begin{design}
Design text.
\end{design}

Can someone point me in the right direction?

Thanks,

David
--
David Allen Laser-Scan Ltd
dav...@lsl.co.uk Science Park
Tel: 01223 420414 Milton Road
Fax: 01223 420044 Cambridge
England

Robin Fairbairns

unread,
Oct 4, 1994, 5:47:31 PM10/4/94
to
In article <DAVIDA.94...@lsld5h.lsl.co.uk>,

David Allen <dav...@lsl.co.uk> wrote:
>I want to get fine-grained "conditional compilation" of LaTeX source
>to produce slightly different documents from the same text. My best
>effort so far is:
>
>\newif\if@design \@designfalse
>\def\moduledesign{\@designtrue}
>\def\design#1{\if@design{#1}\fi}
>
>...
>
>\design{Hello world}
>
>which inserts "Hello world" if \moduledesign has been included.
>However, this fails if the conditional text spans more than one
>paragraph:

... or if there's anything untoward about the skipped text. It's not
a solution I would go for. (However, the problem you outline can be
attacked by defining the macro \long.)

>[...] Ideally I would like


>
>\begin{design}
>Design text.
>\end{design}
>
>Can someone point me in the right direction?

comment.sty solves this problem. [I _think_ it's old enough that I
left a copy on Laser-Scan's discs (in an obvious sort of place on the
VAXcluster) before I left]. As I recall, its documentation is
included in the style file.
--
Robin (Campaign for the Third Programme) Fairbairns r...@cl.cam.ac.uk
U of Cambridge Computer Lab, Pembroke St, Cambridge CB2 3QG, UK
Private page: http://www.cl.cam.ac.uk/users/rf/robin.html

Timothy Murphy

unread,
Oct 4, 1994, 6:01:11 PM10/4/94
to
dav...@lsl.co.uk (David Allen) writes:

>I want to get fine-grained "conditional compilation" of LaTeX source
>to produce slightly different documents from the same text. My best
>effort so far is:

>\newif\if@design \@designfalse
>\def\moduledesign{\@designtrue}
>\def\design#1{\if@design{#1}\fi}

I may have misunderstood what you are trying to do,
but have you considered just saying

\ifundefined\moduledesign
...
\else
...
\fi

?

--
Timothy Murphy
e-mail: t...@maths.tcd.ie
tel: +353-1-2842366
s-mail: School of Mathematics, Trinity College, Dublin 2, Ireland

Graham Gough

unread,
Oct 7, 1994, 10:15:41 AM10/7/94
to David Allen
Have a look at comment.sty on your local CTAN

macros/latex209/contrib/misc/comment.sty


It has facilities for doing exactly what you're asking

e.g.

\documentclass{article}
\usepackage{comment}
\begin{document}
\includecomment{versiona}
\excludecomment{versionb}

\begin{versiona}
AAAAAAAAA
\end{versiona}

\begin{versionb}
BBBBBBBB
\end{versionb}
\end{document}

Graham

0 new messages