Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am looking for a way to automatically create the legend for an equation (let's say embedded in the align environment).

What I'm currently using is a semi automated to fully manual way. Let me explain: The result should look like this:

img1.

What I am doing to accomplish this requires 3 steps to generate the output shown above:

1) Placing equation:

\begin{align}  
    \dot{D} = \frac{1-\eta_{Deg,r}}{\tau} \label{eq:deg}  
\end{align}

2) Defining the corresponding entries in the symbol glossary:

\newglossaryentry{sym:deg}{  
type=symbols,  
name={$\dot{D}$},  
description={Prozentuale jährliche Abnahme des Wirkungsgrades},  
user1={\%/a},  
sort=deg  
}  

\newglossaryentry{sym:etadegr}{
type=symbols,
name={$\eta_{Deg,r}$},
description={Verbleibender Wirkungsgrad bezogen auf den ursprünglichen Wirkungsgrad},
user1=\%,
sort=eta deg rest
}

\newglossaryentry{sym:tau}{
type=symbols,
name={$\tau$},
description={Lebenszyklus / Einsatzdauer des betrachteten Systems},
user1=a,
sort=tau
}

3) Custom command to fill table with glossaries reference:

%Command
\newcommand{\items}[1]{\glstext*{#1} & \glsdesc*{#1} [\glsuseri*{#1}] \\}

%Legend Environment
\begin{tabular}{@{} p{1cm} p{0.9 \textwidth}}
    \items{sym:deg}
    \items{sym:etadegr}
    \items{sym:tau}
\end{tabular}

Question

I'd like to create a command which searches the previous align environment for elements of my symbol glossary and puts them into a legend (in this case tabular) environment. Does this already exist (didn't find anything)? And how would i realize this? Not expecting a perfect solution but I have no clue how to do this.

An MWE to tinker with can be found here --> Gist

€:
-Additional Information: Using miktex 2.9 and TechniXCenter 2 on Windows.
-Matches for the search could be done with the name key of the glossary entry

share|improve this question
1  
This is similar to tex.stackexchange.com/questions/89107/… except you're using equation rather than section. (Is there a reason for using align rather than equation? If you're going to have multi-lined equations, that may make the solution harder.) –  Nicola Talbot May 14 '13 at 12:09
    
