# How run makeindex inside memoir class document for glossary?

How can one run makeindexfrom within a memoir documentclass source so as to create a glossary?

For a glossary, calling makeindex (via the imakeidx package) fails with memoir.

Here is my source, which calls makeindex (via the imakeidx package) seemingly using the syntax as described in Section 17.3 of memman.pdf.

When I run a pdflatex make file on the source (from within TeXShop, via the pdflatexmk engine), I get the following error:

Rule 'cusdep goo gas book': File changes, etc:
Non-existent destination files:
'book.gls


The source:

% BOOK.TEX

\documentclass{memoir}

\usepackage{amsmath}

\usepackage[makeindex]{imakeidx}
\makeglossary
\makeindex[options=-s glossarystyle.gst,-o book.gls book.glo]

\begin{document}

The empty set is denoted by $\emptyset$.%
\glossary{$\emptyset$}{empty set}

The set of all subsets of a set $X$ is denoted by $\mathcal{P}(X)$.%
\glossary{$\mathcal{P}(X)$}{power set of set}

\newpage

For sets $X$ and $Y$, the notation $f \colon X \to Y$ means that $f$ is a functions from $X$ to $Y$.%
\glossary{$f \colon X \to Y$}{functions from one set to another}.

\printglossary

\end{document}


The referenced style file glossarystyle.gst:

% GLOSSARYSTYLE.GST
%%% basic.gst basic makindex glossary style file
%%% Output style parameters
preamble "\\begin{theglossary}"
postamble "\n\\end{theglossary}\n"
item_0    "\n\\glossitem"
delim_0   "{\\memglonum{"
encap_suffix "}}}"
%%% Input style parameters
keyword "\\glossaryentry"


Note that I am using just the built-in glossary facilities of the memoir class, and not the external package glossaries!

the latexmkrc file being called by the TeXShop.app's built-in pdflatexmk engine is:

# latexmkrcedit
# Edit this File to add/change dependencies and rules
# The following is used by ALL the latexmk engine files

# change the empty string ,'', to '--shell-escape' to add the shell-escape default
$TSUserCompileOptions = ''; #$TSUserCompileOptions = '--shell-escape';

# turn recorder option off (no .fls file generated)
#$recorder=0; # Custom dependency for glossary/glossaries package # if you make custom glossaries you may have to add items to the @cus_dep_list and corresponding sub-routines add_cus_dep('glo', 'gls', 0, 'makeglo2gls'); sub makeglo2gls { system("makeindex -s '$_[0]'.ist -t '$_[0]'.glg -o '$_[0]'.gls '$_[0]'.glo"); } # The glossaries package, with the [acronym] option, produces a .acn file when processed with (xe/pdf)latex and # then makeindex to process the .acn into .acr and finally runs of (xe/pdf)latex to read in the .acr file. Unfortunately # the glossary package does just the reverse; i.e. (xe/pdf)latex processing produces a .acr files and makeindex then # is used to convert the .acr file to a .acn file which is then ... . This dependency assumes the glossaries package. add_cus_dep('acn', 'acr', 0, 'makeacn2acr'); sub makeacn2acr { system("makeindex -s '$_[0]'.ist -t '$_[0]'.alg -o '$_[0]'.acr '$_[0]'.acn"); } # for glossary package (Sigh...) --- they can co-exist! add_cus_dep('acr', 'acn', 0, 'makeacr2acn'); sub makeacr2acn { system("makeindex -s '$_[0]'.ist -t '$_[0]'.alg -o '$_[0]'.acn '$_[0]'.acr"); } # example of an added custom glossary type that is used in some of the glossary/glossaries example files: # this is for the new glossary type command \newglossary[nlg]{notation}{not}{ntn}{Notation} from the glossaries package # NOTE: the glossary package uses a very different command: the <in-ext> and <out-ext> # are reversed in the calling sequence :-( add_cus_dep('ntn', 'not', 0, 'makentn2not'); sub makentn2not { system("makeindex -s '$_[0]'.ist -t '$_[0]'.nlg -o '$_[0]'.not '$_[0]'.ntn"); } # for the glossary package (Sigh...) --- they can co-exist! add_cus_dep('not', 'ntn', 0, 'makenot2ntn'); sub makenot2ntn { system("makeindex -s '$_[0]'.ist -t '$_[0]'.nlg -o '$_[0]'.ntn '$_[0]'.not"); } # dependencies for custom indexes using the index package # examples for sample.tex for index package: add_cus_dep('adx', 'and', 0, 'makeadx2and'); sub makeadx2and { system("makeindex -o '$_[0]'.and '$_[0]'.adx"); } add_cus_dep('ndx', 'nnd', 0, 'makendx2nnd'); sub makendx2nnd { system("makeindex -o '$_[0]'.nnd '$_[0]'.ndx"); } add_cus_dep('ldx', 'lnd', 0, 'makeldx2lnd'); sub makeldx2lnd { system("makeindex -o '$_[0]'.lnd '$_[0]'.ldx"); } # Custom dependency and function for nomencl package add_cus_dep('nlo', 'nls', 0, 'makenlo2nls'); sub makenlo2nls { system("makeindex -s nomencl.ist -o '$_[0]'.nls '$_[0]'.nlo"); }  And in turn the pdflatexmk engine is the script file: #!/bin/bash # pdflatexmk.engine # export TSBIN="$HOME/Library/TeXShop/bin/tslatexmk"
export LTMKBIN="$HOME/Library/TeXShop/bin/tslatexmk" export LTMKEDIT="$HOME/Library/TeXShop/bin"
# make sure latexmkrcedit exists in bin
if [ ! -e "${LTMKEDIT}/latexmkrcedit" ] ; then cp "${TSBIN}/latexmkrcDONTedit" "${LTMKEDIT}/latexmkrcedit" fi # Use local rc file platexmkrc if it exists. p = project export localrc="" if [ -e ./platexmkrc ] ; then export localrc="-r ./platexmkrc" fi "${LTMKBIN}"/latexmk -pdf -r "${LTMKEDIT}/latexmkrcedit" -r "${TSBIN}/pdflatexmkrc" ${localrc} "$1"


