Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 805
shuhalo Avatar asked May 01 '11 00:05

shuhalo


2 Answers

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.

like image 124
shuhalo Avatar answered Sep 28 '22 05:09

shuhalo


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.

like image 27
Brent.Longborough Avatar answered Sep 28 '22 07:09

Brent.Longborough