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 need to produce two document layouts using the same content. I'm going to be making heavy use of the input{} command to do this, but it is more complex than just this. I'm looking for suggestions how to best build the document.

I have 10 instruments, and each instrument has an intro, calibration, operation, post processing, and maintenance documentation section. So there are 50+ segments to this document.

One version needs to be arranged by instrument, like so:

  • Doc Intro
  • Instrument 1
    • Intro
    • Calib
    • Ops...
  • Instrument 2
    • Intro
    • Calib

etc.

I need a second version of the document that is arranged by order of operations, so:

  • Doc Intro
  • Calibration
    • In 1
    • In 2
    • ...
    • In 10
  • Operations
    • In 1
    • In 2

etc.

As you can see, just writing a shell script to build a wrapper .tex document full of \input{} isn't enough, as each of the input-ed tex documents needs different headers, both depth and title, for example. What is a \subsection{Instrument 1} in one document becomes a \subsubsection{Calibration} in another document, although the exact same text is in the paragraphs below that.

I could have the shell script decide what is a subsection and what is a subsubsection too, but now I'm writing more bash then LaTeX.

Is there something for sections like the itemize environment? For itemize, I don't need to tell it how deep it is with itemitemitemize similar to subsubsubsection, it just handles it automagically.

Any other suggestions on how to best write once and compile twice will be much appreciated.

share|improve this question
add comment

2 Answers 2

up vote 7 down vote accepted

Ok, you have 10 instruments with 6 section each, makes 60 in total. The simplest would be to create 60 input files then. You could use the filecontents environment if you want to not manually create all of the files. These files should not contain the sectioning commands.

Then place the sectioning commands into the two different main files:

% File 1:
\section{Doc Intro}

\section{Instrument 1}
\subsection{Intro}
\input{instr1-intro}
\subsection{Calib}
\input{instr1-calib}
\subsection{Ops}
\input{instr1-ops}
% ...

\section{Instrument 2}
\subsection{Intro}
\input{instr1-intro}
\subsection{Calib}
\input{instr1-calib}
\subsection{Ops}
\input{instr1-ops}
% ...

% etc.

and

% File 2:
\section{Doc Intro}

\section{Calibration}
\subsection{Instrument 1}
\input{instr1-intro}
\subsection{Instrument 2}
\input{instr2-intro}
\subsection{Instrument 3}
\input{instr3-intro}
% ...

\section{Operations}
\subsection{Instrument 1}
\input{instr1-ops}
\subsection{Instrument 2}
\input{instr2-ops}
\subsection{Instrument 3}
\input{instr3-ops}
% ...

% etc.

You could use loops to do this part for you:

\newcount\instrument
\instrument=1
\loop\ifnum\instrument<11\relax
  \section{Instrument \the\instrument}
  \subsection{Intro}
  \input{instr\the\instrument-intro}
  \subsection{Calib}
  \input{instr\the\instrument-calib}
  \subsection{Ops}
  \input{instr\the\instrument-ops}
  % ...
  \advance\instrument by 1\relax
\repeat

and

\section{Calibration}
\loop\ifnum\instrument<11\relax
  \subsection{Instrument \the\instrument}
  \input{instr\the\instrument-calib}
  % ...
  \advance\instrument by 1\relax
\repeat

The \foreach macro of pgf can also be used here and might be easier to handle. It can also iterate over section titles.

share|improve this answer
    
OK. In summary, there are only ~50 sections, not 5000, so don't bother trying to script it, just do it manually. FYI the instruments are named, so simple loops won't suffice. This works just fine, I was trying to over-engineer the solution. –  mankoff Mar 10 '11 at 22:41
add comment

Is there something for sections like the itemize environment? For itemize, I don't need to tell it how deep it is with itemitemitemize similar to subsubsubsection, it just handles it automagically.

\sections aren't usually environments, and this is the problem with a one-size-fits-all \section. For instance, how would LaTeX know if the next \section was a child section or a sibling section?

But maybe you could implement document divisions as environments, and then keep track of the section depth that way.

share|improve this answer
add comment

Your Answer

 
discard

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.