[texhax] vanishing tab characters and docstrip

Mathias Bauer listensammler at gmx.net
Mon Oct 19 17:42:57 CEST 2009


Hello list!

With docstrip and the package doc, I want to generate commented
Makefile code (and code using other programming languages, too)
instead of LaTeX code.  Running either tex or latex on the .ins
installation file
    latex test.ins
kills all tab characters at the beginning of a line.  Because of
the Makefile syntax requiring tab characters at the beginning of
some lines, docstrip's behaviour is unsolicited and in some sense
"erroneous".

Here are the two files of a minmalistic example, the .ins
installation file `test.ins' and the .dtx documented source code
file `test.dtx':

----------snip---------- test.ins ----------snip----------
\input docstrip
% ---------- Misc ----------
%\keepsilent%
%\showprogress%
%\askforoverwritefalse%
%\askforoverwritetrue%
% ---------- LaTeX driver ----------
\generate{\file{test-driver.tex}{\from{test.dtx}{driver}}}%
% ---------- Makefile ----------
% Trick from bibexports
{\catcode`\#=12%
  \gdef\DoubleSharp{##}}%
\let\MetaPrefix\DoubleSharp%
\preamble%
Preamble for the Makefile.
\endpreamble%
% Trick from apacite
\edef\noendinputpostamble{%
  \MetaPrefix ^^J%
  \MetaPrefix\space End of `\outFileName'.}%
\generate{\usepostamble\noendinputpostamble%
  \file{test-makefile.txt}{\from{test.dtx}{makefile}}}%
\endbatchfile
----------snap---------- test.ins ----------snap----------

and

----------snip---------- test.dtx ----------snip----------
% \iffalse
%<*driver>
\ProvidesFile{test.dtx}%
\documentclass{article}%
\usepackage{doc}%
\AlsoImplementation\CodelineIndex\listfiles
\begin{document}\DocInput{test.dtx}\end{document}%
%</driver>
% \fi
% Documentation\ldots
% \StopEventually{}
% Implementation\ldots
%    \begin{macrocode}
%<*makefile>
# Lines starting with tab character:
all:
	echo Hello world!
	@echo Hello world again!
	printf "Hello\tworld!\n"
# Lines starting with blanks:
 one
  two
   three
%</makefile>
%    \end{macrocode}
% \Finale
----------snap---------- test.dtx ----------snap----------

Searching for an explanation of docstrip's behavior, I looked
into docstrip.tex and its documentation.  There, the macro
\readsource (l. 584) reads the .dtx documented TeX file line
after line and calls \processLine (l. 344).  \processLine uses
\normalLine (l. 314+) - and all seems to be very unsuspicious to
me.

\def\normalLine#1\endLine{%
  \maybeMsg{.}%
  \def\inLine{#1}%
  \let\do\putline at do
  \activefiles
}

Then the macro \putline at do is executed

\def\putline at do#1#2#3{%
  \StreamPut#1{\inLine}}

and finally the real work is be done by \StreamPut (l. 203):

\def\StreamPut{\immediate\write}

I didn't find any implementation of \immediate or \write either
in docstrip.tex nor in the whole LaTeX code (source2e), so it
seems to be pure TeX (which I didn't know much about).  But where
in this whole process the tab characters vanish?

How can I avoid docstrip killing tab characters at the input
line's beginning?  Can anybody give me a hint?

Many thanks in advance,
Mathias


More information about the texhax mailing list