符号列表的问题

符号列表的问题

我正在使用 TeX Live。我有一个书籍样式文件,我想在目录之前有一个符号列表。这个网站上有一个很好的符号列表代码,由 Heiko Oberdiek 于 符号列表?(示例文件)。但这有一个问题。此列表未出现在文件的第一个部分。我怎样才能打印文件第一个部分中的列表?

答案1

如果在定义符号之前使用这些符号,则必须将定义放入文件中.aux。与我对问题“符号列表?“,我现在把它分成\new@symb两部分。\new@symb将定义写入.aux文件中并设置\label。如果尚未从文件中读取符号,它还会定义符号.aux

\newcommand*{\new@symb}[3]{%
  \@bsphack
  \if@filesw
    \protected@write\@auxout{}{%
      \string\new@aux@symb{#1}{%
        \detokenize\expandafter{\unexpanded{#2}}%
      }{%
        \detokenize\expandafter{\unexpanded{#3}}%
      }%
    }%
  \fi
  \label{symb:#1}%
  \@ifundefined{symb:#1}{%
    \expandafter\gdef\csname symb:#1\endcsname{#2}%
  }{}%
  \@esphack
}

\new@aux@symb文件中的宏.aux定义该符号并将其放入符号列表中:

\newcommand*{\new@aux@symb}[3]{%
  \g@addto@macro{\symb@list}{\symb@do{#1}{#2}{#3}}%
  \expandafter\gdef\csname symb:#1\endcsname{#2}%
  \begingroup
    \settowidth{\dimen@}{#2}%
    \ifdim\dimen@>\symb@maxwidth
      \global\symb@maxwidth=\dimen@
    \fi
  \endgroup
}

针对没有正确定义的情况,在文件中通过包\new@aux@symb提供了 的默认定义:.auxauxhook.aux\new@aux@symb

\usepackage{auxhook}
\AddLineBeginAux{%
  \string\providecommand\string\new@aux@symb[3]{}%
}

完整示例文件:

\documentclass[a4paper,12pt]{article}
\usepackage[
  hmargin=25mm,
]{geometry}
\usepackage{supertabular}
\usepackage{array}
\usepackage{amsmath}
\usepackage[T1]{fontenc}
\usepackage{textcomp}

\makeatletter
\usepackage{auxhook}
\AddLineBeginAux{%
  \string\providecommand\string\new@aux@symb[3]{}%
}
\newcommand*{\symb@list}{}
\newlength{\symb@maxwidth}
\newlength{\symb@meaning}
\newcommand*{\new@aux@symb}[3]{%
  \g@addto@macro{\symb@list}{\symb@do{#1}{#2}{#3}}%
  \expandafter\gdef\csname symb:#1\endcsname{#2}%
  \begingroup
    \settowidth{\dimen@}{#2}%
    \ifdim\dimen@>\symb@maxwidth
      \global\symb@maxwidth=\dimen@
    \fi
  \endgroup
}
\newcommand*{\new@symb}[3]{%
  \@bsphack
  \if@filesw
    \protected@write\@auxout{}{%
      \string\new@aux@symb{#1}{%
        \detokenize\expandafter{\unexpanded{#2}}%
      }{%
        \detokenize\expandafter{\unexpanded{#3}}%
      }%
    }%
  \fi
  \label{symb:#1}%
  \@ifundefined{symb:#1}{%
    \expandafter\gdef\csname symb:#1\endcsname{#2}%
  }{}%
  \@esphack
}
\newcommand*{\newmathsymb}[3]{%
  \new@symb{#1}{\ensuremath{#2}}{#3}%
}
\newcommand*{\newtextsymb}{%
  \@dblarg\symb@newtext
}
\def\symb@newtext[#1]#2#3{%
  \new@symb{#1}{#2}{#3}%
}
\newcommand*{\symb}[1]{%
  \@ifundefined{symb:#1}{%
    \@latex@error{Symbol `#1' is undefined}\@ehc
  }{%
    \csname symb:#1\endcsname
  }%
}
% List of symbols
\newcommand*{\symb@head}[1]{\textbf{\large#1}}
\newcommand*{\printsymblist}{%
  \twocolumn[%
    \section*{%
      \centering
      List of Symbols, Abbreviations, and Notation%
    }%
  ]%  
  \thispagestyle{empty}% optional
  \renewcommand*{\arraystretch}{1.1}%
  \settowidth{\dimen@}{\symb@head{Symbol}}%
  \ifdim\dimen@>\symb@maxwidth
    \global\symb@maxwidth\dimen@
  \fi
  \setlength{\symb@meaning}{\linewidth}%
  \addtolength{\symb@meaning}{-\symb@maxwidth}%
  \settowidth{\dimen@}{\symb@head{Page}}%
  \addtolength{\symb@meaning}{-\dimen@}% 
  \addtolength{\symb@meaning}{-4\tabcolsep}%
  \tablehead{%
    \symb@head{Symbol} & \symb@head{Meaning} & \symb@head{Page}\\[.5ex]%
  }%
  \begin{supertabular}{@{}p{\symb@maxwidth}p{\symb@meaning}c@{}}%
    \symb@list
  \end{supertabular}%
  \clearpage
  \onecolumn
}
\newcommand*{\symb@do}[3]{%
  #2&%
  \sbox0{%
    \renewcommand*{\arraystretch}{1}%
    \begin{tabular}[t]{@{}p{\symb@meaning}@{}}%
      \raggedright
      #3%
    \end{tabular}%
  }%
  \sbox2{%
    \renewcommand*{\arraystretch}{1}%
    \begin{tabular}[b]{@{}b{\symb@meaning}@{}}%
      \raggedright
      #3%
    \end{tabular}%
  }%
  \usebox0 %
  \xdef\symb@raise{\the\dimexpr\ht0-\ht2}%
  &\raisebox{\symb@raise}{\pageref{symb:#1}}\tabularnewline
}
\makeatother

\begin{document}
\printsymblist

\setcounter{page}{40}
\newmathsymb{ABline}{\overleftrightarrow{AB}}{line $AB$}
Text with \symb{ABline} in text mode.
\begin{equation}
  \symb{ABline} = \symb{ABline}
\end{equation}
\newpage
\newmathsymb{ABsegment}{\overline{AB}}{line segment $AB$}
Text with \symb{ABsegment}.
\newmathsymb{AB}{AB}{the length of \symb{ABsegment}}
\newmathsymb{ABray}{\overrightarrow{AB}}{ray $AB$}  
\newpage
\newmathsymb{angleABC}{\angle ABC}{angle $ABC$}
Text with \symb{angleABC}.

\newcommand*{\test}[1]{%
  \newpage
  \setcounter{page}{#1}%
  Dummy text.%
}
\test{42}\newtextsymb{degree}{\textdegree}{degree}
\test{88}\newmathsymb{approx}{\approx}{approximately equal to}
\test{108}\newmathsymb{pi}{\pi}{pi}
\test{186}\newmathsymb{if p then q}{p \Rightarrow q}{if $p$, then $q$}
\test{189}\newmathsymb{p iff q}{p \Leftrightarrow q}{$p$ if and only if $q$}
\test{198}\newtextsymb{HL}{Hypotenuse-Leg Congruence Theorem}
\test{198}\newtextsymb[CP]{C.P.}{\textbf{C}orresponding \textbf{P}arts
  of Congruent Triangles Are Congruent}
\test{199}\newtextsymb{ASA}{Angle-Side-Angle Congruence Postulate}
\test{298}\newmathsymb{a:b}{a\colon b}{ratio $\frac{a}{b}$}
\test{309}\newtextsymb{AAA}{Angle-Angle-Angle Similarity Postulate}
\test{309}\newtextsymb{AA}{Angle-Angle Similarity Theorem}
\test{310}\newtextsymb{SAS}{Side-Angle-Side Similarity Theorem}{310}
\test{311}\newtextsymb{LL}{Leg-Leg Similarity Theorem}
\test{541}\newmathsymb{>}{>}{is greater than}
\test{541}\newmathsymb{<}{<}{is less than}   
\test{541}\newmathsymb{<=}{\neq}{is less than or equal to}
\test{541}\newmathsymb{>=}{\geq}{is greater than or equal to}
\test{562}\newmathsymb{dT}{d_T}{taxicab distance}{562}
\test{562}\newmathsymb{dE}{d_E}{Euclidian distance}{562}

\end{document}

改进:添加警告

例如,当符号发生变化时,以前的版本不会发出警告。这个问题通过使用 LaTeX 的内部标签接口(通过宏 )得到解决\@newl@bel,该宏会进行全局定义(现在使用前缀\SYMB@而不是以前的\symb:),并且 LaTeX 会在文档末尾重新定义 ,以便在.aux重新读取文件时检查符号定义是否发生变化。

精炼示例:

\documentclass[a4paper,12pt]{article}
\usepackage[
  hmargin=25mm,
]{geometry}
\usepackage{supertabular}
\usepackage{array}
\usepackage{amsmath}
\usepackage[T1]{fontenc}
\usepackage{textcomp}

\makeatletter
\usepackage{auxhook}
\AddLineBeginAux{%
  \string\providecommand\string\new@aux@symb[3]{}%
}
\newcommand*{\symb@list}{}
\newlength{\symb@maxwidth}
\newlength{\symb@meaning}
\newcommand*{\new@aux@symb}[3]{%
  \g@addto@macro{\symb@list}{\symb@do{#1}{#2}{#3}}%
  \@newl@bel{SYMB}{#1}{#2}%
  \begingroup
    \settowidth{\dimen@}{#2}%
    \ifdim\dimen@>\symb@maxwidth
      \global\symb@maxwidth=\dimen@
    \fi
  \endgroup
}
\newcommand*{\new@symb}[3]{%
  \@bsphack
  \if@filesw
    \protected@write\@auxout{}{%
      \string\new@aux@symb{#1}{%
        \detokenize\expandafter{\unexpanded{#2}}%
      }{%
        \detokenize\expandafter{\unexpanded{#3}}%
      }%
    }%
  \fi
  \label{symb:#1}%
%  \@ifundefined{SYMB@#1}{%
%    \expandafter\gdef\csname SYMB@#1\endcsname{#2}%
%  }{}%
  \@esphack
}
\newcommand*{\newmathsymb}[3]{%
  \new@symb{#1}{\ensuremath{#2}}{#3}%
}
\newcommand*{\newtextsymb}{%
  \@dblarg\symb@newtext
}
\def\symb@newtext[#1]#2#3{%
  \new@symb{#1}{#2}{#3}%
}
\newcommand*{\symb}[1]{%
  \@ifundefined{SYMB@#1}{%
    \@latex@warning{Symbol `#1' is undefined}%
    \nfss@text{\textbf{??}}%
  }{%
    \csname SYMB@#1\endcsname
  }%
}
% List of symbols
\newcommand*{\symb@head}[1]{\textbf{\large#1}}
\newcommand*{\printsymblist}{%
  \twocolumn[%
    \section*{%
      \centering
      List of Symbols, Abbreviations, and Notation%
    }%
  ]%  
  \thispagestyle{empty}% optional
  \renewcommand*{\arraystretch}{1.1}%
  \settowidth{\dimen@}{\symb@head{Symbol}}%
  \ifdim\dimen@>\symb@maxwidth
    \global\symb@maxwidth\dimen@
  \fi
  \setlength{\symb@meaning}{\linewidth}%
  \addtolength{\symb@meaning}{-\symb@maxwidth}%
  \settowidth{\dimen@}{\symb@head{Page}}%
  \addtolength{\symb@meaning}{-\dimen@}% 
  \addtolength{\symb@meaning}{-4\tabcolsep}%
  \tablehead{%
    \symb@head{Symbol} & \symb@head{Meaning} & \symb@head{Page}\\[.5ex]%
  }%
  \begin{supertabular}{@{}p{\symb@maxwidth}p{\symb@meaning}c@{}}%
    \symb@list
  \end{supertabular}%
  \clearpage
  \onecolumn
}
\newcommand*{\symb@do}[3]{%
  #2&%
  \sbox0{%
    \renewcommand*{\arraystretch}{1}%
    \begin{tabular}[t]{@{}p{\symb@meaning}@{}}%
      \raggedright
      #3%
    \end{tabular}%
  }%
  \sbox2{%
    \renewcommand*{\arraystretch}{1}%
    \begin{tabular}[b]{@{}b{\symb@meaning}@{}}%
      \raggedright
      #3%
    \end{tabular}%
  }%
  \usebox0 %
  \xdef\symb@raise{\the\dimexpr\ht0-\ht2}%
  &\raisebox{\symb@raise}{\pageref{symb:#1}}\tabularnewline
}
\makeatother


\begin{document}
\printsymblist

\setcounter{page}{40}
\newmathsymb{ABline}{\overleftrightarrow{AB}}{line $AB$}
Text with \symb{ABline} in text mode.
\begin{equation}
  \symb{ABline} = \symb{ABline}
\end{equation}
\newpage
\newmathsymb{ABsegment}{\overline{AB}}{line segment $AB$}
Text with \symb{ABsegment}.
\newmathsymb{AB}{AB}{the length of \symb{ABsegment}}
\newmathsymb{ABray}{\overrightarrow{AB}}{ray $AB$}  
\newpage
\newmathsymb{angleABC}{\angle ABC}{angle $ABC$}
Text with \symb{angleABC}.

\newcommand*{\test}[1]{%
  \newpage
  \setcounter{page}{#1}%
  Dummy text.%
}
\test{42}\newtextsymb{degree}{\textdegree}{degree}
\test{88}\newmathsymb{approx}{\approx}{approximately equal to}
\test{108}\newmathsymb{pi}{\pi}{pi}
\test{186}\newmathsymb{if p then q}{p \Rightarrow q}{if $p$, then $q$}
\test{189}\newmathsymb{p iff q}{p \Leftrightarrow q}{$p$ if and only if $q$}
\test{198}\newtextsymb{HL}{Hypotenuse-Leg Congruence Theorem}
\test{198}\newtextsymb[CP]{C.P.}{\textbf{C}orresponding \textbf{P}arts
  of Congruent Triangles Are Congruent}
\test{199}\newtextsymb{ASA}{Angle-Side-Angle Congruence Postulate}
\test{298}\newmathsymb{a:b}{a\colon b}{ratio $\frac{a}{b}$}
\test{309}\newtextsymb{AAA}{Angle-Angle-Angle Similarity Postulate}
\test{309}\newtextsymb{AA}{Angle-Angle Similarity Theorem}
\test{310}\newtextsymb{SAS}{Side-Angle-Side Similarity Theorem}{310}
\test{311}\newtextsymb{LL}{Leg-Leg Similarity Theorem}
\test{541}\newmathsymb{>}{>}{is greater than}
\test{541}\newmathsymb{<}{<}{is less than}   
\test{541}\newmathsymb{<=}{\neq}{is less than or equal to}
\test{541}\newmathsymb{>=}{\geq}{is greater than or equal to}
\test{562}\newmathsymb{dT}{d_T}{taxicab distance}{562}
\test{562}\newmathsymb{dE}{d_E}{Euclidian distance}{562}

\end{document}

相关内容