# How to get a correct README when using a dtx file

I use Joseph Wright's model dtx file. Unfortunately, when using it, the generated README.txt file contains parts of the package code, which is of course unwanted.

The rather long minimal example is appended at the end. The important part regarding my question is quite on the top, where only "Text" should end up in the README.txt to my understanding:

%<*readme>
Text


Text
\endbatchfile


Why is that? What did I do wrong?

% \iffalse meta-comment
%<*internal>
\iffalse
%</internal>
Text
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
\expandafter\begingroup
\fi
%</internal>
%<*install>
\input docstrip.tex
\keepsilent
\preamble
Preamble
\endpreamble
\postamble
Postamble
\endpostamble
\usedir{tex/latex/tikzscale}
\generate{
\file{\jobname.sty}{\from{\jobname.dtx}{package}}
}
%</install>
%<install>\endbatchfile
%<*internal>
\usedir{source/latex/tikzscale}
\generate{
\file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\nopreamble\nopostamble
\usedir{doc/latex/tikzscale}
\generate{
}
\ifx\fmtname\nameofplainTeX
\expandafter\endbatchfile
\else
\expandafter\endgroup
\fi
%</internal>
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{tikzscale}[2012/09/10 v0.1 tikzscale LaTeX package]
%</package>
%<*driver>
\documentclass{ltxdoc}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
%\GetFileInfo{\jobname.sty}
%
%\title{Title}
%\author{Author}
%\date{Released \filedate}
%
%\maketitle
%
%\changes{v0.1}{2012/09/10}{First public release}
%
% Text
%
%
%\StopEventually{^^A
%  \PrintChanges
%^^A  \PrintIndex
%}
%
%\Finale

-

You have an 'unguarded' code line. If you have a line in the .dtx which does not start % and is 'outside' of the guards, it appears in every extracted file. You can see that if you look in the .sty or .ins files. So you want

%    \begin{macrocode}
%<*package>
%</package>
%    \end{macrocode}


or

% \iffalse
%<*package>
% \fi
%    \begin{macrocode}
%    \end{macrocode}
% \iffalse
%</package>
% \fi


or similar.

Not linked to the issue, but the line

%<readme>\endbatchfile


is also spurious.

-
if you're thinking of distributing via ctan, please note that ctan needs README, not README.txt -- renaming it slows us down, so please try to remember that the .txt bit is a mistake. (my apologies if you weren't intending that the package be submitted to ctan.) –  wasteofspace Sep 11 '12 at 9:42
@wasteofspace It's not possible to get DocStrip to create a file with no extension: TeX will not do this. So the best that can be done in the .dtx is to use a sensible extension. (In the build scripts I've also discussed on my blog, I think I've mentioned something similar and include a rename part.) –  Joseph Wright Sep 11 '12 at 10:15
@JosephWright Thanks for the great answer, for the additional information and for the original code. I added a hardlink to README.txt with name README. The latter one is now used in my ctanify script. That might be a good compromise, given the constraints you mentioned here and on your blog. –  MMM Sep 11 '12 at 20:19
@wasteofspace Thanks a lot for mentioning, I'd had overseen this issue otherwise, as the plan is to distribute this package via ctan one day. –  MMM Sep 11 '12 at 20:21