2

This is a followup question about the code provided by Nicola Talbot in this question: Automated generation of equation key

TL;DR: Defines new environment alignglos which can be used to wrap the align environment. If you happen to have your equation symbols defined as a glossaryentry, you can use (or better reference) them in said equation to generate a mini glossary with the referenced symbols in a key.

So far so good. The code (MWE) from N. Talbot compiles fine if you copy&paste it. I tried incorporating the solution in my paper where many more packages are included. Somehow the functionality is broken. I don't know if this is due to the packages or due to the code used to generate the key. Some problems I found using the code are:

  1. Using the toc option in the glossaries package creates an unwanted entry (setting title={} only eliminates the text)

  2. I use hyperref to generate the linked page numbers in the glossary and therefore load the package before glossaries. Even if all alignglos environments are commented out, there is one reference warning: name{alignsglos.0} has been referenced but does not exist. One or more alignglos environments in the documents cause more warnings.

  3. The number list of all glossaries gets messed up. Only page 0 entries can be found (with no alignglos environment used) and 1 and 2 if used.

  4. Uncommenting the first two alignglos environments on line 225, 230, 234 and 238 produces the desired result (apart from the things listed above). Uncommenting further alignglos environments on line 250, 255, 260, 265 causes compiler errors which is annoyingly fascinating to me.

  5. This only occurs if you first compile the document without the alignglos environments: Instead of only the referenced elements inside alignglos, all entries from the symbol glossary ever referenced are printed out.

MWE hosted on github as gist: MWE with errors (Notes: Files encoding-ansi, begin{document}-line 218, package filecontents-used)


Optional: Just FYI, here is the link to the big document I was talking about where alignglos is not working too. Its a github repo. Clone with:

git clone git@github.com:tairun/hslu.bda2013.git ~

Use BDA_Doku_main.tex as project file and compile with pdflatex and makeglossaries+biblatex (with biber). All files should be encoded in ansi. The directory ./sty/ handles all the packages and userdefined stuff like the alignglos environment. Rest is just content. The eqaution shown in the MWE can be found in ./tex/loesungsfindung.tex > line 12. Output is about 50 pages (A4). Same equation is now located around page 37.

Sensei
  • 515

1 Answers1

4

The problem is that the symbol glossary needs the page location list for the main listing, which conflicts with the alignglos location list used by the alignglos environment. I think the simplest solution is to create two symbol glossaries, one for storing the page lists and the other for storing the alignglos lists. The following MWE does that:

% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{array}
\usepackage{amsmath}
\usepackage{etoolbox}
\usepackage{color}
\usepackage[left=3.0cm,right=3.0cm,top=2.5cm,bottom=2cm,includeheadfoot]{geometry}
\usepackage[hidelinks,colorlinks=false,linkcolor=black,bookmarksnumbered=true]{hyperref}
\usepackage[acronym,toc,nogroupskip]{glossaries}
\newglossary[slg]{symbols}{slm}{sbl}{Symbolverzeichnis}
\newglossary[slg2]{symbols2}{slm2}{sbl2}{Symbolverzeichnis2}[alignglos]

\newacronym{sia}{SIA}{Schweizerischer Ingenieur- und
Architektenverein}
\newacronym{www}{WWW}{World Wide Web}
\newacronym{bhkw}{BHKW}{Blockheizkraftwerk}
\newacronym{wkk}{WKK}{Wärmekraftkopplung}

\newglossaryentry{erntefaktor}{
name=Erntefaktor,
description={Der Erntefaktor beschreibt das Verhältnis der genutzten
Energie zur investierten Energie. Im Falle von Kraftwerken ist meist
Elektrizität (allgemein Exergie), während die im Anlagenlebenszyklus
aufgewandte Graue Energie beschreibt, die im Idealfall auch als
Exergie angegeben werden sollte. wird auch als kumulierter
Energieaufwand bezeichnet.}
}

\newglossaryentry{degradation}{
name=Degradation,
description={Alterungsbedingte Änderung der Parameter von
Halbleiterbauteilen. Im Falle von Photovoltaikzellen: Rückgang des
Wirkungsgrades im Laufe ihrer Einsatzdauer.}
}

