.dtx 文件中的 \DefineOptions 位于哪里以及规则是什么?

.dtx 文件中的 \DefineOptions 位于哪里以及规则是什么?

给出demopkg.dtx的来源:

    % \iffalse meta-comment
    % !TEX program  = pdfLaTeX
    %<*internal>
    \iffalse
    %</internal>
    %<*readme>
    ----------------------------------------------------------------
    demopkg --- description text
    E-mail: [email protected]
    Released under the LaTeX Project Public License v1.3c or later
    See https://www.latex-project.org/lppl.txt
    ----------------------------------------------------------------
    
    Some text about the package: probably the same as the abstract.
    %</readme>
    %<*internal>
    \fi
    \def\nameofplainTeX{plain}
    \ifx\fmtname\nameofplainTeX\else
      \expandafter\begingroup
    \fi
    %</internal>
    %<*install>
    \input docstrip.tex
    \keepsilent
    \askforoverwritefalse
    \preamble
    ----------------------------------------------------------------
    demopkg --- description text
    E-mail: [email protected]
    Released under the LaTeX Project Public License v1.3c or later
    See https://www.latex-project.org/lppl.txt
    ----------------------------------------------------------------
    
    \endpreamble
    \postamble
    
    Copyright (C) 2009 by You <[email protected]>
    
    This work 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:
    
    https://www.latex-project.org/lppl.txt
    
    This work is "maintained" (as per LPPL maintenance status) by
    You.
    
    This work consists of the file  demopkg.dtx
    and the derived files           demopkg.ins,
                                    demopkg.pdf and
                                    demopkg.sty.
    
    \endpostamble
    \usedir{tex/latex/demopkg}
    \generate{
      \file{\jobname.sty}{\from{\jobname.dtx}{package}}
    }
    %</install>
    %<install>\endbatchfile
    %<*internal>
    \usedir{source/latex/demopkg}
    \generate{
      \file{\jobname.ins}{\from{\jobname.dtx}{install}}
    }
    \nopreamble\nopostamble
    \usedir{doc/latex/demopkg}
    \generate{
      \file{README.txt}{\from{\jobname.dtx}{readme}}
    }
    \ifx\fmtname\nameofplainTeX
      \expandafter\endbatchfile
    \else
      \expandafter\endgroup
    \fi
    %</internal>
    %<*package>
    \NeedsTeXFormat{LaTeX2e}
    \ProvidesPackage{demopkg}[2009/10/06 v1.0 description text]
    %</package>
    %<*driver>
    \documentclass{ltxdoc}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}
    \usepackage{\jobname}
    \usepackage[numbered]{hypdoc}
    \EnableCrossrefs
    \CodelineIndex
    \RecordChanges
    \begin{document}
      \DocInput{\jobname.dtx}
    \end{document}
    %</driver>
    % \fi
    %
    %\GetFileInfo{\jobname.sty}
    %
    %\title{^^A
    %  \textsf{demopkg} --- description text\thanks{^^A
    %    This file describes version \fileversion, last revised \filedate.^^A
    %  }^^A
    %}
    %\author{^^A
    %  You\thanks{E-mail: [email protected]}^^A
    %}
    %\date{Released \filedate}
    %
    %\maketitle
    %
    %\changes{v1.0}{2009/10/06}{First public release}
    %
    %\DescribeMacro{\examplemacro}
    % Some text about an example macro called \cs{examplemacro}, which
    % might have an optional argument \oarg{arg1} and mandatory one
    % \marg{arg2}.
    %
    %\StopEventually{^^A
    %  \PrintChanges
    %  \PrintIndex
    %}
    %
    %    \begin{macrocode}
    %<*package>
    %    \end{macrocode}
    %
    %\begin{macro}{\examplemacro}
    %\changes{v1.0}{2009/10/06}{Some change from the previous version}
    %    \begin{macrocode}
    \newcommand*\examplemacro[2][]{%
      Some code here, probably
    }
    %    \end{macrocode}
    %\end{macro}
    %
    %    \begin{macrocode}
    %</package>
    %    \end{macrocode}
    %\Finale

我应该在哪里放置 \DefineOptions 块,例如:

    % \begin{macro}{\ifFN@noemph}
    % Define the |noemph| option: This sets a marker for use later
    % when defining the option's auxiliary code and when patching the
    % output routine and so on.
    %    \begin{macrocode}
    \newif\ifFN@noemph \FN@noemphfalse
    \DeclareOption{noemph}{\relax}
    %    \end{macrocode}
    % \end{macro}

