我想使用 listofsymbols 包进行命名,基本操作似乎运行良好。我能够定义符号并通过各自的命令调用它们。出现了两个错误。首先:由于某种原因,我无法在公式中使用罗马下标。如果没有它,它可以\mathrm
正常工作,使用新符号\mathrm
可以正常工作,但不能作为描述为 B 的符号中的下标。
调用 listofsymbols 时出现第二个错误。实际上错误会成倍增加,但使用最小示例(仅使用符号 A)时,会出现 2 个错误,其中提到一些未定义的旧字体命令,而\bf
我只是使用 LaTex,似乎无法理解这些错误。
\documentclass{scrreprt}
\usepackage{listofsymbols}
\usepackage{amsmath}
\opensymdef
\newsym[A]{test}{\vec{a}_b}
\newsym[B]{moretest}{\mathbf{\Theta}_\mathrm{asd}}
\closesymdef
\begin{document}
%\listofsymbols
\test\\ \moretest
\end{document}
答案1
我发现问题的根源有以下几个:
代码一瞥符号列表-package(Stefan Spreng 的 LaTeX 包 listofsymbols v0.2,电子邮件:[email protected]
,2003 年 8 月,请参阅https://ctan.org/tex-archive/macros/latex/contrib/listofsymbols)揭示了软件包代码的几个问题:
软件包内部使用旧命令,例如
\bf
更改字体。这些命令已弃用。如果您希望应用它们/如果您希望使用应用它们的软件包,您需要enabledeprecatedfontcommands
向撰稿人-班级。在最后,
listofsymbols.pdf
你会发现一个漂亮的代码列表,其中显示了 的内容listofsymbols.sty
。但是 的代码listofsymbols.sty
根本没有注释。因此,当你试图了解该包试图实现和执行哪些类型的算法时,你完全只能靠自己了。包/.sty 文件没有正确考虑 LaTeX 的读取装置。例如,它并不总是考虑到在标记左花括号后读取装置会切换到状态 M(行中),因此左花括号后的空格会产生空格标记,而这反过来又会在水平模式下产生可见的水平粘连,在收集非分隔参数的开头期间不会丢弃空格标记的情况下。
该包提供了一个选项
pageno
。通过应用包选项,pageno
可以显示页码以指示相关符号/下标的定义位置。这对我来说没有意义,因为页码与生成的输出文件(.dvi 或 .pdf)相关,而符号是在 .tex 源文件中定义的,而不是在生成的输出文件中定义的。
因此,在草稿模式下表示 .tex 源文件的名称和路径以及行号可能更有意义。
该包定义并使用一个命令
\addsymline
将内容写入辅助文件。该命令反过来不考虑\immediate\write
LaTeX 的机制。\protect
这会导致在不方便的时刻扩大诸如
\mathbf
或之类的事情。\mathrm
在不方便的时候扩展事物会导致奇怪的错误消息。
在不方便的时候扩展内容也会导致辅助文件中出现奇怪的东西。例如,通过我们的提问者提供的示例,我在 .sym 文件中发现了以下内容:
\printsymline{\mathbf{\Theta }_\protect \relax \protect \begingroup \immediate \write \@unused \def \MessageBreak \let \protect \edef You're in trouble here. Try typing <return> to proceed.\MessageBreak If that doesn't work, type X <return> to quit. \errhelp \let \def \MessageBreak \def \errmessage LaTeX Error: \mathrm allowed only in math mode. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help \endgroup \relax {asd}}{\mathbf{\Theta }_\protect \relax \protect \begingroup \immediate \write \@unused \def \MessageBreak \let \protect \edef You're in trouble here. Try typing <return> to proceed.\MessageBreak If that doesn't work, type X <return> to quit. \errhelp \let \def \MessageBreak \def \errmessage LaTeX Error: \mathrm allowed only in math mode. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help \endgroup \relax {asd}}{moretest}{B}{1}
我认为这应该是这样的:
\printsymline{\mathbf{\Theta }_\mathrm {asd}}{\mathbf{\Theta }_\mathrm {asd}}{moretest}{B}{\thepage }
这些奇怪的事情反过来会
\errmessage
在输入 .sym 文件时产生奇怪的错误消息。-command
\addsymline
还会将页码 (\thepage
) 写入辅助文件。这意味着页计数器的值是以 的形式写入的\immediate\write
。这没有考虑到输出例程的异步性,因此执行时的页计数器的值\addsymline
不一定是材料作为输出文件/.pdf 文件/.dvi 文件的页面的一部分发送出去时页计数器的值。
我认为这是设计上的问题符号列表-package,实际上不是一个与其他包的兼容性相关的问题。
\addtocontents
我建议使用基于/衍生自 LaTeX 2ε /机制的东西来重新实现\@starttoc
。
文件listofsymbols_CHANGED_BY_UD_IN_2020_03_18.sty
:
%%
%% This is file `listofsymbols_CHANGED_BY_UD_IN_2020_03_18.sty',
%% derived in March 18, 2020 from listofsymbols.sty
%% which is part of the
%%
%% LaTeX package listofsymbols v0.2
%% by Stefan Spreng
%% e-mail: [email protected]
%% August 2003
%%
%% See: https://ctan.org/tex-archive/macros/latex/contrib/listofsymbols
%%
%% IMPORTANT NOTICE:
%%
%% Licence:
%% --------
%%
%% This material is derived from listofsymbols.sty which is
%% subject to the LaTeX Project Public License.
%%
%% This material is subject to the LaTeX Project Public License.
%%
%% For the details of that license see:
%% http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html
%%
%% For the copyright also see the file listofsymbols.dtx.
%%
%% Any modified versions of this file must be renamed
%% with new filenames distinct from listofsymbols.sty.
%%
%% For distribution of the original source see the terms
%% for copying and modification in the file listofsymbols.dtx.
%%
%% Purpose:
%% --------
%%
%% The purpose of this material is providing the functionality
%% of listofsymbols.sty while retaining both the LaTeX2e-\protect-mechanism
%% and delayed writing of page-numbers.
%%
%% My opinion about the "pageno"-option:
%% -------------------------------------
%%
%% By applying the package-option "pageno" page-numbers can be displayed
%% for indicating where the symbol/subscript in question is defined.
%%
%% This does not make sense to me because page-numbers are related
%% to the resulting output-file (.dvi or .pdf)
%% while symbols are defined in the .tex-source-file, not in the resulting
%% output-file.
%%
%% Therefore denoting the name and path of the .tex-source-file and
%% the line-number in draft mode might probably make more sense.
%%
%% The number of the line of .tex-input that currently is processed is
%% available in (La)TeX.
%% In case you wish to obtain the name and path of the current
%% .tex-input-file, Martin Scharrer's currfile-package might be of interest,
%% see: https://www.ctan.org/pkg/currfile .
%%
%% Be that as it may.
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{listofsymbols_CHANGED_BY_UD_IN_2020_03_18}
\RequirePackage{ifthen}
\RequirePackage{calc}
\newboolean{b@nomencl}
\newboolean{b@final}
\newboolean{b@Final}
\newboolean{b@pageno}
\newboolean{b@xspace}
\DeclareOption{nomencl}{\setboolean{b@nomencl}{true}}
\DeclareOption{draft}{\setboolean{b@nomencl}{false}
\setboolean{b@final}{false}\setboolean{b@Final}{false}}
\DeclareOption{final}{\setboolean{b@nomencl}{false}
\setboolean{b@final}{true}\setboolean{b@Final}{false}}
\DeclareOption{Final}{\setboolean{b@nomencl}{false}
\setboolean{b@final}{true}\setboolean{b@Final}{true}}
\DeclareOption{pageno}{\setboolean{b@pageno}{true}}
\DeclareOption{nopageno}{\setboolean{b@pageno}{false}}
\DeclareOption{usexspace}{\setboolean{b@xspace}{true}}
\DeclareOption{noxspace}{\setboolean{b@xspace}{false}}
\ExecuteOptions{draft,nopageno,usexspace}
\ProcessOptions
% Define paraphernalia:
%
\newcommand\los@exchange[2]{#2#1}%
\@ifdefinable\los@csname{%
\long\def\los@csname#1#{\romannumeral\los@@csname{#1}}%
}%
\newcommand\los@@csname[2]{%
\expandafter\los@exchange\expandafter{\csname#2\endcsname}{0 #1}%
}%
\@ifdefinable\losglobaldef{%
\los@csname\@ifdefinable{osglobaldef }{%
\DeclareRobustCommand\losglobaldef{}%
\los@csname\long\def{losglobaldef }#1#2{%
\@ifdefinable{#1}{\gdef#1{#2}}%
}%
}%
}%
\newcommand*\losglobalnamedef{\los@csname\losglobaldef}%
% Defining paraphernalia done.
\newlength{\symindent}
%equal to second argument of \l@figure and \l@table:
\setlength{\symindent}{1.5em}
\newlength{\symwidth}
\setlength{\symwidth}{2.5cm}
\newlength{\sympagenowidth}
\newcommand\los@usedphrase{Symbol used in the document.}
\newcommand\los@unusedphrase{Symbol not used in the document.}
\ifthenelse{\boolean{b@nomencl}}%
{\RequirePackage{nomencl}}%
{}%
\ifthenelse{\boolean{b@xspace}}%
{%
\RequirePackage{xspace}%
\newcommand{\spaceaftersym}{\xspace}%
}{%
\newcommand{\spaceaftersym}{}%
}%
\ifthenelse{\boolean{b@pageno}}%
{%
\settowidth{\sympagenowidth}{9999}%
}{%
\setlength{\sympagenowidth}{0cm}%
}%
\newcommand{\printsymline}[5]{%
\@ifundefined{#3include}{%
\los@csname\protected@edef{#3include}{no}%
}{}%
\ifthenelse{%
\boolean{b@final}%
\AND
\(%
\equal{\los@csname{#3include}}{no}\OR\equal{#4}{}%
\)%
}%
{%
\PackageInfo{listofsymbols_CHANGED_BY_UD_IN_2020_03_18}{symbol/subscript #3 has no or empty description or is not used: omitted}%
}%
{%
\hspace*{\symindent}%
\makebox[\symwidth][l]{\ensuremath{#2}}%
\parbox[t]{\textwidth-\symwidth-\sympagenowidth-16pt}{%
\begin{raggedright}%
\strut
\ifthenelse{\boolean{b@final}}%
{#4}%
{%
\texttt{\char`\\#3} --- #4 (%
\ifthenelse{\equal{\los@csname{#3include}}{yes}}{\los@usedphrase}{\los@unusedphrase}%
)%
}%
\strut
\end{raggedright}%
}%
\ifthenelse{\boolean{b@pageno}}{\hfill#5}{}%
\newline
}%
}%
\newcommand{\losstring}{}%
% \opensymdef / \closesymdef are obsolete with the \@starttoc-\addtocontents-approach.
% Thus make them no-ops:
\newcommand{\opensymdef}{}%
\newcommand{\closesymdef}{}%
\ifthenelse{\boolean{b@Final}}%
{%
\newcommand{\addsymline}[5]{}%
}{%
\newcommand{\addsymline}[5]{%
\renewcommand{\losstring}{\string}%
\addtocontents{#5}{%
\string\printsymline{\string#1}{\string#2}{\string#3}{#4}{\thepage}%
}%
\renewcommand{\losstring}{}%
}%
}%
\newcommand{\@createsym}[3]{%
\losglobalnamedef{#2}{%
\relax
\ensuremath{#3}%
\markasused{#2}%
\spaceaftersym
}%
\losglobalnamedef{#2doc}{#1}%
\losglobalnamedef{#2tabdoc}{%
\ensuremath{#3}%
}%
\losglobalnamedef{#2isused}{no}%
}%
\ifthenelse{\boolean{b@nomencl}}%
{%
\newcommand{\newsym}[3][]{%
\@bsphack
\@createsym{#1}{#2}{#3}%
\ifthenelse{\equal{#1}{}}%
{}%
{\nomenclature{\ensuremath{#3}}{#1}}%
\@esphack
}%
}%
{%
\newcommand{\newsym}[3][]{%
\@bsphack
\@createsym{#1}{#2}{#3}%
\addsymline{#3}{#3}{#2}{#1}{sym}%
\@esphack
}%
}%
\newcommand{\@createsub}[3]{%
\losglobalnamedef{#2}{%
\relax
\ensuremath{_{#3}}%
\markasused{#2}%
\spaceaftersym
}%
\losglobalnamedef{#2nonsubscript}{%
\relax
\ensuremath{{#3}}%
\markasused{#2}%
\spaceaftersym
}%
\losglobalnamedef{#2doc}{#1}%
\losglobalnamedef{#2tabdoc}{%
\ensuremath{#3}%
}%
\losglobalnamedef{#2isused}{no}%
}%
\ifthenelse{\boolean{b@nomencl}}%
{%
\newcommand{\newsub}[3][]{%
\@bsphack
\@createsub{#1}{#2}{#3}%
\ifthenelse{\equal{#1}{}}{}{\nomenclature{\ensuremath{#3}}{#1}}%
\@esphack
}%
}%
{%
\newcommand{\newsub}[3][]{%
\@bsphack
\@createsub{#1}{#2}{#3}%
\addsymline{#3}{#3}{#2}{#1}{sub}%
\@esphack
}%
}%
\newcommand{\subsep}[1][]{\ensuremath{{}_{#1}{}}}
\newcommand{\symheadingname}{List of Symbols}
\newcommand{\subheadingname}{List of Subscripts}
\newcommand{\bothheadingname}{Notation}
\ifthenelse{\boolean{b@final}}%
{%
\newcommand{\symheading}{\section*{\symheadingname}}%
\newcommand{\subheading}{\section*{\subheadingname}}%
}%
{%
\newcommand{\symheading}{%
\section*{\symheadingname\ (draft)} %
\makebox[\symwidth+\symindent][l]{\textbf{Symbol}}{\textbf{Description}}%
\ifthenelse{\boolean{b@pageno}}{\hfill{\textbf{Defined on page}}}{}%
}%
\newcommand{\subheading}{%
\section*{\subheadingname\ (draft)} %
\makebox[\symwidth+\symindent][l]{\textbf{Subscript}}{\textbf{Description}}%
\ifthenelse{\boolean{b@pageno}}{\hfill{\textbf{Defined on page}}}{}%
}%
}%
\ifthenelse{\boolean{b@nomencl}}%
{%
\@ifpackagelater{nomencl}{2005/09/22}{%
\if@compatibilitymode\expandafter\@secondoftwo\else\expandafter\@firstoftwo\fi
}{\@secondoftwo}{%
\makenomenclature
\newcommand{\listofsymbols}{\printnomenclature}%
}{%
\makeglossary
\newcommand{\listofsymbols}{\printglossary}%
}%
\renewcommand{\nomname}{\symheadingname}%
\setlength{\nomitemsep}{-1\parsep}%
\newcommand{\listofsubscripts}{}%
}%
{%
\newlength{\old@parskip}%
\newlength{\old@parindent}%
\newcommand{\listofsymbols}{%
\setlength{\old@parskip}{\parskip}%
\setlength{\parskip}{0pt}%
\setlength{\old@parindent}{\parindent}%
\setlength{\parindent}{0pt}%
\symheading
\par
\@starttoc{syc}%
\@starttoc{sym}%
\setlength{\parskip}{\old@parskip}%
\setlength{\parindent}{\old@parindent}%
}%
\newcommand{\listofsubscripts}{%
\setlength{\old@parskip}{\parskip}%
\setlength{\parskip}{0pt}%
\setlength{\old@parindent}{\parindent}%
\setlength{\parindent}{0pt}%
\subheading
\par
\@starttoc{suc}%
\@starttoc{sub}%
\setlength{\parskip}{\old@parskip}%
\setlength{\parindent}{\old@parindent}%
}%
}%
\ifthenelse{\boolean{b@nomencl}}%
{\newcommand{\listofboth}{\listofsymbols}}%
{%
\newcommand{\listofboth}{%
\renewcommand{\symheading}{\subsection*{\symheadingname}}%
\renewcommand{\subheading}{\subsection*{\subheadingname}}%
\section*{\bothheadingname\ifthenelse{\boolean{b@final}}{}{ (draft)}}%
\listofsymbols
\listofsubscripts
}%
}%
\DeclareRobustCommand{\markasunused}[1]{%
\los@csname\gdef{#1isused}{no}%
}%
\DeclareRobustCommand{\markasused}[1]{%
\los@csname\gdef{#1isused}{yes}%
}%
\newcommand{\los@temp}{}%
% Do something about \dontmarkasused's fouling of xspace:
\DeclareRobustCommand{\dontmarkasused}[1]{%
\protected@xdef\los@temp{\los@csname{#1isused}}%
\los@csname{#1}{}%
\los@csname\protected@xdef{#1isused}{\los@temp}%
\spaceaftersym
}%
% .sym and. sub get destroyed during the LaTeX-run due to \@starttoc.
% At the begin of the LaTeX-run they are not yet destroyed. Thus let's
% do things at the begin of the document.
% At the begin of the document the ..isused..-commands are not available yet.
% Thus don't have them expanded at the time of writing to the .aux-file
% but have them expanded at the time of carrying out the .aux-file's
% \@writefile-entries at the end of the LaTeX-run.
% As \@writefile prevents expansion completely, an own \@writefile-variant
% is needed, \los@writefile, which performs the needed expansions before
% passing things to \@writefile:
\newcommand\los@writefile[3]{%
\expandafter\los@exchange\expandafter{%
\expandafter{%
\romannumeral
\expandafter\los@exchange\expandafter{%
\expandafter{#3}%
}{%
\expandafter\los@exchange\expandafter{%
\expandafter{\string#2}%
}{\@firstofone{0\expandafter} \string\losglobaldef}%
}%
}%
}{\@writefile{#1}}%
}%
\newcommand\los@addtocontents[3]{%
\protected@write\@auxout{%
\let\label\@gobble\let\index\@gobble\let\glossary\@gobble
}{%
\string\los@writefile{#1}{#2}{#3}%
}%
}%
\ifthenelse{\boolean{b@nomencl}}{}{%
\AtBeginDocument{%
\begingroup
\renewcommand{\printsymline}[5]{%
\los@addtocontents{syc}{%
\los@csname\string{#3include}%
}{%
\los@csname\string{#3isused}%
}%
}%
\@input{\jobname.sym}%
\renewcommand{\printsymline}[5]{%
\los@addtocontents{suc}{%
\los@csname\string{#3include}%
}{%
\los@csname\string{#3isused}%
}%
}%
\@input{\jobname.sub}%
\endgroup
}%
}%
\endinput
%%
%% End of file `listofsymbols_CHANGED_BY_UD_IN_2020_03_18.sty'.
文件test.tex
:
\documentclass{scrreprt}
\usepackage{listofsymbols_CHANGED_BY_UD_IN_2020_03_18}
%\usepackage{listofsymbols}
\usepackage{amsmath}
\opensymdef
\newsym[Description of the symbol \dontmarkasused{test}.]{test}{\vec{a}_b}
\newsym[Description of the symbol \dontmarkasused{moretest}.]{moretest}{\mathbf{\Theta}_\mathrm{asd}}
\newsym[Description of the symbol \dontmarkasused{yetmoretest}.]{yetmoretest}{\mathbf{\iota}}
\newsub[Description of the subscript \dontmarkasused{subznonsubscript} as in \dontmarkasused{yetmoretest}{}\dontmarkasused{subz}]{subz}{\mathrm{z}}
\closesymdef
\begin{document}
\listofsymbols
\listofsubscripts
\noindent\hrulefill\null
\noindent The symbol \test is used here.
\noindent The symbol \test{}\subz is used here.
\noindent The symbol \moretest is used here.
\noindent The symbol \moretest{}\subz is used here.
\noindent The symbol \yetmoretest is used here.
\noindent The symbol \yetmoretest{}\subz is used here.
\end{document}
摘录自test.log
:
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=pdflatex 2020.2.13)
LaTeX2e <2018-12-01>
Document Class: scrreprt 2019/02/01 v3.26b KOMA-Script document class (report)
Package: scrkbase 2019/02/01 v3.26b KOMA-Script package (KOMA-Script-dependent basics and keyval usage)
Package: scrbase 2019/02/01 v3.26b KOMA-Script package (KOMA-Script-independent basics and keyval usage)
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
Package: scrlfile 2019/02/01 v3.26b KOMA-Script package (loading files)
Package: tocbasic 2019/02/01 v3.26b KOMA-Script package (handling toc-files)
Package: typearea 2019/02/01 v3.26b KOMA-Script package (type area)
Package: listofsymbols_CHANGED_BY_UD_IN_2020_03_18
Package: ifthen 2014/09/29 v1.1c Standard LaTeX ifthen package (DPC)
Package: calc 2017/05/25 v4.3 Infix arithmetic (KKT,FJ)
Package: amsmath 2018/12/01 v2.17b AMS math features
Package: amstext 2000/06/29 v2.01 AMS text
File: amsgen.sty 1999/11/30 v2.0 generic functions
Package: amsbsy 1999/11/29 v1.2d Bold Symbols
Package: amsopn 2016/03/08 v2.02 operator names
结果截图如下test.pdf
:
答案2
有两个问题。
一个问题很容易解决。该包使用了已被弃用超过四分之一世纪的listofsymbols
命令。该类未定义(或者更确切地说,将其定义为发出错误)。\bf
scrreprt
\bf
第二个问题更严重。同一个包使用了\immediate\write
,因此诸如 之类的命令\mathbf
无法继续存在。不过,这个问题有两行解决方案。
\documentclass{scrreprt}
\usepackage{listofsymbols}
\usepackage{amsmath}
% avoid the error introduced by listofsymbols
\AtBeginDocument{%
\providecommand{\bf}{}%
\renewcommand{\bf}{\normalfont\bfseries}%
}
% Work around the issue with \immediate\write by not expanding the argument untimely
\newcommand{\NewSym}[3][]{%
\newsym[#1]{#2}{\unexpanded{\unexpanded{#3}}}%
}
\opensymdef
\NewSym[A]{test}{\vec{a}_b}
\NewSym[B]{moretest}{\mathbf{\Theta}_{\mathrm{asd}}}
\closesymdef
\begin{document}
\listofsymbols
\test
\moretest
\end{document}