2

I'm using TeX Live. I have a book style file and I want to have a symbol list before the table of contents. There is a good code in this site for the symbol list that written by Heiko Oberdiek in List of Symbols? (the example file). But this have a problem. This list doesn't appear in the first of file. How can I print the list in the first of the file?

  • 3
    Welcome to TeX.SX! Of course, it is always a good idea to use code, written by me. ;-) What do you mean with "first of file"? Can you make an example? – Heiko Oberdiek Aug 8 '15 at 6:27
  • Thank you Dear Oberdicek, I mean that, I define a new symbol in chapter 1 or chapter 2, etc., I want to create list before chapter 1, in the other words, first, I want to run \printsymblist and then I want to use \newmathsymb{}{}, such as table of content. – m h Akrami Aug 8 '15 at 7:31
  • If \printsymblist is used before any symbol has been added with \newmathsymbol then it's indeed an empty list. The labels are there, but nothing is printed, apart from the header – user31729 Aug 8 '15 at 8:04
  • The reason is, that \printsymblist wants to show \symb@list but this is empty at the beginning of the document. – user31729 Aug 8 '15 at 8:10
4

If the symbols are used before they are defined, then the definitions must go into the .aux file. In comparison to my answer for question "List of Symbols?", I have now split \new@symb in two parts. \new@symb writes the definition in the .aux file and sets the \label. It also defines the symbol, if it was not yet read from the .aux file.

\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
}

The macro \new@aux@symb in the .aux file defines the symbol and puts it to the symbol list:

\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
}

A default definition for \new@aux@symb is provided in the .aux file via package auxhook for the case, the .aux file is used without proper definition of \new@aux@symb:

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

Full example file:

\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}

Refinement: Adding warnings

The previous version does not warn, when a symbol has changed, for example. This is fixed by using LaTeX's internal label interface via macro \@newl@bel, which makes the global definition (now with prefix \SYMB@ instead of the former \symb:) and which is redefined at the end of the document by LaTeX to check the symbol definitions for changes, when the .aux file is reread.

Refined example:

\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}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.