# Ways to force LaTeX structure?

Some types of publications like for instance module documentation have a clear structure (for instance first one has an introduction section, at the end source code is provided,...)

I was wondering if it LaTeX or some package can force a user to obey a given structure. If the user fails to write a document according to the specified structure, at least an warning should be printed.

• Put the information into a database and then generate LaTeX from that. Otherwise, not in any way that feels natural, IMHO. Oct 19 '13 at 3:39

As far as I know you can’t enforce the structure, in a way that \section only appear in a distinct order. But you can extend (imitate) the \maketitle mechanism.

Define some macros like

\newcommand{\mc@introduction}{}
\newcommand{\introduction}[1]{%
\renewcommand{\mc@introduction}{#1}%
}


(The mc@ prefix can be chosen freely. I used mc for MyClass …) And use them inside a macro like \makedocument

\newcommand{\makedocument}{%
Some text

\mc@introduction

\let\makedocument\relax
}


The last line ensures that \makedocument can’t be used twice. And with etoolbox you can call \makedocument automatically at the end of the document.

\AtEndDocument{\makedocument}


If some of the information must be provided you may initialize the \mc@introduction macro like this

\newcommand{\mc@introduction}{
\ClassError{myclass}{\string\introduction\space not used.}{%
You must provide the introduction.
}
}


When you redefine the \section you can permit to use it in the document

\renewcommand{\section}[1][]{%
\ClassError{myclass}{Don't use \string\section}{%
You are not allowed to use \string\section
}
}


but you must save the definition before redefining if you want to use it in \makedocument with

\let\addsec\section


This is a full but very rudimentary example:

% myclass-test.tex
\documentclass{myclass}

\begin{document}
\faqs{The order in the document won't change anything.}

\introduction{Text}

%\section{Test}% caues an error

%\makedocument% optional
\end{document}


% myclass.cls
\ProvidesClass{myclass}

\RequirePackage{etoolbox}

\newcommand{\mc@introduction}{
\ClassError{myclass}{\string\introduction\space not used.}{%
You must provide the introduction.
}
}
\newcommand{\introduction}[1]{%
\renewcommand{\mc@introduction}{#1}%
}
\newcommand{\mc@information}{}
\newcommand{\information}[1]{%
\renewcommand{\mc@information}{#1}%
}
\newcommand{\mc@faqs}{}
\newcommand{\faqs}[1]{%
\renewcommand{\mc@faqs}{#1}%
}

\renewcommand{\section}[1][2]{%
\ClassError{myclass}{Don't use \string\section}{%
You are not allowed to use \string\section
}
}

\newcommand{\makedocument}{%
Some text that is always the same in
every single document.