# Make appendix files work for both book and article document classes

I have a book with chapters, sections, subsections, etc. I frequently want to distribute a single chapter of the book as a stand-alone article. To do this, I just write a replacement preamble setting the documentclass to article.

There's a catch. In the book class the appendices are marked with the \chapter command, but in the article class they're marked with \section.

Is there an easy way to make the same appendix files work for both classes?

My solution so far has been to make a new command I call varsec which takes two arguments:

1. The type of section (chapter, section, subsection).

2. The name of the section.

I mark the appendices as \varsec{chapter}, and then in the article preamble I make \varsec{chapter} produce \section, while in the book preamble I make it produce \chapter.

Is there a better way?

• It might be better if you explained what you actually want to achieve because the finer nuances of the technical term "organizational chunk" may be lost on many of the readers of TeX.SX:) It is quite likely that you can achieve what you want by setting tocdepth etc to appropriate values. Another approach, which I use, is to include your chapters as separate files using \include commands., Then youcan use \includeonly{...} to print only certain chapters. – Andrew May 8 '15 at 6:48
• @Andrew I understand the value of explaining what one wants to achieve instead of asking how to execute a particular task. However, I think I did explain what I want to achieve in the post, so I need some feedback. What's unclear? – DanielSank May 8 '15 at 6:51
• Daniel, as I said, I have no idea what an "organizational chunk" is. Further, the most likely interpretation can be catered for using standard latex flags such as tocdepth. You should explain what you want to do in terms of layout rather than in terms of redefining commands as there may well be easier ways to achieve the desired output. – Andrew May 8 '15 at 6:54
• try this \let\artappendix\appendix\renewcommand\appendix{\artappendix\let\chapter\section} in article preambl – touhami May 8 '15 at 7:03
• You could also have a look at package coseoul. – Johannes_B May 8 '15 at 7:07

Suppose this is the code of book

\documentclass{book}
\usepackage{lipsum}

\begin{document}
\tableofcontents
\chapter{first}% or \include
\lipsum
\appendix
\chapter{first appe}% or \include
\lipsum
\chapter{first appe}
\lipsum

\end{document}


this will be the article

\documentclass{article}
\usepackage{lipsum}
\let\chapter\part
\begin{document}
\tableofcontents
\chapter{first appe}% or \include
\lipsum
\chapter{first appe}
\lipsum

\end{document}

• This sort of works, but does unhappy things to the TOC. – DanielSank May 8 '15 at 7:37
• @DanielSank what do you mean exactly – touhami May 8 '15 at 7:49
• Did you try compiling your example with a TOC? The pieces marked as \part get bigger font in the TOC. The headings in the document are also bigger than the headings for the \sections. – DanielSank May 8 '15 at 7:56
• @DanielSank this is the idea, otherwise you canreplace \part by \section – touhami May 8 '15 at 7:58
• Yeah, using \section is much better. Still better is to use my own label, e.g. \appendix and then set that to either \chapter or \section, which is roughly what is proposed in OP, but your idea of using \let is better than using a two argument macro. – DanielSank May 8 '15 at 15:09