# Listofsymbols errors when using cascaded formulas

I want to use the listofsymbols package for a nomenclature and the basics seem to work fine. I am able to define symbols and call them by their respective commands. Theere are two errors arising. First: For some reason I cannot use a roman subscript in the formula. Wihtout the \mathrm it works fine, a new symbol using \mathrm is working fine but not as a subscript in the symbol with the description B.

The second error comes up while calling the listofsymbols. Actually the errors multiply but also with the minimum examble (just using symbol A) there are 2 errors mentioning some undefined old font command \bf I am just using LaTex and cannot seem to understand the errors.

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


• Welcome to TeX.SE! The listofsymbols package is quite old (from 2003), so it is likely that some incompatibilities have been introduced in documentclasses, other packages, or LaTeX itself, in the past 16.5 years. Maybe the still maintained glossaries package can be useful for you? See tex.stackexchange.com/questions/348640/… for an example. Mar 16, 2020 at 11:02

I see several sources for problems:

A glimpse on the code of the listofsymbols-package (LaTeX package listofsymbols v0.2 by Stefan Spreng, e-mail: listofsymbols@gmx.de, August 2003, see https://ctan.org/tex-archive/macros/latex/contrib/listofsymbols) reveals several issues with the package code:

• Internally the package uses old commands like \bf for changing fonts. These commands are deprecated. If you wish to apply them/if you wish to use a package which applies them, you need to provide the option enabledeprecatedfontcommands to the scrreprt-class.

• At the end of listofsymbols.pdf you find a nice code-listing which displays the content of listofsymbols.sty. But the code of listofsymbols.sty is not commented at all. So you are left entirely on your own when trying to get to know what sorts of algorithms are attempted to be implemented and carried out by that package.

• The package/the .sty-file does not properly take into account LaTeX's reading-apparatus. E.g., it does not always take into account that the reading-apparatus is switched to state M (middle of line) after tokenizing an opening curly brace and that therefore a space after an opening curly brace yields a space-token which in turn may yield visible horizontal glue in horizontal mode in situations where space tokens are not discarded during the gathering of the begin of a non-delimited argument.

• The package provides an option pageno. 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 package defines and uses a command \addsymline for writing things into auxiliary files. That command in turn does \immediate\write without taking LaTeX's \protect-mechanism into account.

1. This leads to expanding things like \mathbf or \mathrm in inconvenient moments of time.

Expanding things at inconvenient times leads to weird error-messages.

Expanding things at inconvenient times also leads to getting weird things into auxiliary files. E.g., with the example provided by our fellow questioner I find the following things in the .sym-file:

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


I think this should be something like:

\printsymline{\mathbf{\Theta }_\mathrm  {asd}}{\mathbf{\Theta }_\mathrm  {asd}}{moretest}{B}{\thepage }


These weird things in turn yield weird error-messages / \errmessages at the time of inputting the .sym-file.

2. The \addsymline-command also does write the page-number (\thepage) to auxiliary files. This implies that the value of the page-counter is written in terms of \immediate\write. This does not take into account the asynchrony of the output-routine due to which the value of the page-counter at the time of carrying out \addsymline is not necessarily the value the page-counter has when material gets shipped out as part of a page of the output-file/.pdf-file/.dvi-file.

I think this is an issue in the design of the listofsymbols-package, not really an issue related to compatibility to other packages.

I suggest re-implementing things using something based on/derived from LaTeX 2ε's \addtocontents/\@starttoc-mechanism.

File 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: listofsymbols@gmx.de
%%    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:
%%
%% 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}}%
{%
}{%
\renewcommand{\losstring}{\string}%
\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}&#1%
}%
\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}%
\@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}&#1%
}%
\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}%
\@esphack
}%
}%

\newcommand{\subsep}[1][]{\ensuremath{{}_{#1}{}}}

\ifthenelse{\boolean{b@final}}%
{%
}%
{%
\makebox[\symwidth+\symindent][l]{\textbf{Symbol}}{\textbf{Description}}%
\ifthenelse{\boolean{b@pageno}}{\hfill{\textbf{Defined on page}}}{}%
}%
\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}%
}%
\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}%
\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}%
\par
\@starttoc{suc}%
\@starttoc{sub}%
\setlength{\parskip}{\old@parskip}%
\setlength{\parindent}{\old@parindent}%
}%
}%

\ifthenelse{\boolean{b@nomencl}}%
{\newcommand{\listofboth}{\listofsymbols}}%
{%
\newcommand{\listofboth}{%
\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}}%
}%
\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@csname\string{#3include}%
}{%
\los@csname\string{#3isused}%
}%
}%
\@input{\jobname.sym}%
\renewcommand{\printsymline}[5]{%
\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'.


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


Excerpt from 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: 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


A screenshot of the resulting test.pdf:

• Do you really believe that amsmath uses \bf? It's listofsymbols that does. Definitely not amsmath. Mar 17, 2020 at 23:12
• @egreg I rectified this statement of mine. Mar 18, 2020 at 3:18

There are two problems.

One is easy to solve. The listofsymbols package uses the command \bf that's been deprecated for more than a quarter of a century. The scrreprt class doesn't define \bf (or rather defines it to issue an error).

The second one is deeper. The same package uses \immediate\write, which commands such as \mathbf don't survive. However, there's a two-line solution to the issue.

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