DocStrip 不喜欢词汇表吗?

DocStrip 不喜欢词汇表吗?

我有一个相当不错的想法,将所有术语表放入 DTX 文件中。我可以按域/主题将任何术语划分为名为 domain.sty/topic.sty 的样式文件,并加载相关内容。所以我浏览了检查清单

  • DTX - 从 Pakin 先生的 dtxtut 文档复制并修改
  • INS - 复制并修改自 Pakin 先生的 dtxtut 文档
  • STY - 从上述来源生成
  • DTX 生成的文档中的词汇表...没有?

我快速浏览了一下 glossaries.dtx,但似乎其中没有包含词汇表……真是讽刺。所以现在是 wiMoWE 时间(“好吧,这只是最小(不是)工作示例”,用丛林中的曲调唱出来……)。

我已附上完整的 example.dtx 和 example.ins,它们应生成 example.pdf 以及包含各种 example.glo/gls/ind/idx 词汇表文件的 example.sty 文件。精明的编译器可能会注意到 example.egn/egd/egg 文件的创建,这些文件是由于在 sty 文件中创建的“\newglossary”而生成的,并且在编译 dtx 文件时生成。

遵循的编译过程是

pdflatex example.idx
makeglossaries example

我收到错误

Package glossaries Warning: No file defined for glossary `[' on input line 86.
! Extra \endcsname.
\@@do@wrglossary ...\csname glo@#1@type\endcsname
                                                  ]{\string \glossaryentry {...
l.86 ...lossary type. It has a single \gls{entry}
                                                  in it.

如果注释掉第 86 行的 \gls{...} 调用,错误就会消失,尽管那时您也不会得到词汇表条目。奇怪的是,在我的原始代码中,我尝试使用 \glsaddall,它引发了类似的错误。样式文件在其他文档中调用时运行良好,只是反向引用 DTX 源不起作用,也许 texdoc 有点挑剔?

示例.dtx

 % \iffalse meta-comment
 %
 % Copyright (C) XXXX by Carel <[email protected]>
 % ----------------------------------------
 % 
 % This file may be distributed and/or modified under the
 % conditions of the LaTeX Project Public License, either version 1.2
 % of this license or (at your option) any later version.
 % The latest version of this license is in:
 %
 %    http://www.latex-project.org/lppl.txt
 %
 % and version 1.2 or later is part of all distributions of LaTeX 
 % version 1999/12/01 or later.
 %
 % \fi
 %
 % \iffalse
 %<*driver>
 \ProvidesFile{example.dtx}
 %</driver>
 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
 %<package>\ProvidesPackage{example}
 %<*package>
     [2004/11/05 v1.0 .dtx example file]
 %</package>
 %
 %<*driver>
 \documentclass{ltxdoc}
 \usepackage[nomain]{glossaries}
 \usepackage{example}[2004/11/05]
 \EnableCrossrefs         
 \CodelineIndex
 \RecordChanges
 \makeglossaries
 \begin{document}
   \DocInput{example.dtx}
   \PrintChanges
   \PrintIndex
 \end{document}
 %</driver>
 % \fi
 %
 % \CheckSum{0}
 %
 % \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) \#
 %   Dollar        \$     Percent       \%     Ampersand     \&
 %   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         \~}
 %
 %
 % \changes{v1.0}{2004/11/05}{Initial version}
 %
 % \GetFileInfo{example.dtx}
 %
 % \DoNotIndex{\newcommand,\newenvironment}
 % 
 %
 % \title{The \textsf{Example} package\thanks{This document
 %   corresponds to \textsf{example}~\fileversion, dated \filedate.}}
 % \author{Carel \\ \texttt{[email protected]}}
 %
 % \maketitle
 %
 % \section{Introduction}
 %
 % Put text here.
 %
 % \section{Usage}
 %
 % Put text here.
 %
 % \DescribeEnv{notes}
 %  
 % Notes is an example glossary type. It has a single \gls{entry} in it.
 %
 % \StopEventually{}
 %
 % \section{Implementation}
 %
 % \begin{environment}{notes}
 % I define an example glossary environment called |notes|.
 %    \begin{macrocode}
 \newglossary[egg]{example}{egd}{egn}{Example glossary}
 %    \end{macrocode}
 % \end{environment}
 %
 % \begin{macro}{notes}
 % I define a single entry in the new glossary format
 %    \begin{macrocode}
 \newglossaryentry{entry}{
  name        = entry,
  type        = example,
  description = An example entry in notes,
 }
 %    \end{macrocode}
 % \end{macro}
 %
 % \Finale
 \endinput

例子.ins

 %%
 %% Copyright (C) XXXX by carel <[email protected]>
 %%
 %% This file may be distributed and/or modified under the conditions of
 %% the LaTeX Project Public License, either version 1.2 of this license
 %% or (at your option) any later version.  The latest version of this
 %% license is in:
 %% 
 %%    http://www.latex-project.org/lppl.txt
 %% 
 %% and version 1.2 or later is part of all distributions of LaTeX version
 %% 1999/12/01 or later.
 %%

 \input docstrip.tex
 \keepsilent

 \usedir{tex/latex/example}

 \preamble

 This is a generated file.

 Copyright (C) XXXX by carel <[email protected]>

 This file may be distributed and/or modified under the conditions of
 the LaTeX Project Public License, either version 1.2 of this license
 or (at your option) any later version.  The latest version of this
 license is in:

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

 and version 1.2 or later is part of all distributions of LaTeX version
 1999/12/01 or later.

 \endpreamble

 \generate{\file{example.sty}{\from{example.dtx}{package}}}

 \obeyspaces
 \Msg{*************************************************************}
 \Msg{*                                                           *}
 \Msg{* To finish the installation you have to move the following *}
 \Msg{* file into a directory searched by TeX:                    *}
 \Msg{*                                                           *}
 \Msg{*     skeleton.sty                                          *}
 \Msg{*                                                           *}
 \Msg{* To produce the documentation run the file skeleton.dtx    *}
 \Msg{* through LaTeX.                                            *}
 \Msg{*                                                           *}
 \Msg{* Happy TeXing!                                             *}
 \Msg{*                                                           *}
 \Msg{*************************************************************}

 \endbatchfile

(注意:命令“texdoc --view PACKAGE”返回 PACKAGE 的文档,这是一个非常有用但尚未宣传的命令,“texdoc --view dtxtut”将提供 Pakins 先生的教程)

更新:为什么?

我的所有 dtx 文件都位于一个文件夹中,其中包含名称与 dtx 文件相对应的子文件夹。我已将它们连接/链接到 TeX 目录结构 (TDS),因此更新宏只需重新编译 DTX。新包只需要复制我的 DTX 模板,构建和链接构建的目录到 TDS,并刷新文件名数据库 (FNDB)(我在 MikTex 上)。将我的词汇表制作成包意味着我的文档和词汇表之间不需要到处连接。我只需 \usepackage{Glossary},tex 就会帮我完成搜索。此外,我可以轻松地将所有术语编译到包文档中以供快速参考。我想分发也变得更容易了,邮寄 dtx。版本控制也变得更加细粒度,如果您愿意,可以在每次新定义后提交。

有关的 :

我的实际 DTX 比 MWE 中显示的要复杂一些,我发现有关的帖子也相关。

答案1

我调整了你的源代码,使之真正成为现实Example.dtx,因为在标准 TeX 分布中Example.ins已经有一个。example.sty

Example.dtx

% \iffalse meta-comment
%
% Copyright (C) XXXX by Carel <[email protected]>
% ----------------------------------------
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.2
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
%    http://www.latex-project.org/lppl.txt
%
% and version 1.2 or later is part of all distributions of LaTeX
% version 1999/12/01 or later.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{Example.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{Example}
%<*package>
   [2004/11/05 v1.0 .dtx Example file]
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage[nomain]{glossaries}
\usepackage{Example}[2004/11/05]
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\makeglossaries
\begin{document}
 \DocInput{Example.dtx}
 \PrintChanges
 \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
% \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) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   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         \~}
%
%
% \changes{v1.0}{2004/11/05}{Initial version}
%
% \GetFileInfo{Example.dtx}
%
% \DoNotIndex{\newcommand,\newenvironment}
%
%
% \title{The \textsf{Example} package\thanks{This document
%   corresponds to \textsf{Example}~\fileversion, dated \filedate.}}
% \author{Carel \\ \texttt{[email protected]}}
%
% \maketitle
%
% \section{Introduction}
%
% Put text here.
%
% \section{Usage}
%
% Put text here.
%
% \DescribeEnv{notes}
%
% Notes is an example glossary type. It has a single \gls{entry} in it.
%
% \StopEventually{}
%
% \section{Implementation}
%
% \begin{environment}{notes}
% I define an example glossary environment called |notes|.
%    \begin{macrocode}
\newglossary[egg]{example}{egd}{egn}{Example glossary}
%    \end{macrocode}
% \end{environment}
%
% \begin{macro}{notes}
% I define a single entry in the new glossary format
%    \begin{macrocode}
\newglossaryentry{entry}{
name        = entry,
type        = example,
description = An example entry in notes,
}
%    \end{macrocode}
% \end{macro}
%
% \printglossaries% added for testing purposes - just to be sure
%
% \Finale
\endinput

Example.ins

%%
%% Copyright (C) XXXX by carel <[email protected]>
%%
%% This file may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.2 of this license
%% or (at your option) any later version.  The latest version of this
%% license is in:
%%
%%    http://www.latex-project.org/lppl.txt
%%
%% and version 1.2 or later is part of all distributions of LaTeX version
%% 1999/12/01 or later.
%%

\input docstrip.tex
\keepsilent

\usedir{tex/latex/example}

\preamble

This is a generated file.

Copyright (C) XXXX by carel <[email protected]>

This file may be distributed and/or modified under the conditions of
the LaTeX Project Public License, either version 1.2 of this license
or (at your option) any later version.  The latest version of this
license is in:

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

and version 1.2 or later is part of all distributions of LaTeX version
1999/12/01 or later.

\endpreamble

\generate{\file{Example.sty}{\from{Example.dtx}{package}}}

\obeyspaces
\Msg{*************************************************************}
\Msg{*                                                           *}
\Msg{* To finish the installation you have to move the following *}
\Msg{* file into a directory searched by TeX:                    *}
\Msg{*                                                           *}
\Msg{*     Example.sty                                           *}
\Msg{*                                                           *}
\Msg{* To produce the documentation run the file Example.dtx     *}
\Msg{* through LaTeX.                                            *}
\Msg{*                                                           *}
\Msg{* Happy TeXing!                                             *}
\Msg{*                                                           *}
\Msg{*************************************************************}

\endbatchfile

得出的结果如下Example.sty

%%
%% This is file `Example.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% Example.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) XXXX by carel <[email protected]>
%% 
%% This file may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.2 of this license
%% or (at your option) any later version.  The latest version of this
%% license is in:
%% 
%%   http://www.latex-project.org/lppl.txt
%% 
%% and version 1.2 or later is part of all distributions of LaTeX version
%% 1999/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{Example}
   [2004/11/05 v1.0 .dtx Example file]
\newglossary[egg]{example}{egd}{egn}{Example glossary}
\newglossaryentry{entry}{
name        = entry,
type        = example,
description = An example entry in notes,
}
\endinput
%%
%% End of file `Example.sty'.

以及以下文档:

示例.pdf

如果您使用不区分大小写的文件系统,则应使用其他名称,否则可能会以不可预测的方式Example混淆。example

所以一切似乎都有效。话虽如此,我并不完全确定你为什么要这样做。也就是说,据我所知,当你只想创建一个词汇表时,为什么要这么麻烦呢.dtx.insglossaries软件包已经允许您以简单的格式保存词汇表条目的数据库.tex。我按主题列出了一大堆,然后可以只加载我需要的条目。如果我添加新条目或更改它们,它们会立即可用 - 无需费力重新生成.sty文件。

.dtx/ stuff.ins旨在帮助分发软件包,但即使您正在分发主题词汇表,那么一个简单的.tex词汇表文件存档不是更简单吗?

相关内容