# How to convert a document from article to report?

Is there another way of doing this besides doing a manual find "section"/ replace all with "chapter" (and the same for subsections, subsubsections etc.) ?

-

Here is a unix script that gives you the option to shift things outward (i.e. for article to report) or inward (report to article, or beamer).

#!/bin/bash

if [ $# -lt 2 ] then echo "need input file name, 0 (out) or 1 (in) " >&2 exit 1 fi # strips .tex from filename to append _out.tex or _in.tex input="$1"
filename=${input%.*x} # 0 shifts all headings outward (section->chapter, etc) # 1 shifts all headings outward (chapter->section) if [$2 -eq 0 ]
then
newfile="$filename""_out.tex" sed -e 's/\\section{/\\chapter{/g' \ -e 's/\\subsection{/\\section{/g' \ -e 's/\\subsubsection{/\\subsection{/g' \ -e 's/\\paragraph{/\\subsubsection{/g' \ -e 's/\\subparagraph{/\\paragraph{/g' \ "$1" > $newfile echo "Saved as$newfile"
elif [ $2 -eq 1 ] then newfile="$filename""_in.tex"
sed -e 's/\\paragraph{/\\subparagraph{/g' \
-e 's/\\subsubsection{/\\paragraph{/g' \
-e 's/\\subsection{/\\subsubsection{/g' \
-e 's/\\section{/\\subsection{/g' \
-e 's/\\chapter{/\\section{/g' \
-e 's/Chapter /\\S/g' \
-e 's/Chapters /\\S/g' \
-e 's/chapter/section/g' \
"$1" >$newfile

echo "Saved as \$newfile"
else
echo "invalid direction, 0 (out) or 1 (in) " >&2
fi

-
Nice one! Please note also the -i switch of sed, for in-place replacement. –  krlmlr Jul 12 '13 at 0:25

The timing of actions is crucial if all levels must be promoted: we have to start from the lowest level up and use \let.

\let\subparagraph\paragraph
\let\paragraph\subsubsection
\let\subsubsection\subsection
\let\subsection\section
\let\section\chapter


Using \renewcommand would turn all section levels into chapters.

However this can work only for very elementary documents without cross references. A complete solution should redefine also the counters and their representation.

\let\thesubparagraph\theparagraph
\let\theparagraph\thesubsubsection
\let\thesubsubsection\thesubsection
\let\thesubsection\thesection
\let\thesection\thechapter

\makeatletter
\let\c@subparagraph\c@paragraph
\let\c@paragraph\c@subsubsection
\let\c@subsubsection\c@subsection
\let\c@subsection\c@section
\let\c@section\c@chapter
\let\p@subparagraph\p@paragraph
\let\p@paragraph\p@subsubsection
\let\p@subsubsection\p@subsection
\let\p@subsection\p@section
\let\p@section\p@chapter
\let\cl@subparagraph\cl@paragraph
\let\cl@paragraph\cl@subsubsection
\let\cl@subsubsection\cl@subsection
\let\cl@subsection\cl@section
\let\cl@section\cl@chapter
\makeatother

-
But is that the correct thing to do? I know this works, but it does not 'feel right'. I would much favor replacements done in an editor. –  Taco Hoekwater Jul 28 '11 at 9:10
No, it isn't the "correct" way to do it. Also all the related macros have to be changed. –  egreg Jul 28 '11 at 9:16
@Taco I've supplemented the macros; using a "find and replace" starting from \section downward would certainly be better. –  egreg Jul 28 '11 at 9:28
@egreg there is a small typo I cannot edit: \let\theparagraph\the\subsubsection should be \let\theparagraph\thesubsubsection –  Tobias Aug 5 '13 at 19:21

I might be a bit overkill, but I would use sed for that instead of pure TeX.

-
Every good editor sports a "find and replace all" feature. One has only to be careful and start from the top: \section to \chapter, then \subsection to \section and so on. Also with sed multiple passes are needed. –  egreg Jul 28 '11 at 10:30
Using Texlipse, I ended up doing this as well. –  ptikobj Jul 28 '11 at 12:47

Besides replacing/redefining the sectioning commands as noted in the other answers, one thing to remember is also updating the reference descriptions when using \ref. If your text reads

As seen in Section \ref{sec:first}, ...


after conversion to a report it should become

As seen in Chapter \ref{sec:first}, ...


If you consistently use the cleveref package's \cref command, this is a non-issue:

As seen in \cref{sec:first}, ...


The command infers the type of the reference from the label and places a textual description in front of the actual section/chapter number. I really see no reason not to use this package.

-