GeneralSet chapter/section programmatically

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
espinchi
Posts: 2
Joined: Sat Aug 30, 2008 6:26 pm

Set chapter/section programmatically

Post by espinchi »

Hi all,

The problem I'm facing is the following: I want to write two documents that share most of the content. One will be my master thesis, and the other a user manual for the application, which will contain a subset of the sections of the whole work.

For the thesis, I'm using a "book" document class. However, I want "article" for the latter. Therefore, I will be declaring "chapters - sections" in one while "sections - subsections" in the other.

I've come up with two solutions so far:
1. declare some commands for the chapter, sections, etc... that I can customize for both versions:

Code: Select all

\newcommand{\mychapter}{\chapter}
\newcommand{\mysection}{\section}
for the thesis.

Code: Select all

\newcommand{\mychapter}{\section}
\newcommand{\mysection}{\subsection}
for the manual.

This way, every time I want to compile a PDF, I just comment out the ones that not apply.

2. use the package ifthen, so I can set a variable that says which mode we want to compile for (thesis or manual), and then generate chapter or section.


Now, the problem which these aproaches is that the TOC is not generated. Does anyone know how can I fix this?

(Note that I do *not* want to rewrite any text, that's why I'm having this headache.)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Set chapter/section programmatically

Post by Stefan Kottwitz »

Hi espinchi,

welcome to the board!
You could try \let\chapter\section etc., have a look at this demonstration example:

Code: Select all

\documentclass[a4paper,10pt]{book}
\begin{document}
\tableofcontents
\chapter{Test1}
\section{test1}
\let\chapter\section
\let\section\subsection
\chapter{Test2}
\section{test1}
\end{document}
But it's just a hack.

Stefan
LaTeX.org admin
espinchi
Posts: 2
Joined: Sat Aug 30, 2008 6:26 pm

Re: Set chapter/section programmatically

Post by espinchi »

Thanks!

I had forgotten that you need to build the project twice in order to generate the TOC :oops:.

FYI, the way I've finally done it is: a main.tex file where the documentclass and the mysection, mysubsection, ... are defined, and include sentences to reference the body of the final document. I define a flag "isThesis" in the preamble, which will decide if "mysection" is a "chapter" or a "section", for instance. This way keeping both versions is pretty easy :)
Post Reply