Monday, October 5, 2009

Creating Glossaries in TexShop on Mac

I was searching for a way to create a word list or dictionary in Latex, and came across the Glossaries package. This package is already installed if you use TexShop for Mac, but I still had problems getting it to work.

The problem is that you first have to be able to build the glossary file before you build your main latex document (similar to when you create a bibliography using Bibtex).

I found a very helpful blog post about all this here: http://www.ict-cloud.ch/2009/07/glossaries-acronyms-and-texshop.html.

I followed his steps and created a text file called "glossary_run.engine" that contained the following code:


#!/bin/sh

bfname=$(dirname "$1")/"`basename "$1" .tex`"

makeindex -s "$bfname".ist -t "$bfname".alg -o "$bfname".acr "$bfname".acn
makeindex -s "$bfname".ist -t "$bfname".glg -o "$bfname".gls "$bfname".glo


Save this file (you must use the .engine extension) to Users/.../Library/TexShop/Engines directory.

(Note: I first tried this with TextEdit. Even if you remove the .rtf extension, this will not work. It will work if you copy and paste the code into Emacs and then save it)

Next, make the file executable. In terminal, navigate to the above directory and type

$ chmod a+x glossary_run.engine

There you have it. The next time you open TexShop, the glossary_run engine (or whatever you named it) will be in the dropdown list next to typeset. Before you build your latex document, select this engine from the drop down and click typeset to build your glossary file first.


To use the glossaries package you will need the following in your preamble:


\usepackage[acronym]{glossaries} %makes a separate acronym list
%there are lots of different options for this package. acronym enables me to define acronyms as well as words

\makeglossaries

%Glossary-File - can include a separate glossary file here
\include{glossary file name.tex}

%Acronyms - can include a separate acronym file
\include{acronym file name.tex}

\begin{document}


Here is the test code I played around with. Instead of including separate files, I defined some terms and acronyms in the preamble. If I do it this way, I do not need the include terms, and instead just use the makeglossaries command:


\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage[acronym]{glossaries} % make a separate list of acronyms

\makeglossaries

%new glossary term
\newglossaryentry{sample}{name={sample}, description={a sample entry}}

%new acronym
\newacronym[\glsshortpluralkey=cas,\glslongpluralkey=contrived acronyms]{aca}{aca}{a contrived acronym}

\begin{document}
A \gls{sample} entry and %\gls{aca}.

Second use: \gls{aca}.

Plurals: \glspl{sample}.

%Reset acronym to first count

\glsreset{aca}

%note this now uses the plural form
First use: \glspl{aca}. Second use: \glspl{aca}.

\printglossaries

\end{document}



11 comments:

  1. Hi Monica

    Thanks for the link to my Blog. But just one question: Why don't you use Trackback-Links?

    With kind regards
    Pascal

    ReplyDelete
  2. Hi Monica,

    Thanks a lot for your help

    Regards,

    Romain

    ReplyDelete
  3. Wow, this worked the very first time I tried and did exactly what I needed. Recommended procedures on other websites include using the terminal and that is so annoying when using Texshop. So thanks a LOT for that very nice extension.

    Nic

    ReplyDelete
  4. Hi Monica,

    Thanks for the great info and engine. I ran into one issue, though. When I typeset glossaries-file.tex using your engine, I get the following error

    Index style file ./glossaries-file.ist not found.
    Usage: makeindex [-ilqrcgLT] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]

    Have you run into this before? Any advice?

    Also, it seems that the original blog post you linked to is gone.

    ReplyDelete
  5. Hi Dan,
    I haven't tried this is a while, as lately I have been using Aquamacs as my Latex editor. I'll check this out in the next day or two and get back to you.

    ReplyDelete
  6. Hi Dan and Monica

    Thanks for the excellent blog and comments, I really appreciated it because I was struggling with the same issues.

    In particular, I received the same error (makeindex [-ilqrcgLT] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]) and could solve it by switching the order of the files in the engine:

    makeindex -s "$bfname".ist -o "$bfname".gls -t "$bfname".glg "$bfname".glo

    (note only the -o .gls and -t .glg are switched)

    I have only tried for the glossary (not for the acronyms), but I guess you have to change the engine for acronym as well.

    Hope that this will also solve your problem

    Cheers Stefan

    ReplyDelete
  7. Hi Monica and Stefan,

    Thanks for the replies. My glossary_run engine seems to be working now.

    In the block before your "test code", you show using an \include statement to include the glossaries-file in the preamble. Have either of you ever tried using that? LaTeX seems to get upset with me when I try to use the \include command in the preamble.

    I may have a lot of glossary terms, and I'd prefer to keep them in a separate file, if possible.

    Thanks again!

    ReplyDelete
  8. Hi Dan,
    You know, I'm not sure now. I'll go back through my files and see if I can find one where I did use an include. I'm pretty sure I tested everything before writing the blog post, including the ability to include separate glossary files.

    ReplyDelete
  9. The \include command didn't work until I removed the extension ".tex". I used TexShop on Mac.

    ReplyDelete
  10. Thank you! This worked like a charm and saved my thesis! :D

    ReplyDelete