\newcommand{\newsymbolentry}[2]{%
  \newglossaryentry{sym:#1}{type=symbols,#2}%
  \newglossaryentry{sym2:#1}{type=symbols2,#2}%
}

\newsymbolentry{etadegr}{
name={\ensuremath{\eta_{\mathrm{Deg},r}}},
description={Verbleibender Wirkungsgrad bezogen auf den
ursprünglichen Wirkungsgrad},
user1=\ensuremath{\%},
sort=eta deg rest
}

\newsymbolentry{tau}{
name={\ensuremath{\tau}},
description={Lebenszyklus / Einsatzdauer des betrachteten Systems},
user1=a,
sort=tau
}

\newsymbolentry{deg}{
name={\ensuremath{\dot{D}}},
description={Prozentuale jährliche Abnahme des Wirkungsgrades},
user1={\ensuremath{\%/a}},
sort=deg
}

%Columntypes I use (also in glossarystyles tabx3col and tabx4col)
\newcolumntype{Z}[1]{>{\raggedright \arraybackslash}m{#1}}
\newcolumntype{Q}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{Y}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{L}{>{\small \raggedright \arraybackslash}X}
\newcolumntype{C}{>{\small \centering \arraybackslash}X}
\newcolumntype{R}{>{\small \raggedleft \arraybackslash}X}

\def\ignoresetentrycounter[#1]#2{}%

\newglossarystyle{alignglos}%
{%
\renewcommand{\glsgroupskip}{}%
\renewcommand{\glossaryheader}{}%
\renewcommand{\glsgroupheading}[1]{}%
\renewenvironment{theglossary}%
{\begin{tabular}{@{}p{1cm}p{0.9\textwidth}}}%
{\end{tabular}}%
\renewcommand*{\glsnumberformat}[1]{##1}%
\renewcommand*{\delimR}{-}%
\renewcommand*{\delimN}{,}%
\renewcommand*{\glossaryentryfield}[5]{%
\let\glossaryentrynumbers\stripentrynumbers
\let\setentrycounter\ignoresetentrycounter
\edef\doifinloclist{\noexpand\ifinloclist{\thealignglos}{##5}}%
\doifinloclist
{%
\items{##1}{##3}%
}%
}%
\renewcommand*{\glossarysubentryfield}[1]{\glossaryentryfield}%
}

\newglossarystyle{tabx3col}{%
% put the glossary in a longtable environment:
\renewenvironment{theglossary}%
{\begin{longtable}{@{}p{0.2\textwidth}@{}p{0.6\textwidth}@{}Y{0.2\textwidth}@{}}}%
{\end{longtable}}%
% Set the table's header:
\renewcommand*{\glossaryheader}{}%
% No heading between groups:
\renewcommand*{\glsgroupheading}[1]{}%
% Main (level 0) entries displayed in a row:
\renewcommand*{\glossaryentryfield}[5]{%
\glstarget{##1}{##2}% Name
& ##3% Description
& ##5% Page list
\\% end of row
}%
%%Sub entries treated the same as level 0 entries:
%\renewcommand*{\glossarysubentryfield}[6]{%
%\glossaryentryfield{##2}{##3}{##5}{##6}}%
%% Nothing between groups:
%\renewcommand*{\glsgroupskip}{}%
}

\newglossarystyle{tabx4col}{%
% put the glossary in a longtable environment:
\renewenvironment{theglossary}%
{\begin{longtable}{@{}p{0.1\textwidth}@{}Z{0.1\textwidth}@{}p{0.6\textwidth}@{}Y{0.2\textwidth}@{}}}%
{\end{longtable}}%
% Set the table's header:
\renewcommand*{\glossaryheader}{}%
% No heading between groups:
\renewcommand*{\glsgroupheading}[1]{}%
% Main (level 0) entries displayed in a row:
\renewcommand*{\glossaryentryfield}[5]{%
\glstarget{##1}{##2}% Name
& \glsentryuseri{##1}% Units
& ##3% Description
& ##5% Page list
\\% end of row
}%
% Sub entries treated the same as level 0 entries:
%\renewcommand*{\glossarysubentryfield}[6]{%
%\glossaryentryfield{##2}{##3}{##5}{##6}}%
%% Nothing between groups:
%\renewcommand*{\glsgroupskip}{}%
}

\makeglossaries

\newcommand{\items}[2]{\glstext*{#1} & #2 [\glsuseri*{#1}] \\}

% Commands I don't understand but are needed
% ---------------------------------

% clean up the format of the location list
\newcommand{\stripentrynumbers}[1]{%
\striprelax#1\endstriprelax
}

\newcommand{\ifinloclist}[3]{%
\renewcommand*{\do}[1]{%
\let\dolistbreak\relax
\doifinloc{#1}{#3}##1-\relax\endrange
\dolistbreak
}%
\docsvlist{#2}%
}

\def\doifinloc#1#2#3-#4\endrange{%
\ifx\relax#4\relax
% just a number
\ifnum#1=#3\relax
#2%
\let\dolistbreak\listbreak
\fi
\else
\doifinrange{#1}{#2}#3-#4%
\fi
}

\def\doifinrange#1#2#3-#4-\relax{%
\ifnum#1=#3\relax
#2%
\let\dolistbreak\listbreak
\else
\ifnum#1=#4\relax
#2%
\let\dolistbreak\listbreak
\else
\ifnum#1>#3\relax
\ifnum#1<#4\relax
#2%
\let\dolistbreak\listbreak
\fi
\fi
\fi
\fi
}

\def\striprelax\relax#1\endstriprelax{#1}


\newcounter{alignglos}

\newcommand{\sym}[2][]{\gls[#1]{sym:#2}}%

\newenvironment{alignglos}%
{\stepcounter{alignglos}%
 \renewcommand{\sym}[2][]{\glsadd[##1]{sym2:##2}\gls[##1]{sym:##2}}%
}%
{%
\glstocfalse
\renewcommand{\glossarysection}[2][]{}%
\printglossary[type=symbols2,style=alignglos]
}

%-----------------------------------------------------------------------------

\begin{document}

\tableofcontents
\vspace{2em}

Reference to equation \ref{eq:deg1} and eq. \ref{eq:deg2}

\begin{alignglos}
\begin{align}
\sym{deg} &= \frac{1-\sym{etadegr}}{\sym{tau}}
\label{eq:deg1}\\
\sym{deg} &= \frac{1-\sym{etadegr}}{\sym{tau}}
\label{eq:deg2}
\end{align}
\end{alignglos}

\vspace{2em}

\begin{alignglos}
\begin{align}
\sym{tau} &= \ldots
\end{align}
\end{alignglos}
\newpage

\gls{bhkw}, \gls{sia}

\textcolor[rgb]{1,1,1}{\lipsum[1-20]}

\gls{www}, \gls{wkk}
\gls{erntefaktor}, \gls{degradation}

Reference to equation \ref{eq:deg3} and eq. \ref{eq:deg4}

\begin{alignglos}
\begin{align}
\sym{deg} &= \frac{1-\sym{etadegr}}{\sym{tau}}
\label{eq:deg3}\\
\sym{deg} &= \frac{1-\sym{etadegr}}{\sym{tau}}
\label{eq:deg4}
\end{align}
\end{alignglos}

\newpage

More Test Text... More Test Text... More Test Text... More Test
Text... More Test Text...

\begin{alignglos}
\begin{align}
\sym{deg} &= \frac{1-\sym{etadegr}}{\sym{tau}}
\label{eq:deg5}\\
\sym{deg} &= \frac{1-\sym{etadegr}}{\sym{tau}}
\label{eq:deg6}
\end{align}
\end{alignglos}

\newpage
\printglossary[type=\acronymtype,style=tabx3col,title=Abbrev]
\printglossary[type=symbols,style=tabx4col,title=Symbols]
\printglossary[style=tabx3col,title=Glossary]

\end{document}

(I had to switch to utf8 for the input encoding, as ansi didn't work for me.)

Nicola Talbot
  • 41,153
  • Hey Nicola, thanks again so much for your effort and time. I appreciate it very much. Once again your MWE compiles just fine. I am struggling to get it to work in my other document. It is driving me crazy. I would even say I'm obsessed with it and its keeping me awake right now -.-'. Getting an error message that says missing \begin{document} for the *slm2 file. Internet says my xkeyval package might be outdated. Got the one from 2012/10/14 which seems to be the current one (acording to ctan.org). Gotta double check for copy and paste errors. Reporting back later. – Sensei May 18 '13 at 22:59
  • 1
    Ooooookay. I moved the commands in the exact same location as you have them in the MWE and now it works beautifully. I had the definition of the \items command with my other newcommand stuff... Really happy right now. – Sensei May 18 '13 at 23:31