# Reusing the same tex files in different base files

I have a number of .tex files containing sections which are \input{} into a large document. I'd now like to create an "excerpt" document that includes only a subset of these sections. The problem is, the hierarchy level should be different in the excerpt than in the main document. That is, in the main document the concerned section may be a \subsection, but in the excerpt it must be a \section (i.e. everything moves up a level). Is there a way to handle this hierarchy level correctly in different files using \input{}?

• You could just put `\renewcommand\subsection{\section}` and similar redefinitions in the preamble for the excerpt. – Ian Thompson Mar 13 '15 at 8:41
• That's a great idea. I guess this still means that I'd have to be consistent with hierarchy differential though? i.e. I can't have a \subsection and a \subsubsection from the original document both be \sections in the excerpt... That may be too much to ask in any case. Thanks for your help! – mindthief Mar 13 '15 at 9:07
• You could rename `\subsubsection` to `\section` as well if you want to. Anything is possible with `TeX`... – Ian Thompson Mar 13 '15 at 9:19
• Right but the \subsection itself has \subsubsections which should be preserved as one-level-below. So these \subsubsections should become \subsections, while other stand-alone \subsections used should become \sections... I guess I could just have all the .tex files without sectioning tags and manually add those tags in each base file. Would be tedious though, since that would mean having a separate .tex file for every section, subsection, subsubsection, ... – mindthief Mar 13 '15 at 9:27

Since in comments you imply that you want to change the relative levels rather than just move a branch up or down the hierarchy, I'd use custom commands in the input files.

If `qqqq.tex` looks like

``````\sectA{zzzz}
zz zz zz
\sectB{thing}
xx xx xx
\sectB{more things}
ww ww ww
``````

Then one document can go

``````\newcommand\sectA{\section}
\newcommand\sectB{\section}
\input{qqq}
``````

with everything at the same level, and another can go

``````\newcommand\sectA{\subsection}
\newcommand\sectB{\subsubsection}
\input{qqq}
``````

with A headings a level down and B headings two levels down

• I think that just might do it! – mindthief Mar 13 '15 at 9:47