3

I'm starting to use the glossaries package. I found a new style I like but I want to make a minor change on it as seen in figure below. I found another style where they used 'symbol' for using the 'units' using \glossentrysymbol{##2} and another using the same method using \glossentrysymbol{##1}.

I have been trying to add it to the style but I always get some serious errors or nothing changes. Is there anyone who can help me on this?

enter image description here

Minimal working sample

\documentclass[onecolumn]{IEEEtran}
\usepackage[acronym,toc,nopostdot]{glossaries}


% % % % % % % % % % % % % % 
\newglossarystyle{dotglos}{%
    \glossarystyle{list}%
    \renewcommand*{\glossaryentryfield}[5]{%
        \item[\glsentryitem{##1}\glstarget{##1}{##2}] \emph{##3}%
        \unskip\leaders\hbox to 2.9mm{\hss.}\hfill##5}%
    \renewcommand*{\glsgroupskip}{}%
}

%% \glossentrysymbol{##1}  % <- Need this to fit in between the symbol and description for unit purpose.
% % % % % % % % % % % % % % 

\glossarystyle{dotglos}


% Some symbols
\newglossaryentry{a}{
    name = $abc$ ,
    description = Yes,
    symbol = $m^2$
}
\newglossaryentry{d}{
    name = $def$ ,
    description = No,
    symbol = $m^2$
}
\newglossaryentry{g}{
    name = $ghi$ ,
    description = Maybe,
    symbol = $m^2$
}

\makeglossaries

\begin{document}
\printglossaries
\newpage
\gls{a}, \gls{d} and \gls{g} are part of the glossary. But I want the 
\end{document}
2

\glossarystyle and \glossaryentryfield are now deprecated. The newer commands are \setglossarystyle{style} and \glossentry{label}{location list}.

The double-hash usage (##1) is required to reference command arguments when redefining commands within \newglossarystyle, so when redefining \glossentry, the label (first argument) is referenced with ##1 (not #1), so you can use \glossentrysymbol{##1} to display the symbol. I suspect that in the cases where you have seen \glossentrysymbol{##2}, this has been for sub-entries within the definition of \subglossentry{level}{label}{location list}, where the label is now the second argument.

I'm not sure of the spacing that you need between the unit and description, so I've just used \quad here. You can change it as necessary.

\newglossarystyle{dotglos}{%
    \setglossarystyle{list}%
    \renewcommand*{\glossentry}[2]{%
        \item[\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}}]
        [\glossentrysymbol{##1}]\quad
        \emph{\glossentrydesc{##1}}%
        \unskip\leaders\hbox to 2.9mm{\hss.}\hfill##2}%
    \renewcommand*{\glsgroupskip}{}%
}

If you want a special case for entries that don't have a symbol, you can use \ifglshassymbol to test for it:

\newglossarystyle{dotglos}{%
    \setglossarystyle{list}%
    \renewcommand*{\glossentry}[2]{%
        \item[\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}}]
        \ifglshassymbol{##1}{[\glossentrysymbol{##1}]\quad}{}%
        \emph{\glossentrydesc{##1}}%
        \unskip\leaders\hbox to 2.9mm{\hss.}\hfill##2}%
    \renewcommand*{\glsgroupskip}{}%
}

Complete MWE:

\documentclass[onecolumn]{IEEEtran}
\usepackage[acronym,toc,nopostdot]{glossaries}

\newglossarystyle{dotglos}{%
    \setglossarystyle{list}%
    \renewcommand*{\glossentry}[2]{%
        \item[\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}}]
        \ifglshassymbol{##1}{[\glossentrysymbol{##1}]\quad}{}%
        \emph{\glossentrydesc{##1}}%
        \unskip\leaders\hbox to 2.9mm{\hss.}\hfill##2}%
    \renewcommand*{\glsgroupskip}{}%
}

\setglossarystyle{dotglos}


% Some symbols
\newglossaryentry{a}{
    name = $abc$ ,
    description = Yes,
    symbol = $m^2$
}
\newglossaryentry{d}{
    name = $def$ ,
    description = No,
    symbol = $m^2$
}
\newglossaryentry{g}{
    name = $ghi$ ,
    description = Maybe,
    symbol = $m^2$
}

\makeglossaries

\begin{document}
\printglossaries
\newpage
\gls{a}, \gls{d} and \gls{g} are part of the glossary. But I want the 
\end{document}

image of glossary

Edit: Regarding your comment about aligning the unit and description, you could base the style on one of the tabular-like styles, but this requires calculating the available space left for the dotted leader. Another possibility is to calculate the widest name and widest unit. Then the name and unit can each be put inside a \makebox of the required width.

The glossaries-extra package comes with the supplementary package glossaries-extra-stylemods, which provides some extra commands that can be used for this purpose. These are quite new, so you'll need a fairly up-to-date version of the package.

The command \glsFindWidestUsedAnyNameSymbol[glossary list]{length register} can be used to calculate the widest name and symbol field of all entries that have been marked as used (for all entries in the glossary types listed in the first argument, which defaults to all glossaries). The width of the widest value of the symbol field is stored in the supplied length register. The widest name field is marked using \glssetwidest (provided by glossaries). The value can be accessed using \glsgetwidestname.

For example:

\newlength\widestsymbol
\newlength\widestname
\glsFindWidestUsedAnyNameSymbol{\widestsymbol}
\settowidth{\widestname}{\glsgetwidestname}

The style can then use \makebox[\widestname][l]{\glossentryname{##1}} and \makebox[\widestsymbol][l]{\glossentrysymbol{##1}} which will have the effect of left-aligning the name, symbol (unit) and description.

The drawback is that you can only use \glsFindWidestUsedAnyNameSymbol at the end of the document, since none of the entries have been marked as used at the start. This isn't a problem for glossaries that occur at the end of the document, but if the glossary is at the start (as in your MWE), then the values need to be stored and made available for the next run. The usual method of doing this is to write the required information in the .aux file.

Updated MWE:

\documentclass[onecolumn]{IEEEtran}

\usepackage[acronym]{glossaries-extra}
\usepackage{glossaries-extra-stylemods}

\newlength\widestsymbol
\newlength\widestname

\newcommand*{\namebox}[1]{%
 \ifdim\widestname>0pt\makebox[\widestname][l]{#1}\else#1\fi}

\newcommand*{\symbolbox}[1]{%
 \ifdim\widestsymbol>0pt\makebox[\widestsymbol][l]{#1}\else#1\fi}

\makeatletter
\AtEndDocument
{%
  \glsFindWidestUsedAnyNameSymbol{\widestsymbol}%
  \settowidth{\widestname}{\glsgetwidestname}%
  \immediate\protected@write\@auxout{}
   {%
    \string\global\string\setlength{\string\widestsymbol}{\the\widestsymbol}%
    \string\global\string\setlength{\string\widestname}{\the\widestname}%
   }%
}
\makeatother

\newglossarystyle{dotglos}{%
    \setglossarystyle{list}%
    \renewcommand*{\glossentry}[2]{%
        \item[\glsentryitem{##1}\glstarget{##1}{\namebox{\glossentryname{##1}}}]
        [\symbolbox{\glossentrysymbol{##1}}]\quad
        \emph{\glossentrydesc{##1}}%
        \unskip\leaders\hbox to 2.9mm{\hss.}\hfill##2}%
    \renewcommand*{\glsgroupskip}{}%
}

\setglossarystyle{dotglos}


% Some symbols
\newglossaryentry{a}{
    name = $a$,
    description = Yes,
    symbol = $m^2$
}
\newglossaryentry{d}{
    name = $de$,
    description = No,
    symbol = $i^2$
}
\newglossaryentry{g}{
    name = $ghi$,
    description = Maybe,
    symbol = $n^2$
}

\makeglossaries

\begin{document}
\printglossaries
\newpage
\gls{a}, \gls{d} and \gls{g} are part of the glossary. But I want
the 
\end{document}

This produces:

image of glossary

Edit: The calc package (internally loaded by pdfpages), redefines \setlength so that it can no longer be prefixed by \global. Without the global assignment the lengths are reset back to 0pt after the .aux file is input (since the .aux file is input within a group). In this case, the lower-level TeX assignment is required:

\makeatletter
\AtEndDocument
{%
  \glsFindWidestUsedAnyNameSymbol{\widestsymbol}%
  \settowidth{\widestname}{\glsgetwidestname}%
  \immediate\protected@write\@auxout{}
   {%
    \string\global\string\widestsymbol=\the\widestsymbol
    \string\global\string\widestname=\the\widestname
   }%
}
\makeatother
  • Thanks Nicola, this does exactly what I described and would work just fine... But is there a way to make this "tabular"? So all units would be parallel and also the description? – Bjartmar Sep 4 '16 at 22:50
  • 1
    @bjartmar I've updated my answer – Nicola Talbot Sep 5 '16 at 10:49
  • thanks for your time on this update. This seems more difficult than I thought. Wish I could give you another up-vote. :D – Bjartmar Sep 6 '16 at 17:52
  • Weird, using the package ' \usepackage{pdfpages} ' will misalign the description. – Bjartmar Sep 6 '16 at 22:53
  • @bjartmar I've updated my answer. – Nicola Talbot Sep 7 '16 at 7:45

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.