Creating Glossaries with MMD and LaTeX

Thanks to all that have posted here and on Fletcher’s site! My Scrivener-Markdown-LaTeX workflow is working well in almost every particular.

I’ve used my workflow to produce the first draft of a reference work that contains a table of contents, table of figures, appendices, index, images, etc. all set up exactly the way I would like and all getting internally referenced correctly. It is great.

I have only one remaining issue, and I am at an impasse: I cannot figure out how to generate a glossary, which is very important for this work. The most help on setting up a glossary comes from Fletcher’s “MultiMarkdown User’s Guide,” but I have exhausted my abilities to figure out where I am going astray. (I also have been studying Huw Evans’ “A toad’s guide to using Scrivener – MultiMarkDown – Latex, which has been indispensable. Much thanks to both Fletcher and Huw for these great references.)

I know this post is inexcusably long and that few forum members, if any, will want to wade through it. However, as this is, in Fletcher’s words, an “Advanced” topic, for anyone that might be willing to help, I figure providing more info is better than providing less. For anyone who even attempts to wade through this post, I am very, very grateful.

This is where I am:

Per Fletcher’s guide, MultiMarkdown has a feature that allows footnotes to be specified as glossary terms. He states that the glossary format for the footnotes is:

 [^glossaryfootnote]: glossary: term (optional sort key)
     the actual definition belongs on a new line, and can continue on
     just as other footnotes.

Trying to follow that, I am leaving out the sort key and creating an entry as follows:

[^civilization]: glossary: civilization
     the society, culture, and way of life of a particular area

Question One: Do I need to, like I would with a footnote, put a separate anchor in the text? For example, if the above glossary entry were really a footnote, then someplace in the text I would write: [^civilization]

If I do include a separate anchor, I end up with the following in the “.tex” file that is produced when I compile my project in Scrivener:

. . .fugiat nulla pariatur. Excepteur \newglossaryentry{civilization}{name={civilization},description={the society, culture, and way of life of a particular area}}\glsadd{civilization} sint occaecat cupidatat

Does this look right?

(Just so you know, the gibberish text around the glossary term is Lorum Ipsum.)

Question Two: How do I generate the Glossary?

Fletcher writes:

Unfortunately, it takes an extra step to generate the glossary when creating a pdf from a latex file:

  1. You need to have the basic.gst file installed, which comes with the memoir class.

  2. You need to run a special makeindex command to generate the
    .glo file: makeindex -s ‘kpsewhich basic.gst‘ -o “filename.gls” “filename.glo”

  3. Then you run the usual pdflatex command again a few times.

My questions:

  1. Where should “basic.gst” be found? It is a little unclear to me where “basic.gst” is installed. I was able to find “basic.gst” installed in the following path on my computer:

/usr/local/texlive/2014/texmf-dist/makeindex/memoir

So hopefully that means I have satisfied Fletcher’s first requirement. Is that where “basic.gst” should be found?

  1. Is it right that I should run the makeindex command as specified above from an OSX terminal window? If so, it is not working. This is the step that I believe is failing for me. Here is what I can tell you:
  • After I have compiled in Scrivener, I have about four files, one of which is the “.tex” file. My next step is to use TexShop and typeset the document with the LaTeX engine. After my first typeset run using the LaTeX engine, additional files are created, including a “.glo” file. Should I be running the makeindex command first, before any type of “.glo” file is created?

  • Does it matter what directory I am in when I try to run the makeindex in terminal?

  • Should Fletcher’s reference to “filename.gls” and “filename.glo” mean that I should, when running the makeindex command, replace “filename” with my own project name?

If I do the substitution of “filename” with my own project name, running makeindex from the terminal gives me the following message: “Index style file kpsewhich basic.gst not found.” As I pointed out, I know that basic.gst is on the computer. I’m afraid I do not understand what “kpsewhich” is and whether that needs to be installed. (And, if that is the case, where would I find it and where would it need to be installed.)

  1. Although I am using the memoir class, I am using the custom LaTeX options in Scrivener and invoking the memoir document class there. My custom LaTeX code includes in the header section the following lines:

\usepackage{glossaries}
\glstoctrue %Adds glossary to toc on additional typsetting run
\makeglossaries

and, in the footer section, after the command \backmatter, I include:

\printglossaries

Am I missing something there?

I doubt anyone will get this far in an attempt to help, but if so, here is a hearty “Thank you!” I am only doing this because I’m not certain what is left for me to try. Consider this a desperate Hail Mary pass—and I apologize if I have violated any forum rules in the length of this post or if I should have asked this question in a different way or different place.

Success!

If anyone is curious or if it proves helpful to others down the road, I will try to answer some of my own questions.

