在 dtx 文件中索引没有前导反斜杠的宏

在 dtx 文件中索引没有前导反斜杠的宏

我正在记录一个包含多个biblatexbibmacros 和布尔值的文件,并希望通过创建一个索引\EnableCrossrefs,但是

% \begin{macro}{mybibmacro}
%    \begin{macrocode}
\newbibmacro{mybibmacro}{}
%    \end{macro}

产生条目

\mybibmacro

在索引中,当然,mybibmacro代码中所有后续出现的 都会被忽略。有没有办法避免使用前导反斜杠?当然,如果将来出现诸如

\usebibmacro{mybibmacro}

也将被编入索引mybibmacro

\newbool{mybool}

有完全相同的问题。

结合这个真实的例子可以得出:

% \iffalse
\documentclass{ltxdoc}
\EnableCrossrefs         
\CodelineIndex
\begin{document}
  \DocInput{test.dtx}
\end{document}
% \fi
%
% \DescribeEnv{mybibmacro}
% This is my bibmacro.
%
% \DescribeMacro{mybool}
% The boolean \verb|mybool| will determine, if \verb|mybibmacro| is executed.
% 
% \StopEventually{\PrintIndex}
%
% \begin{macro}{mybool}
% Here we define the boolean.
%    \begin{macrocode}
\newbool{mybool}
%    \end{macrocode}
% \end{macro}
%
% \begin{environment}{mybibmacro}
% Here we define the bibmacro.
%    \begin{macrocode}
\newbibmacro{mybibmacro}{}
%    \end{macrocode}
% \end{environment}
%
% Now the macro is executed depending on the status of \verb|mybool|. Ideally, both should be indexed as being used here.
%    \begin{macrocode}
\ifbool{mybool}{\usebibmacro{mybibmacro}}{}
%    \end{macrocode}
% 
% \Finale

通过 latex 和 makeindex 运行此操作可得出

带索引的编译 dtx 文件

在索引中mybool收到了前导反斜杠,并且在第 3 行中既没有索引mybool也没有mybibmacro索引用法。

mybibmacro此外,下面的列表environments有点令人困惑,最好摆脱它,当然,如果除了环境之外还可以添加其他类别(例如布尔值,bibmacro等),那就最好了。

答案1

可能你想要(滥用)使用或基于某些东西,\begin{environment}而不是\begin{macro}因为那不是预期的反斜杠形式


首先给出一个适用于环境使用的扩展,因为它更简单,下一节中将提供一个更完整的示例。

这里有一个例子,修改doc使得\begin{foo}宏代码中的使用不会被索引为使用\begin,而是因为环境的使用foo \end会自动从索引列表中排除。

测试2.sty

\def\macro@finish{%
  \macro@namepart
\ifx\macro@namepart\xbegin
  \expandafter\macro@grabname
  \else  
\ifx\macro@namepart\xend
 \else
  \ifnot@excluded
     \edef\@tempa{\noexpand\SpecialIndex{\bslash\macro@namepart}}%
     \@tempa  \fi
  \fi\fi}

