% \iffalse
%
%% File l3dosctrip.dtx Copyright (C) 2012 The LaTeX3 Project
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
%% license or (at your option) any later version. The latest version
%% of this license is in the file
%%
%% http://www.latex-project.org/lppl.txt
%%
%% This file is part of the "l3kernel bundle" (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%%
%% The released version of this bundle is available from CTAN.
%%
%% -----------------------------------------------------------------------
%%
%% The development version of the bundle can be found at
%%
%% http://www.latex-project.org/svnroot/experimental/trunk/
%%
%% for those people who are interested.
%%
%%%%%%%%%%%
%% NOTE: %%
%%%%%%%%%%%
%%
%% Snapshots taken from the repository represent work in progress and may
%% not work or may contain conflicting material! We therefore ask
%% people _not_ to put them into distributions, archives, etc. without
%% prior consultation with the LaTeX Project Team.
%%
%% -----------------------------------------------------------------------
%%
%
%
\def\ExplFileDate{2012/06/08}
\def\ExplFileName{l3docstrip}
\def\ExplFileVersion{3787}
%
%
% The same approach as used in \textsf{DocStrip}: if \cs{documentclass}
% is undefined then skip the driver, allowing the file to be used to extract
% \texttt{l3docstrip.tex} from \texttt{l3docstrip.dtx} directly. This works
% as the \cs{fi} is only seen if \LaTeX{} is not in use. The odd \cs{jobname}
% business allows the extraction to work with \LaTeX{} provided an appropriate
% \texttt{.ins} file is set up.
%
\ifx\jobname\relax\let\documentclass\undefined\fi
\ifx\documentclass\undefined
\else \csname fi\endcsname
%
\def\filename{docstrip.dtx}
\documentclass[full]{l3doc}
\ExplSyntaxOn
\cs_set_eq:NN \__codedoc_replace_at_at:N \use_none:n
\ExplSyntaxOff
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%
\fi
%
%
% \fi
%
% \title{^^A
% The \pkg{l3docstrip} package\\ Code extraction and manipulation^^A
% \thanks{This file describes v\ExplFileVersion,
% last revised \ExplFileDate.}^^A
% }
%
% \author{^^A
% The \LaTeX3 Project\thanks
% {^^A
% E-mail:
% \href{mailto:latex-team@latex-project.org}
% {latex-team@latex-project.org}^^A
% }^^A
% }
%
% \date{Released \ExplFileDate}
%
% \maketitle
%
% \begin{documentation}
%
% \section{Extending \textsf{DocStrip}}
%
% The \pkg{l3docstrip} module adds \LaTeX3 extensions to the \textsf{DocStrip}
% program for extracting code from \texttt{.dtx}. As such, this documentation
% should be read along with that for \textsf{DocStrip}.
%
% \section{Internal functions and variables}
%
% An important consideration for \LaTeX3 development is separating out public
% and internal functions. Functions and variables which are private to one
% module should not be used or modified by any other module. As \TeX{} does
% not have any formal namespacing system, this requires a convention for
% indicating which functions in a code-level module are public and which are
% private.
%
% Using \pkg{l3docstrip} allows internal functions to be indicated using a
% \enquote{two part} system. Within the \texttt{.dtx} file, internal functions
% may be indicated using |@@| in place of the module name, for example
% \begin{verbatim}
% \cs_new_protected:Npn \@@_some_function:nn #1#2
% {
% % Some code here
% }
% \tl_new:N \l_@@_internal_tl
% \end{verbatim}
%
% To extract the code using \pkg{l3docstrip}, the \enquote{guard} concept
% used by \textsf{DocStrip} is extended by introduction of the syntax
% \texttt{\%
% %
% \cs_new_protected:Npn \@@_some_function:nn #1#2
% {
% % Some code here
% }
% \tl_new:N \l_@@_internal_tl
% %
% \end{verbatim}
% will be extracted as
% \begin{verbatim}
% \cs_new_protected:Npn \__foo_some_function:nn #1#2
% {
% % Some code here
% }
% \tl_new:N \l__foo_internal_tl
% \end{verbatim}
% where the |__| indicates that the functions and variables are internal
% to the \texttt{foo} module.
%
% \end{documentation}
%
% \begin{implementation}
%
% \section{\pkg{l3docstrip} implementation}
%
% \begin{macrocode}
%
% \end{macrocode}
%
% We start by loading the existing \textsf{DocStrip} code using the \TeX{}
% input convention.
% \begin{macrocode}
\input docstrip %
% \end{macrocode}
%
% \begin{macro}{\checkOption}
% The \cs{checkOption} macro is defined by \textsf{DocStrip} and is redefined
% here to accommodate the new \texttt{\%#2\endLine{%
\maybeMsg{}%
\prepareActiveModule{#1}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\prepareActiveModule}
% \begin{macro}{\replaceModuleInLine}
% Here, we set up to do the search-and-replace when doing the extraction.
% The argument (|#1|) is the replacement text to use, or if empty an
% indicator that no replacement should be done. The search material is
% one of |__@@|, |_@@| or |@@|, done in order such that all three will end
% up the same in the output. The replacement function is initialised as a
% do-nothing for the case where |%
\advance\codeLinesPassed\@ne
%
\maybeMsg{.}%
\def\inLine{#1}%
\replaceModuleInLine
\let\do\putline@do
\activefiles
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\doOption}
% As \textsf{DocStrip} processes each line, a line starting with |% ...stats-only code to include...|.
% The original definition of \cs{doOption} did not use \cs{inLine} but I believe we're safe to do so.
% \begin{macrocode}
\def\doOption#1>#2\endLine{%
\maybeMsg{}%
\Evaluate{#1}%
\def\do##1##2##3{%
\if1\Expr{##2}%
\def\inLine{#2}%
\replaceModuleInLine
\StreamPut##1{\inLine}%
\fi
}%
\activefiles
}
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
%
% \end{macrocode}
%
% \end{implementation}
%
% \PrintIndex