2

When generating files with the docstrip utility, it adds a preamble of %-commented lines. This easily violates the syntax of output files, if they are not latex formats.

E.g. running pdftex on the file minimal.dtx (see below), will produce a syntactically incorrect skeleton starting with

%%
%% This is file `minimal.py',
%% generated with the docstrip utility.
%%
%% The original source files were:
%% ...
...
\endinput
%%
%% End of file `minimal.py'.

minimal.dtx

%\iffalse -- Ignore driver section when typesetting.
%<*driver>
\iffalse ---- SINGLE-FILE: INS FILE INCLUDED ---- \fi
\begingroup\input{docstrip}
\askforoverwritefalse
\generate{
  \file{\jobname.py}{\from{\jobname.dtx}{python}}
}
\endgroup
\documentclass{ltxdoc}
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
$</driver>
%\fi
%
%
% \section{Imports}
%    \begin{macrocode}
%<*python>
import sys
import os
%</python>
%    \end{macrocode}
kdb
  • 1,889

1 Answers1

3

The solution is to use the \nopreamble and \nopostamble commands before invoking \generate, which suppress this output.

If the output file is sensitive to empty lines at the beginning of the file, it is additionally important to properly comment out all empty lines, that are not delimited by docstrip tags (%<tag> or %<*tag>...%</tag>).

See docstrip.pdf on CTAN for details.

moewe
  • 175,683
kdb
  • 1,889