\def\xbegin{begin}
\def\xbegin{end}
\begingroup
\lccode`\(`\{
\lccode`\)`\}
\lowercase{\endgroup
\def\macro@grabname\fi(#1){%
(#1)%
\SpecialEnvIndex{#1}%
}
}

测试2.dtx

% \iffalse
\documentclass{ltxdoc}
\usepackage{test2}
\EnableCrossrefs         
\CodelineIndex
\begin{document}
  \DocInput{test2.dtx}
\end{document}
% \fi
%
% \DescribeMacro{\mymacro}
% Some meaningful description.
% 
% \StopEventually{\PrintIndex}
%
% \begin{macro}{\mymacro}
% Here we define the macro.
%    \begin{macrocode}
\newcommand{\mymacro}{hello}
%    \end{macrocode}
% \end{macro}

% \begin{environment}{myenv}
% Here we define the env.
%    \begin{macrocode}
\newenvironment{myenv}{\par[[[}{]]]\par}
%    \end{macrocode}
% \end{environment}
%
% And here we use it.
%    \begin{macrocode}
\PackageInfo{test2}{\mymacro}
%    \end{macrocode}
%    \begin{macrocode}
\def\foo{\begin{myenv}kkk\end{myenv}}
%    \end{macrocode}
% \clearpage
%    \begin{macrocode}
\def\foobar{\begin{myenv}jjj\end{myenv}}
%    \end{macrocode}
% 
% \Finale

处理方式如下:

pdflatex test2.dtx
makeindex -s gind.ist test2
pdflatex test2.dtx

请注意,它doc并不关心宏是如何定义的,只是关心它的外观,它\begin{environment}开始定义但不显示反斜杠的宏,并在“环境”(标准文档)下对其进行索引。这里的补充是,它begin{foo}被索引为环境使用。因此,如果您有一个包含 bibmacro 定义形式的包,并且使用 as,则\newbibmacro需要将环境的定义从doc(包括上述扩展)复制到一组相同但environment更改为bibmacro并更改为的宏,然后再次更改为\begin或您需要的任何其他非反斜杠定义/使用类别。\usebibmacroboolean


完整 BibLaTeX 版本

因此,采用上述方法然后基本上参数化环境代码,使其适用于environment bibboolbibmacro产生以下结果: 在此处输入图片描述

测试布尔值

% \iffalse
\documentclass{ltxdoc}
\usepackage{test2}
\EnableCrossrefs         
\CodelineIndex
\begin{document}
  \DocInput{testbool.dtx}
\end{document}
% \fi
%
% \DescribeBibMacro{mybibmacro}
% This is my bibmacro.
%
% \DescribeBibBool{mybool}
% The boolean \verb|mybool| will determine, if \verb|mybibmacro| is executed.
%
% \DescribeMacro{\texmacro}
% Checking I haven't broken the original
% indexing macros  for \verb|\texmacro|.
%
% \StopEventually{\PrintIndex}
%
% \begin{bibbool}{mybool}
% Here we define the boolean.
%    \begin{macrocode}
\newbool{mybool}
%    \end{macrocode}
% \end{bibbool}
%
% \begin{macro}{\texmacro}
% Here we define the boolean.
%    \begin{macrocode}
\def\texmacro{}
%    \end{macrocode}
% \end{macro}
%
% \begin{bibmacro}{mybibmacro}
% Here we define the bibmacro.
%    \begin{macrocode}
\newbibmacro{mybibmacro}{}
%    \end{macrocode}
% \end{bibmacro}
%
% Now the macro is executed depending on the status of \verb|mybool|. Ideally, both should be indexed as being used here.
%    \begin{macrocode}
\ifbool{mybool}{\usebibmacro{mybibmacro}}{}
%    \end{macrocode}
% 
%    \begin{macrocode}
\texmacro
%    \end{macrocode}
% 
% \Finale

测试2.sty

\def\bibmacro{\def\macro@type{bibmacro}\environment}
\let\endbibmacro\endenvironment


\def\bibbool{\def\macro@type{bibbool}\environment}
\let\endbibbool\endenvironment

\def\macro@type{environment}%% default

\def\macro@finish{%
  \macro@namepart
\ifx\macro@namepart\xbegin
  \def\macro@type{environment}%
\else\ifx\macro@namepart\xifbool
   \def\macro@type{bibbool}%
   \let\macro@namepart\xbegin
\else\ifx\macro@namepart\xusebibmacro
 \def\macro@type{bibmacro}%
 \let\macro@namepart\xbegin
\fi\fi\fi
\ifx\macro@namepart\xbegin
  \expandafter\macro@grabname
  \else  
\ifx\macro@namepart\xend
 \else
  \ifnot@excluded
     \edef\@tempa{\noexpand\SpecialIndex{\bslash\macro@namepart}}%
     \@tempa  \fi
  \fi\fi}

\def\xbegin{begin}
\def\xifbool{ifbool}
\def\xusebibmacro{usebibmacro}
\def\xend{end}
\begingroup
\lccode`\(`\{
\lccode`\)`\}
\lowercase{\endgroup
\def\macro@grabname\fi(#1){%
(#1)%
\SpecialxEnvUseIndex\macro@type{#1}%
}
}


\def\SpecialxEnvUseIndex#1{%
  \expandafter\SpecialxxEnvUseIndex\expandafter{#1}}

\def\SpecialxxEnvUseIndex#1#2{\@bsphack
    \special@index{#2\actualchar{\string\ttfamily\space#2}
           (#1)}%
    \special@index{#1s:\levelchar#2\actualchar{\string\ttfamily\space#2}}\@esphack}



\def\SpecialMainEnvIndex{%
   \expandafter\SpecialMainxEnvIndex\expandafter{\macro@type}}

\def\SpecialMainxEnvIndex#1#2{\@bsphack\special@index{%
                                      #2\actualchar
                                      {\string\ttfamily\space#2}
                                         (#1)%
                                      \encapchar main}%
    \special@index{#1s:\levelchar#2\actualchar{%
                   \string\ttfamily\space#2}\encapchar
           main}\@esphack}


\def\DescribeBibBool{%
\leavevmode\@bsphack\begingroup\MakePrivateLetters
\def\macro@type{bibbool}\begingroup\Describe@Env}

\def\DescribeBibMacro{%
\leavevmode\@bsphack\begingroup\MakePrivateLetters
\def\macro@type{bibmacro}\begingroup\Describe@Env}

\def\DescribeBibEnv{%
\leavevmode\@bsphack\begingroup\MakePrivateLetters
\def\macro@type{environment}\begingroup\Describe@Env}


\def\Describe@Env#1{\endgroup
              \marginpar{\raggedleft\PrintDescribeEnv{#1}}%
              \SpecialEnvIndex{#1}\endgroup\@esphack\ignorespaces}

\def\SpecialEnvIndex{%
   \expandafter\SpecialxEnvIndex\expandafter{\macro@type}}

\def\SpecialxEnvIndex#1#2{\@bsphack
    \index{#2\actualchar{\string\ttfamily\space#2}
           (#1)\encapchar usage}%
    \index{#1s:\levelchar#2\actualchar{\string\ttfamily\space#2}\encapchar
           usage}\@esphack}

相关内容