I fail to see how the other post could be of any help to me. There would be multiple equations per environment, hence the align. I don't think the glossaries package can provide a solution here (via glossariy styles). –  Sensei May 14 '13 at 12:20
1  
This is not what you want, but if you are ready for special mark-up of the source like people do when thy want to index things, say \x{\dot{D}} rather than \dot{D}, \x\tau rather than \tau, etc... then a not too complicated solution would be easily feasible. (not by me, as I don't know anything about glossary). –  jfbu May 14 '13 at 15:22

1 Answer 1

up vote 6 down vote accepted

Here's a possible solution. It requires xindy rather than makeindex. If you really don't want to use xindy, it's possible to adjust the code, but it's more complicated.

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

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[counter=alignglos,xindy]{glossaries}

\newglossary[slg]{symbols}{slm}{sbl}{List of Symbols}

\GlsSetXdyMinRangeLength{0}

\makeglossaries

\newglossaryentry{sym:deg}{  
type=symbols,  
name={\ensuremath{\dot{D}}},  
description={Prozentuale jährliche Abnahme des Wirkungsgrades},  
user1={\%/a},  
sort=deg  
}  

\newglossaryentry{sym:etadegr}{
type=symbols,
name={\ensuremath{\eta_{Deg,r}}},
description={Verbleibender Wirkungsgrad bezogen auf den
ursprünglichen Wirkungsgrad},
user1=\%,
sort=eta deg rest
}

\newglossaryentry{sym:tau}{
type=symbols,
name={\ensuremath{\tau}},
description={Lebenszyklus / Einsatzdauer des betrachteten Systems},
user1=a,
sort=tau
}

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

\newglossarystyle{alignglos}%
{%
  \renewcommand{\glsgroupskip}{}%
  \renewcommand{\glossaryheader}{}%
  \renewcommand{\glsgroupheading}[1]{}%
  \renewenvironment{theglossary}%
   {\begin{tabular}{@{}p{1cm}p{0.9\textwidth}}}%
   {\end{tabular}}%
  \renewcommand*{\glossaryentrynumbers}[1]{##1}%
  \renewcommand*{\glsXalignglosXglsnumberformat}[2]{##2}%
  \renewcommand*{\delimN}{,}%
  \renewcommand*{\glossaryentryfield}[5]{%
    \edef\doifinlocation{\noexpand\ifinlocation{\thealignglos}{\expandafter\striprelax##5\endstriprelax}}%
    \doifinlocation
    {%
      \items{##1}{##3}%
    }%
  }%
}

\newcommand{\ifinlocation}[3]{%
 \DTLifinlist{#1}{#2}{#3}{}%
}

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


\newcounter{alignglos}

\newenvironment{alignglos}%
 {\stepcounter{alignglos}}%
 {%
   \printglossary[type=symbols,style=alignglos,title={}]
 }

\begin{document}

\begin{alignglos}
\begin{align}  
    \gls{sym:deg} &= \frac{1-\gls{sym:etadegr}}{\gls{sym:tau}}
\end{align}
\end{alignglos}

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

\end{document}

Edit:

Here's the code for use with makeindex instead of xindy:

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

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{etoolbox}
\usepackage[counter=alignglos]{glossaries}

\newglossary[slg]{symbols}{slm}{sbl}{List of Symbols}

\makeglossaries

\newglossaryentry{sym:deg}{  
type=symbols,  
name={\ensuremath{\dot{D}}},  
description={Prozentuale jährliche Abnahme des Wirkungsgrades},  
user1={\%/a},  
sort=deg  
}  

\newglossaryentry{sym:etadegr}{
type=symbols,
name={\ensuremath{\eta_{Deg,r}}},
description={Verbleibender Wirkungsgrad bezogen auf den
ursprünglichen Wirkungsgrad},
user1=\%,
sort=eta deg rest
}

\newglossaryentry{sym:tau}{
type=symbols,
name={\ensuremath{\tau}},
description={Lebenszyklus / Einsatzdauer des betrachteten Systems},
user1=a,
sort=tau
}

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

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

\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
    \edef\doifinloclist{\noexpand\ifinloclist{\thealignglos}{##5}}%
    \doifinloclist
    {%
      \items{##1}{##3}%
    }%
  }%
  \renewcommand*{\glossarysubentryfield}[1]{\glossaryentryfield}%
}

\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\setentrycounter[]#1#2\endstriprelax{#2}


\newcounter{alignglos}

\newenvironment{alignglos}%
 {\stepcounter{alignglos}}%
 {%
   \printglossary[type=symbols,style=alignglos,title={}]
 }

\begin{document}

\begin{alignglos}
\begin{align}  
    \gls{sym:deg} &= \frac{1-\gls{sym:etadegr}}{\gls{sym:tau}}
\end{align}
\end{alignglos}

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

\end{document}

Result for either method:

Image of resulting document

This will also work if you want to use equation instead of align. The code is adapted from Glossary per chapter or section. You just need to wrap your equations inside the alignglos environment.

Notes:

  1. I've used \ensuremath instead of $ so it doesn't matter if you are in or out of math mode when you use the glossary entry
  2. I think Deg should probably be \operatorname{Deg} or \mathrm{Deg} (assuming it's not just D times e times g).

Edit 2:

I've modified the alignglos style so that it suppresses the group skip. I've also deferred \listbreak to the end of \do. If you have Perl installed, you can use the makeglossaries script to call makeindex or xindy, which will skip any empty glossaries. If you have Perl and Java installed, you can just run arara on the document and it will run all the commands listed in the % arara: directives. When you switch to linux, you should have Perl preinstalled and probably also the Java runtime environment.

share|improve this answer
    
Thank you very much for your solution. I fail to get xindy to work on windows. I followed these instructions to the dot (tex.stackexchange.com/questions/71167/…). I suspect its the .cnf file. I tried modifying all the paths, did not help. I'm not sure to what extent I need to modify the command line parameter for xindy in order to work with the glossaries package either. And also why is your solution xindy specific? What would need to be changed in order to run on pure makeindex? –  Sensei May 14 '13 at 19:49
1  
It's the ability to switch off the range formation (\GlsSetXdyMinRangeLength{0}) that makes it easier to do in xindy. To get it to work with makeindex, \ifinlocation would need to be modified so that it can check if a number lies within a given range (and detect if there is a range present). \glsXalignglosXglsnumberformat is also xindy-specific. I'll see if I can work out the modifications to make it work with makeindex. –  Nicola Talbot May 14 '13 at 20:04
    
I really don't mid using xindy at all (since I'm switching to linux only soon). I just don't know how to make it work. The glossaries documentation provides some help (chapter Use xindy explicitly). I tried to adapt the syntax for the command line to my TeXnicCenter setup, sadly with no succes. –  Sensei May 14 '13 at 22:18
    
I first struggled to get the makeindex version to work but turns out the problem was laying with TeXnicCenters post processing handler. I have defined 3 post processing jobs: glossary, acronyms and symbols. If the first two are empty you need to move the symbol job to the top or else the other ones won't get processed. I need to check if this holds true for xindy as well, but I need the other PC to check. Will report back later. One issue with this solution though: If you have nogroupskip set I get error Incomplete \iftrue, all text was ignored after line ... and Missing } inserted –  Sensei May 15 '13 at 7:17
1  
I think you'll have to modify the minimal example so that it reproduces those problems and post it as a new question. It sounds like you're using hyperref which complicates matters. The alignglos style will need to be modified to counteract the toc setting. –  Nicola Talbot May 15 '13 at 12:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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