# How to modify latex package documentation

Let's say I want to modify the documentation of certain package. I download the .dtx and .ins files and I see that the documentation is in the .dtx file but it's commented. If I compile the .ins file I get the .sty file. Why is the documentation commented and how do I get the .pdf?

• compile the .dtx file directly to get the PDF of the manual. – Steven B. Segletes Feb 14 '15 at 17:14
• Ok that worked. – Arturo Feb 14 '15 at 17:21
• The format of a dtx is interpreted differently by the compiler so that single % are part of the document, double %% remain comments. Stuff in the macrocode environment is extracted by the ins compilations, etc. Very complicated, but it all works. It uses the ltxdoc documentclass. – Steven B. Segletes Feb 14 '15 at 17:30
• @StevenB.Segletes -- you might make that an answer. i don't remember seeing this question elsewhere, at least not phrased in this way. (but you should probably check for duplicates also. unfortunately, i haven't time right now.) – barbara beeton Feb 14 '15 at 20:54

I am not an expert on dtx files, even though I've written a few. If I recall, I took an existing .dtx file and adapted it for my use. Along those lines, I provide a very stripped down sample.dtx file below (and the associated sample.ins). With it, I show both the sample.sty and sample.pdf files that are extracted from it.

What are some of the salient points to take in:

A. the line \generate{\file{sample.sty}{\from{sample.dtx}{package}}} in the ins file says to look in the dtx file for the lines identified as the "package". These are identified in two ways:

1. Lines beginning with <package> identify the package and end up in the sty file.

2. %<*package> and %</package> delimiters in the dtx file identify all intervening lines as the "package", for extracting sample.sty. Within that range, anything starting with a single % is not extracted into the sty file, but anything beginning with a %% is extracted into the sty file as a comment.

B. dtx files use the ltxdoc document class. It follows different rules. I don't know them all, but here are a few takeaways:

1. the %<*driver> and %</driver> delimiters provide code definitions in the standard LaTeX way that may be needed to compile the dtx documentation.

2. The \iffalse and \fi delimiters around the <package> and <driver> regions are necessary. If omitted, the compilation fails.

3. The \CheckSum{} macro is optional and is used to guarantee file integrity after a file transmission. If the argument is incorrect, it generates an error during compilation, telling you what checksum it expected and what checksum you specified. As the package developer, you edit the parameter value to be the same that the compiler told you, and then the error disappears. If the file gets corrupted during transmission, an error will reappear (with modern transmission error corrections, this is something of a quaint throwback).

4. After the %</driver> and % \fi lines, the dtx document compilation follows the ltxdoc rules, in which a leading % is stripped from each line for creating the document.

5. The environment % \begin{macrocode}...% \end{macrocode} (in which the four blank characters between the % and \begin are essential) delimits code that will be displayed as verbatim code. It will be numbered in this case, because \CodelineNumbered was an option in the <driver> code.

6. The environment \begin{macro}{macro-name}...\end{macro} is used to enclose both an associated macrocode environment defining macro-name as well as the description of that macro.

7. According to the LaTeX Companion, \StopEventually{} separates the source file into a "user documentation" and "implementation" part.

8. As to \Finale, this runs anything delayed from the earlier \StopEventually, which doesn't really do anything in this particular example.

With the advent of .ZIP files, I think the need for dtx formats may be lessened. But in the days before .ZIP, putting both code and documentation into a single file was a big plus, both for version control, and for data transmission.

Here is the sample.dtx file that is small enough in size that you can hopefully follow its parts and pieces easily. As to how to modify documentation, you can easily see in this dtx MWE where different parts of the documentation originate. Therefore, I hope that it might help you in understanding what parts of a dtx are modified to reflect changes in the documentation.

% \CheckSum{9}
% \iffalse
%%
%% sample.sty
%%
%<package>\ProvidesPackage{sample}
%<package>[2015/02/16 v1.00
%<package> Tools for absolutely nothing]
%<package>\NeedsTeXFormat{LaTeX2e}
%<*driver>
% V1.00-Initial release (version control could go here)
\documentclass{ltxdoc}
\usepackage{sample}
\DisableCrossrefs
\CodelineNumbered
% DEFINE SOME COMMANDS THAT ARE EASIER HERE THAN IN DocInput ENVIRONMENT
\let\iq\itshape%     SHORTHAND FOR ITALIC  FONT
\let\uq\upshape%     SHORTHAND FOR UPSHAPE FONT
\newcommand\sample{\textsf{sample}}
\GetFileInfo{sample.sty}
\begin{document}
\title{The \textsf{sample} Package\\
\rule{0em}{0.7em}\small\fileinfo}
\author{A. Nonymous\\
nulname@gmail.com}
\date{\filedate\\
\fileversion}
\maketitle
\DocInput{sample.dtx}
\end{document}
%</driver>
% \fi
% \parskip 1ex
% \begin{abstract}
% This is the package abstract
% \end{abstract}
%
% \tableofcontents
%
%\noindent\hrulefill
%
% \section {Introduction}
%
% blah-blah
%
% \subsection{Commands}
%
% This \sample{} package provides the macros named:
%
% \noindent
% |\sampleA[|\iq integer\uq|]{|\iq text\uq|}|\\
% |\sampleB[|\iq integer\uq|]{|\iq text\uq|}|
%
% Here is a description of their use.
%
% \DescribeMacro{\sampleA}
% The routine |\sampleA| is useful for nothing.
%
% \DescribeMacro{\SampleB}
% Likewise, the macro |\sampleB| is also pretty much useless.
%
% \section{Sample Usage}
%
% The code |\sampleA[3]{test}\sampleB[5]{I win.}| will result in
%
% \sampleA[3]{test}\sampleB[5]{I win.}
%
% This package provides little utility. The only thing left
% is the code listing itself.
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Acute accent  \'     Left paren    $$Right paren$$
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  $Backslash \\ %% Right bracket$     Circumflex    \^     Underscore    \_
%%   Grave accent  \     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{mysample}
\setcounter{mysample}{0}
\newcommand\sampleA[2][0]{%
\setcounter{mysample}{#1}%
}
\newcommand\sampleB[2][0]{%
[\themysample]
\setcounter{mysample}{#1}%
#2 NOT!
}
\endinput
%%
%% End of file sample.sty'.

On the other hand, if I compile sample.dtx, I get the following PDF: