# Inserting a document with its own internal section numbering in another document

I have a fairly large LaTeX document, with several chapters. In one chapter, I intend to insert another LaTeX document. "In the following pages, we include (DOCUMENT) ..."

I could use `\includepdf`, but I want the inserted document to have the same style as the rest of the work. I could recompile the inserted document in the desired style and then use `\includepdf`. Is there a simpler way?

So: is there some way to make the inserted document have its own section numbering, independent of the sections around it? Internal references in the inserted document should remain consistent. Ideally, the section numbering in the inserted document should differ from the surrounding numbering, for example the numbering could be alphabetic in the inserted document but numerical in the surrounding text. The sections of the inserted document should not occur in the table of contents of the surrounding document.

I have full access to the LaTeX code of the inserted document.

-

## migrated from stackoverflow.comJan 2 '13 at 15:02

This question came from our site for professional and enthusiast programmers.

There probably exists a good way to do what you want, but I have never discovered it. What I have done in your situation is this: I use `\setcounter` and the elements associated with it to save the section number before the excerpt, then to restore it after the excerpt. However, as I said, this is a poor solution, and I shall be interested to read here if someone posts a better one. Otherwise, good luck. –  thb Jan 2 '13 at 13:46

The problem I see here is the table of contents. It's easy to set up something like:

``````\newcounter{sectionsaved}% [...]
\setcounter{sectionsaved}{\value{section}}% [...]
\setcounter{section}{0}% [...]
``````

Then insert your document and after it restore the old sectioning values:

``````\setcounter{section}{\value{sectionsaved}}% [...]
``````

(`[...]` indicates additional counters like `subsection` you may need if you don't start a new section after the insertion.)

One way to switch to alphabetical sectioning would be to alter the `\thesection` command:

``````\let\thesectionold\thesection
\renewcommand\thesection{\Alph{section}}%
``````

After the inserted document `\thesection` can be reset with the command:

``````\let\thesection\thesectionold
``````

Sadly, sectioning commands in the inserted document would produce entries in the table of contents. You could redefine `\section`, `\subsection`, etc. to not write to the toc. However, the most convenient solution might be to stick to `\includepdf`.

-
Adding `\addtocontents{toc}{\setcounter{tocdepth}{-2}}` where you start the document inclusion, restoring the value at the end in a similar way should solve the issue with the TOC. –  egreg Jan 2 '13 at 16:43
Thanks! combined with a hiddensection command as I found here, this solves the problem quite well. –  Wouter Jan 2 '13 at 19:07