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?

shuhalo
  • 4,851
  • 6
  • 37
  • 53

2 Answers2

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.

shuhalo
  • 4,851
  • 6
  • 37
  • 53
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.

Brent.Longborough
  • 8,787
  • 10
  • 38
  • 60
  • 1
    I don't see what part of the package you actually meant to use. The proposal of @shuhalo 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? – strpeter Sep 12 '18 at 08:22