[Tex/LaTex] Use a quality glossary and acronym list in Lyx

glossarieslyxnomenclature

The question How to combine Acronym and Glossary shows us how to make a great glossaries and acronym lists. I would like to use a quality glossary and acronym list in Lyx.

enter image description here

This may be too large a question to ask all at once. I have broken a possible first step, combining use of nomenclature and glossary. I am trying to use two packages together:

  1. nomenclature to render the glossary and acronym list in Lyx
  2. glossaries to use the full name the first time it is used in the text and the acronym after.

My attempt is shown below:

enter image description here

%% LyX 1.6.7 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{nomencl}
% the following is useful when we have the old nomencl.sty package
\providecommand{\printnomenclature}{\printglossary}
\providecommand{\makenomenclature}{\makeglossary}
\makenomenclature

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{hyperref}
\usepackage{glossaries}
\usepackage{nomencl}
\makeglossary
\makenomenclature
\RequirePackage{ifthen}
\renewcommand{\nomgroup}[1]{
\ifthenelse{\equal{#1}{A}}
{\item[\textbf{Acronym}]}
{ \ifthenelse{\equal{#1}{G}}
{\item[\textbf{Glossary}]}{}}
}

\makeatother

\usepackage{babel}

\begin{document}
\newglossaryentry{api}{%
type=\acronymtype,
name={API},
description={Application Programming Interface},
first={Application Programming Interface (API)},
see=[Glossary:]{apig}
}

%%% The glossary entry the acronym links to    

\newglossaryentry{apig}{%
name={API}, %
description={An Application Programming Interface (API) is a particular set of rules %
and specifications that a software program can follow to access and make %
use of the services and resources provided by another particular software %
program that implements that API%
}}

\nomenclature[a]{API}{Application Programming Interface}

\nomenclature[g]{API}{%
An Application Programming Interface (API) is a particular set of rules %
and specifications that a software program can follow to access and make %
use of the services and resources provided by another particular software %
program that implements that API%
}

\printnomenclature{}

main text body

first use \gls{api}

subsequent use of \gls{api}
\end{document}

Now how can I create a macro to automatically use all the glossary entries in nomenclature to render the printed glossary. Right now I am typing them twice, as you can see. Bonus points if you can get rid of the "Nomenclature" heading and make the Acronym and Glossary headings larger. Extra special bonus points if you can somehow get the links to work properly, for example, between an acronym and its corresponding glossary entry. I will check if the solutions provided render in Lyx.

Best Answer

The following steps will lead to a glossary and an acronym list in LyX. When using this approach, "nomenclature" and "nomenclature entries" in LyX cannot be used.

Setup

  1. In the LaTeX Preamble ("Document > Setting...") we add:

    \usepackage[acronym]{glossaries}
    \makeglossaries
    
  2. The generating the index files for the glossaries package uses different options than for the nomencl package. The following wrapper script needs to be used. saved in the home directory .

    • for linux, save the file as mkgloss.sh in your home directory and make the script executable by chmod u+x mkgloss.sh

      #!/bin/sh
      makeglossaries `basename "$1" .glo`
      
    • for windows, (caution: not tested!) save the file as mkgloss.bat in your home directory

      REM for loop used for formatting purpose only
      FOR /F %%I in ("%1") do makeglossaries %%~nI
      
  3. We tell LyX to use this script instead of the default makeindex -s nomencl.ist by changing the field "Nomenclature command" in "Tools > Preferences... > Output > LaTeX". We use the filename with absolute path. Depending on where you have saved the file, for example, for linux,

    "/home/tux/mkgloss.sh"
    

    or for windows,

    "C:\Documents and Settings\Peter\mkgloss.bat"
    

Usage

Now, we can write acroyms and a glossary entries in the LyX document by using TeX code/ERT (Ctrl-L). For example,

\newglossaryentry{api}{type=\acronymtype, name={API}, description={Application
Programming Interface}, first={Application Programming Interface (API)},
see=[Glossary:]{apig}}

\newglossaryentry{apig}{name={API},
description={An Application Programming Interface (API) is a particular set
of rules and specifications that a software program can follow to access and
make use of the services and resources provided by another particular software
program that implements that API}}

In the LyX document \gls{api} as TeX code/ERT will use the glossary entry api and \glsadd{apig} will add the entry apig to the glossary without generating text.

Finally, we write the two pieces of TeX code \printglossary[type=\acronymtype] and \printglossary[type=main] at the end of the document (or whereever the acronym list and glossary should appear). Now the PDF displays both.

A working example can be found here (on that site save the text as ".lyx" file). Removing all page breaks from the example we get:

compiled LyX file


Notice: You can debug whether "mkgloss" script is correctly executed by opening LyX Messages Pane (View > Messages Pane). If the script is executed, you will see the script name appears somewhere in Messages Pane.

Problem: A change of an acronym entry seems to be missed by LyX and the acronym list in the output (PDF) is not updated.

Workaround: Add following TeX code/ERT in your LyX document:

\newglossaryentry{dummy}{name={DUMMY},
description={Type or erase a letter here and LyX will update the glossary and
acronym list (do *not* use space as only working under certain circumstances)}}
\glsadd{dummy}

By changing the description of this entry LyX will get reminded to update glossary and acronym list.

Related Question