Question One: Do I need to, like I would with a footnote, put a separate anchor in the text? For example, if the above glossary entry were really a footnote, then someplace in the text I would write: [^civilization]

To get it to work, I did have to include the separate anchor. It was important to have both the \newglossaryentry and the \glsadd codes in the “.tex” file. The example in the original post works. (If I omitted the anchor, resulting in the loss of the \glsadd code, it did not work.)

Question Two: How do I generate the Glossary?

My questions:

  1. Where should “basic.gst” be found? It is a little unclear to me where “basic.gst” is installed. I was able to find “basic.gst” installed in the following path on my computer:

/usr/local/texlive/2014/texmf-dist/makeindex/memoir

Since I was able to get the glossaries package to work, presumably the above location is correct for the “basic.gst” file.

One thing not mentioned by Fletcher is that you need to load the glossaries package after certain other packages that may be required. According to the beginner’s guide that accompanies the LaTeX glossaries package, the packages that must be loaded before glossaries are, specifically, hyperref, babel, polyglossia, inputenc and fontenc. I was using both inputenc and fontenc and so I moved them in the preamble prior to invoking the glossaries package.

  1. Is it right that I should run the makeindex command as specified above from an OSX terminal window? Yes.

This is what I did that worked:

  1. After compiling your Scrivener project, go ahead and do a typeset run using the LaTeX engine. That creates a “.glo” file and an “.ist” file in the same directory/folder that contains the “.tex” file.

  2. Open a terminal window on OSX. Use the cd command to change directory to get to the directory/folder that contains the files produced during the Scrivener compile and LaTeX run. (It will be the folder that contains the “.tex”, “.glo” and “.ist” files.

  3. Run makeindex from the terminal. I had success by running it within the folder that contained the “.tex” file that was produced during the Scrivener compile process. (So open terminal and use the cd command to change directory to that folder.) I did not run the command as specified by Fletcher. I ran the command specified in the beginner’s guide that accompanies the glossaries package. This is the command I used:

makeindex -l -s myDoc.ist -o myDoc.gls myDoc.glo

Running that command successfully produced the following response in terminal:

This is makeindex, version 2.15 [TeX Live 2014] (kpathsea + Thai support).
Scanning style file ./myDoc.ist…done (29 attributes redefined, 0 ignored).
Scanning input file myDoc.glo…done (1 entries accepted, 0 rejected).
Sorting entries…done (0 comparisons).
Generating output file myDoc.gls…done (6 lines written, 0 warnings).
Output written in myDoc.gls.
Transcript written in myDoc.ilg.

(This was a “one-entry” glossary run as a test, but the numbers would, I presume, change quite a bit for a real glossary with lots of entries. Also, when running makeindex, you will replace myDoc with the base name of your LaTeX document file. And you should avoid spaces in the file name—therefore, a one word file/project name is probably best to avoid potential trouble.)

What happens here is that the .glo file is the input file and the .ist file is the style. Makeindex uses those files to create an output file with the extension .gls. That is the file that is used to create the glossary.

  1. Run the LaTeX engine again.

  2. As I have “real” indexes, I then run the makeindex engine from within TexShop. After that, I run the LaTeX engine again a couple of times.

That process is working for me.

So, just to try and be a little clear, let me repeat and now answer my questions from the original post:

  • After I have compiled in Scrivener, I have about four files, one of which is the “.tex” file. My next step is to use TexShop and typeset the document with the LaTeX engine. After my first typeset run using the LaTeX engine, additional files are created, including a “.glo” file. Should I be running the makeindex command first, before any type of “.glo” file is created? No. The .glo file must exist BEFORE running makeindex.

  • Does it matter what directory I am in when I try to run the makeindex in terminal? Yes. Run it from the folder/directory that contains the files resulting from the Scrivener compile process.

  • Should Fletcher’s reference to “filename.gls” and “filename.glo” mean that I should, when running the makeindex command, replace “filename” with my own project name? Yes.

  1. Although I am using the memoir class, I am using the custom LaTeX options in Scrivener and invoking the memoir document class there. My custom LaTeX code includes in the header section the following lines:

\usepackage{glossaries}
\glstoctrue %Adds glossary to toc on additional typsetting run
\makeglossaries

and, in the footer section, after the command \backmatter, I include:

\printglossaries

Am I missing something there? No. This all seemed to work fine after I got the makeindex command working from the terminal window. However, I did, as noted above, move the inputenc and fontenc packages in the preamble BEFORE invoking the glossaries package.

If I learn anything new as I increase the size of the glossary, I’ll report back. Hope this is helpful. And, again, thanks for all the great resources that have been made available for trying to combine Scrivener, MMD and LaTeX.