For an ordinary index, calling makeindex (via the imakeidx package) does work with memoir.

For example, the following does produce an index:

\documentclass{memoir}

\usepackage{amsmath}

\usepackage[makeindex]{imakeidx}
%%\makeglossary
%%\makeindex[options=-s glossarystyle.gst -o book.gls book.glo]

\begin{document}

The empty set is denoted by $\emptyset$.%
\index{empty set!notation}
%%\glossary{$\emptyset$}{empty set}

The set of all subsets of a set $X$ is denoted by $\mathcal{P}(X)$.%
\index{power set}
%%\glossary{$\mathcal{P}(X)$}{power set of set}

\newpage

For sets $X$ and $Y$, the notation $f \colon X \to Y$ means that $f$ is a functions from $X$ to $Y$.%
\index{function!notation}
%%\glossary{$f \colon X \to Y$}{functions from one set to another}.

\printindex
%%\printglossary

\end{document}


Here the referenced index style file indexheaders.ist is:

headings_flag 1


New try: no error but no glossary

I changed the source file line

 \makeindex[options=-s glossarystyle.gst,-o book.gls book.glo]


to

\makeindex[name=glossary,title=Index of notation,options=-s glossarystyle.gst -o book.gls book.glo]


and changed each \glossary command so as to add optional file name (glossary), e.g.:

glossary[glossary]{$\emptyset$}{empty set}


Now when I run TeXShop's pdflatexmk engine, it generates no errors -- but no glossary at all! It generates the expected glossary.glo file with the several \glossaryentry commands, but the glossary.gls file is empty.

Solution!

Thanks to help from Herb Schulz on the macosx-tex mailing list and privately, the following solves the problem while still using only the internal glossary facility of memoir, without the glossaries package.

The corrected source:

\documentclass{memoir}

\usepackage{amsmath}

\newcommand{\from}{\mathpunct{:}}
%\newcommand{\from}{\protect\colon}
%\newcommand{\from}{:}

\makeglossary[glossary]
\renewcommand*{\glossaryname}{Index of Notation}

\makeindex

\begin{document}

The empty set is denoted by $\emptyset$.%
\index{empty set!notation}
\glossary[glossary]{$\emptyset$}{empty set}

The set of all subsets of a set $X$ is denoted by $\mathcal{P}(X)$.%
\index{power set}
\glossary[glossary]{$\mathcal{P}(X)$}{power set of set}

\newpage
$f \from X \to Y$
For sets $X$ and $Y$, the notation $f \from X \to Y$ means that $f$ is a functions from $X$ to $Y$.%
\index{function!notation}
\glossary[glossary]{$f \from X \to Y$}{function from one set to another}

\printglossary[glossary]
\printindex