我想我忽略了一些显而易见的东西,但像往常一样,我发现其他人的“显而易见”的东西却是晦涩难懂的。

答案1

请注意,您已对示例进行了双缩进,除非您删除每行的 4 个空格,否则它根本不起作用。

\ProvidesPackagedtx 结构看起来比通常更复杂,但可以工作,您需要在以 so 结尾的包开头添加选项部分,\ProcessOptions例如

% \iffalse meta-comment
% !TEX program  = pdfLaTeX
%<*internal>
\iffalse
%</internal>
%<*readme>
----------------------------------------------------------------
demopkg --- description text
E-mail: [email protected]
Released under the LaTeX Project Public License v1.3c or later
See https://www.latex-project.org/lppl.txt
----------------------------------------------------------------

Some text about the package: probably the same as the abstract.
%</readme>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\preamble
----------------------------------------------------------------
demopkg --- description text
E-mail: [email protected]
Released under the LaTeX Project Public License v1.3c or later
See https://www.latex-project.org/lppl.txt
----------------------------------------------------------------

\endpreamble
\postamble

Copyright (C) 2009 by You <[email protected]>

This work 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:

https://www.latex-project.org/lppl.txt

This work is "maintained" (as per LPPL maintenance status) by
You.

This work consists of the file  demopkg.dtx
and the derived files           demopkg.ins,
                                demopkg.pdf and
                                demopkg.sty.

\endpostamble
\usedir{tex/latex/demopkg}
\generate{
  \file{\jobname.sty}{\from{\jobname.dtx}{package}}
}
%</install>
%<install>\endbatchfile
%<*internal>
\usedir{source/latex/demopkg}
\generate{
  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\nopreamble\nopostamble
\usedir{doc/latex/demopkg}
\generate{
  \file{README.txt}{\from{\jobname.dtx}{readme}}
}
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internal>
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{demopkg}[2009/10/06 v1.0 description text]
%</package>
%<*driver>
\documentclass{ltxdoc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{\jobname}
\usepackage[numbered]{hypdoc}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
%\GetFileInfo{\jobname.sty}
%
%\title{^^A
%  \textsf{demopkg} --- description text\thanks{^^A
%    This file describes version \fileversion, last revised \filedate.^^A
%  }^^A
%}
%\author{^^A
%  You\thanks{E-mail: [email protected]}^^A
%}
%\date{Released \filedate}
%
%\maketitle
%
%\changes{v1.0}{2009/10/06}{First public release}
%
%\DescribeMacro{\examplemacro}
% Some text about an example macro called \cs{examplemacro}, which
% might have an optional argument \oarg{arg1} and mandatory one
% \marg{arg2}.
%
%\StopEventually{^^A
%  \PrintChanges
%  \PrintIndex
%}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
% \begin{macro}{\ifFN@noemph}
% Define the |noemph| option: This sets a marker for use later
% when defining the option's auxiliary code and when patching the
% output routine and so on.
%    \begin{macrocode}
\newif\ifFN@noemph \FN@noemphfalse
\DeclareOption{noemph}{\relax}
\ProcessOptions
%    \end{macrocode}
% \end{macro}
%
%\begin{macro}{\examplemacro}
%\changes{v1.0}{2009/10/06}{Some change from the previous version}
%    \begin{macrocode}
\newcommand*\examplemacro[2][]{%
  Some code here, probably
}
%    \end{macrocode}
%\end{macro}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%\Finale

然后在 dtx 上运行 tex 将提取demopkg.sty如下内容

%%
%% This is file `demopkg.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% demopkg.dtx  (with options: `package')
%% ----------------------------------------------------------------
%% demopkg --- description text
%% E-mail: [email protected]
%% Released under the LaTeX Project Public License v1.3c or later
%% See https://www.latex-project.org/lppl.txt
%% ----------------------------------------------------------------
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{demopkg}[2009/10/06 v1.0 description text]
\newif\ifFN@noemph \FN@noemphfalse
\DeclareOption{noemph}{\relax}
\ProcessOptions
\newcommand*\examplemacro[2][]{%
  Some code here, probably
}

相关内容