0

Is it possible make the docstrip utility's \generate ignore all lines, that have not been marked by the %<*guard>...%</guard> construct?

This ties in to my (duplicate) question Can docstrip be configured to output ONLY tagged snippets? and the question (How) Can I write a .dtx file without having to comment out *everything*?, which gives partial solutions.

However, a common source of error for me when writing DTX files are lines that are output to the .sty file, that I don't want to output.

Example

Running pdftex on the file gen.ins

\input docstrip.tex
\askforoverwritefalse
\nopreamble\nopostamble
\generate{\file{gen.sty}{\from{gen.ins}{c}}}
%<*c>
Only this region
should be output to
gen.sty
%</c>
stuff after

I want only the tagged part between %<*c> and %</c> to be included in the .sty file. Instead, the .sty file contains

\input docstrip.tex
\askforoverwritefalse
\nopreamble\nopostamble
\generate{\file{gen.sty}{\from{gen.ins}{c}}}
Only this region
should be output to
gen.sty
stuff after

A workaround mentioned in (How) Can I write a .dtx file without having to comment out *everything*? would be to add unused guards around the parts that should not be emitted, but this results in high verbosity, and it retains the risk of misplacing guards.

%<*none>
\input docstrip.tex
\askforoverwritefalse
\nopreamble\nopostamble
\generate{\file{gen.sty}{\from{gen.ins}{c}}}
%</none>
%<*c>
Only this region
should be output to
gen.sty
%</c>
%<*none>
stuff after
%</none>

Note how this format contains double guard lines, while still being brittle against mistakes such as

\nopreamble\nopostamble
%</none>
\generate{\file{gen.sty}{\from{gen.ins}{c}}}
%<*c>
Only this region

Additionally, there are two versions of how to handle the documentation, that come with trade-offs:

  • Export a tex file with \generate, e.g. here by `\generate{\file{gen.sty}{\from{gen.dtx}{c,none}}} and compile it in a separate step. Breaks synctex compatibility.
  • Process the .ins file directly to a pdf. In that version, the guards occur as unwanted visible elements.
  • 2
    no although you could always put in a feature request. What we do is use extra guards then use % \iffalse aroud those so they do not appear in typeset documentation (addressing your second bullet point) – David Carlisle Sep 22 '18 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.