\end{document}


Indeed, with TeXShop there is no need for imakeidx. The source is processed from within TeXShop using its pdflatexmk engine and the following additional file platexmkrc placed in the source directory:

add_cus_dep('glo', 'gls', 0, 'makeglo2gls');
sub makeglo2gls {
system("makeindex -s basic.gst -t '$_[0]'.glg -o '$_[0]'.gls '$_[0]'.glo"); };  (For completeness: the three \newcommand{\from}... versions shown are ways of avoiding an error with the math relation \colon in the argument to \glosary, without having to work around an error in \@@glossary, per Extra '@' in glossary entry with memoir class .) • Is there supposed to be a comma after -s glossarystyle.gst (in \makeindex)? It doesn't look right, but I might be wrong. It looks as though you're creating the glossary files both through \write18 and pdflatexmk, which might be confusing things. – Nicola Talbot Jul 29 '16 at 22:13 • I wondered about the comma separator in the options, so I also tried deleting it. Same error. – murray Jul 29 '16 at 22:25 • Do you have any reason to think this is supposed to be possible? I don't know Memoir well, but there's no obvious indication that imakeidx is supported on first glance through section 17.3 of the manual. – cfr Jul 30 '16 at 3:46 • The error message looks like it's coming from pdflatexmk not from TeX (or memoir). Do you have extra code for latexmk in a .latexmkrc file? – Nicola Talbot Jul 30 '16 at 10:03 • @cfr: The memoir class does support using imakeidx in order to be able to call makeindex from within the source .tex file. I'll edit my post to indicate how that works. – murray Jul 30 '16 at 15:17 ## 1 Answer The error message Rule 'cusdep goo gas book': File changes, etc:  looks like a message from (pdf)latexmk (not a TeX message). This suggests there's a rule for latexmk along the lines of add_cus_dep('goo', 'gas', 0, 'something');  This doesn't really make sense as your document isn't writing or reading any files with those extensions, so it seems like something's confusing latexmk, but there's nothing in the code you've posted that explains it (as far as I can tell). The rest of the error message:  Non-existent destination files: 'book.gls  is suggesting that it's expecting the file book.gls to exist, but with memoir, the .gls file is the file that's dependent on the .glo file. You can tell this from the transcript (book.log) file which contains the line: Writing glossary file book.glo  This is the file that contains the glossary information for makeindex to process. A little later in the transcript is another line: No file book.gls.  This is the file that's read in by \printglossary and is the file that makeindex needs to create. So the full build sequence is: pdflatex book makeindex -s glossarystyle.gst -o book.gls book.glo pdflatex book  This is what pdflatexmk ought to be doing if the dependencies were set up correctly, but it seems that something has muddled them. You can invoke makeindex using TeX's shell escape, which is what you seem to be trying to do with imakeidx, but as @egreg pointed out in the comments, that can't be done in this situation. Instead you can explicitly use the shell escape with \write18. Like this: \documentclass{memoir} \immediate\write18{makeindex -s glossarystyle.gst -o \jobname.gls \jobname.glo} \usepackage{amsmath} \makeglossary \begin{document} The empty set is denoted by$\emptyset$.% \glossary{$\emptyset$}{empty set} The set of all subsets of a set$X$is denoted by$\mathcal{P}(X)$.% \glossary{$\mathcal{P}(X)$}{power set of set} \newpage For sets$X$and$Y$, the notation$f \colon X \to Y$means that$f$is a functions from$X$to$Y$.% \glossary{$f \colon X \to Y\$}{functions from one set to another}.

\printglossary

\end{document}


Note that \immediate is needed here to ensure that makeindex is run before \makeglossary overwrites the .glo file. Now you just need:

pdflatex book
pdflatex book


This causes a couple of errors for your test file: \doglobookmark is undefined (I'm assuming you simply omitted it from your test file) and makeindex reports an error (transcript in book.ilg):

!! Input index error (file = test.glo, line = 3):
-- Extra @' at position 106 of first argument.


This is caused by the premature expansion of \colon, which has already been dealt with in another question.

• That method, using \write18, does not work for me from within TeXShop. A solution that does is described in there "Solution" section of my original post. – murray Aug 1 '16 at 20:19
• @murray If you've found a solution, you ought to post it as an answer to get the question off the unanswered list. (You can self-answer your own questions.) The \write18 solution won't work if the shell escape has been disabled. – Nicola Talbot Aug 2 '16 at 15:42