2

I have to publish a document in two versions:

  1. Original full version
  2. Chapters that have been published elsewhere must be excluded

My problem is related to version 2. Simply removing the appropriate chapters does not work since I have three restrictions:

  1. I must keep the original page numbering (even though there will be numbering gaps)
  2. The table of contents must be identical for both versions
  3. In case of removed chapters I have to include a page which indicates that the chapter content is not there because it has been published elsewhere

To give an example, the following would be the “original full version”:

  • Contents
    • Chapter 1…………1
    • Chapter 2…………28
    • Chapter 3…………86
  • Chapter 1 (pp. 1-27)
  • Chapter 2 (pp. 28-85)
  • Chapter 3 (pp. 86-110)

Let’s assume “Chapter 2” has been published elsewhere. Hence, I have to remove pages 28-85. In addition I have to show a note on page 28 that the contents are not available because they have been published elsewhere. Hence, within the *.pdf-file page 86 follows immediately after page 28 (numbering gap). Examples for page 28 for both versions:

Page 28: Original full version:

Original full version

Page 28: Reduced version (chapter 2 has been excluded):

Version where chapter 2 has been excluded

Using \includeonly and \nofiles allows me to remove chapters while keeping page numbering and the table of contents. However, I can't figure out how to replace the original "Chapter"-page with a reduced one as shown above.

A perfect solution would allow me to use some kind of switch to compile different versions.

Anonymous
  • 121
  • Have your chapters that shall be excluded a substructure with \section etc? –  Dec 31 '16 at 02:10

1 Answers1

1

You can do like this:

\documentclass{book}
\usepackage{etoolbox}

\usepackage{lipsum}

\newif\iffullversion
%\fullversiontrue

\newcommand{\extrainclude}[3]{%
  \iffullversion\else
    \expandafter\preto\csname cp@#1\endcsname{%
      \chapter{#2}
      The contents of this chapter has already appeared in \cite{#3}
      \cleardoublepage
    }
  \fi
  \include{#1}
}

\iffullversion\else
  \includeonly{chapter1,chapter3}
\fi

\begin{document}

\frontmatter

\tableofcontents

\mainmatter

\include{chapter1}

\extrainclude{chapter2}{This will not appear}{whatever}

\include{chapter3}

\begin{thebibliography}{1}

\bibitem{whatever} I. Myself, My precious paper, 2015.

\end{thebibliography}

\end{document}

Instead of the bibliography entry you can modify the definition of \extrainclude to use differently the third argument where you can insert the full data.

If you uncomment the \fullversiontrue line, the whole document will be produced. Do it before commenting it, of course.

The trick is that if chapter2.tex is excluded from \includeonly, LaTeX will execute the macro \csname cp@chapter2\endcsname, to which we prepend the suitable action; then the standard behavior will follow, which is resetting the counters to their previous value.

egreg
  • 1,121,712