# How to include preamble-only commands in .dtx file?

I am trying to write my first package using Doc and DocStrip but I have problems including preamble-only commands into the documentation. For example I want to include \allowdisplaybreaks inside \begin{macrocode} ... \end{macrocode}. But then Doc seems to try to make the command available for the documentation and this fails since \allowdisplaybreaks is contained in the document part.

Is there a way to stop Doc from treating certain commands as macros which also should be available during the documentation?

EDIT: To make it more precise: this

%\begin{macro}{\allowdisplaybreaks}
% page breaks allowed in long formulas
%    \begin{macrocode}
\allowdisplaybreaks
%    \end{macrocode}
%\end{macro}


is part of my .dtx file, but when running it I get a "Undefined control sequence"-error, but it works if I replace \allowdisplaybreaks by some \newcommand.

EDIT 2: So here is package.dtx

% \iffalse
%<*driver>
\ProvidesFile{package.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[2005/12/01]
%<package>\ProvidesPackage{package}
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{package}[2004/11/05]
\usepackage{amsmath}

\begin{document}
\DocInput{package.dtx}
\end{document}
%</driver>
% \fi

%\begin{macro}{\allowdisplaybreaks}
% page breaks allowed in long formulas
%    \begin{macrocode}
\allowdisplaybreaks
%    \end{macrocode}
%\end{macro}
% \Finale
\endinput


As stated above I get a "! Undefined control sequence. l.24 \allowdisplaybreaks"-error.

• Welcome to TeX.SX! Could you please make a small code example of what you're trying to achieve (MWE)? – TeXnician Feb 5 '18 at 10:20
• Assuming you have a driver, etc., you'll be fine. However, we will need some idea of the full structure of your .dtx. – Joseph Wright Feb 5 '18 at 11:22
• you are only loading amsmath in the documentation driver and only using \allowdisplaybreaks in the package code. You need to add \allowdisplaybreaks in the driver section and add \RequirePackage{amsmath} to your package code. – David Carlisle Feb 5 '18 at 14:44
• @JosephWright : I added a (hopefully extensive enough) code example – Marvin Dippell Feb 5 '18 at 14:47

You have used \usepackage{amsmath} in the documentation, but if you want to allow display breaks in the doc, you need to add it. Conversely if your package code is using \allowdisplaybreaks then it probably should have \RequirePackage{amsmath}

% \iffalse
%<*driver>
\ProvidesFile{package.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[2005/12/01]
%<package>\ProvidesPackage{package}
%
%<*driver>
\documentclass{ltxdoc}
\usep*ackage{package}[2004/11/05]
\usepackage{amsmath}
\allowdisplaybreaks
\begin{document}
\DocInput{package.dtx}
\end{document}
%</driver>
% \fi
%\begin{macro}{\allowdisplaybreaks}
% page breaks allowed in long formulas
%    \begin{macrocode}
\RequirePackage{amsmath}
\allowdisplaybreaks
%    \end{macrocode}
%\end{macro}
% \Finale
\endinput