Simple preprocessor for latex: detect whether you are an included file or being compiled stand-alone
Asked Answered
O

2

6

I work on a huge script in \latex.

I want to be able to compile each of the chapters as stand-alone, because it is easier for hacking sessions with Latex.

On the other hand, I would like to maintain a document which encompasses the whole script so far written.

I do not know how to maintain both these documents without permanently annoying overhead, as a tex-file can either be written stand-alone or to be included.

It would be great help to have something a Latex-preprocessor available that is capable of C-like #define and #ifdef-#else-#endif statements. This would facilitate writing to a great extent. Do you know whether something like this exists in latex, or how can you do something equivalent? Google hasn't supplied me with a satisfying answer to this.

EDIT: Some remarks in order to avoid misunderstandings: I am aware of the very simple built-in TEX-preprocessor, but these commands don't work properly as I expected. Hence a reference to these will not help me out.

The chapters in my script shall look something like this (Pseudo-Code)

IF being_just_included defined
   %No header here, and document has already begun
ELSE
\input{common_header.tex} %Header things all my documents use
\begin{document}
ENDIF

%%% Lots of stuff

IF being_just_included defined
   %Nothing to do here
ELSE
   \end{document}
END IF

In contrast, my complete script source file should look like this

\input{common_header.tex}
DEFINE being_just_included
\begin{document}
\input{preamble.tex}
\input{first_chapter.tex}
\input{second_chapter.tex}
\input{third_chapter.tex}
\end{document}

Could you post a code which performs something like this?

Opportuna answered 1/5, 2011 at 0:9 Comment(0)
W
2

One way of doing this is to use the standalone package, intended for this specific purpose.

You may also care to browse through, and perhaps join, TeX and Friends.

Wheel answered 1/5, 2011 at 11:20 Comment(1)
I don't see what part of the package you actually meant to use. The proposal of @Opportuna seems to work fine. Including the chapters as finished PDF does not allow for references or a global toc. Or could you explain how this works with the standalone package?Saleratus
O
3

Thank you very much for this package and the hint to the forum.

After some time I've figured out there exists a tex preprocessor, which is similar to the CPP. Maybe not well-engineered, but it serves my purpose quite well.

The magic lines are:

\def\justbeingincluded{justbeingincluded}

\ifx\justbeingincluded\undefined

\fi

to be used appropiatly within the respective source files.

Opportuna answered 2/5, 2011 at 4:12 Comment(1)
I'm sure it works, but it's a bit like using Assembler for your website instead of CSS...Wheel
W
2

One way of doing this is to use the standalone package, intended for this specific purpose.

You may also care to browse through, and perhaps join, TeX and Friends.

Wheel answered 1/5, 2011 at 11:20 Comment(1)
I don't see what part of the package you actually meant to use. The proposal of @Opportuna seems to work fine. Including the chapters as finished PDF does not allow for references or a global toc. Or could you explain how this works with the standalone package?Saleratus

© 2022 - 2024 — McMap. All rights reserved.