[Tex/LaTex] Glossaries Package and LaTeXTools

acronymsglossarieslatextoolssublime-text

I used the provided answers on TEX.se a lot while writing my Bachelor Thesis but couldn´t find an answer on the following question:

How do I use the LaTeXTools build-system with the glossaries package to have a list of acronyms somewhere in my document?

My MWE:

\documentclass{article} 
\usepackage[acronym,nomain,toc,shortcuts,xindy]{glossaries}
\makeglossaries 

\newacronym{Mr}{M$_r$}{Remanence}
\newacronym{Hc}{H$_c$}{Coercivity}

\setacronymstyle{long-short}
\begin{document}
\tableofcontents

\newpage
Here's a \ac{Mr} glossary entry.
\printglossaries

\end{document}

With my MWE on Sublime Text 3 and the latest version of LaTeXTools the following output was produced:
Page1 - no Acronyms section in the Content; Page2 - A well formatted acronym - but no Acronyms section at all
Using the Terminal (OS X and TeXLive 2016) with the following commands (thesis.tex is my file)

xelatex thesis
makeglossaries thesis
xelatex thesis
xelatex thesis

the correct output was produced:
Correct output produced with the terminal

Okay now why don´t I just use the Terminal: I have way more packages that require extra commands etc. – That might be obvious

Why don´t I use a TEX-specific editor: Until now the LaTeXTools Plugin does a great job and sublime text is just one of the most convenient text-editors i´ve seen so far so I would like to keep on going with it.

I already found a question related to this which is not quite answered (I just can´t link to it because i already used the 2 links I have with my little reputation…)

Thanks in Advance for any help!

Best Answer

There are a few different ways this could be approached.

The traditional builder that LaTeXTools uses launches latexmk, so you can solve the issue the same way you would for latexmk, i.e., add a .latexmkrc file to the directory containing your main tex document with the following contents:

add_cus_dep('glo', 'gls', 0, 'makeglossaries');
add_cus_dep('acn', 'acr', 0, 'makeglossaries');
sub makeglossaries {
    if ($silent) {
        system("makeglossaries -q \"$_[0]\"");
    } else{
        system("makeglossaries \"$_[0]\"");
    }
}
push @generated_exts, 'glo', 'gls', 'glg';
push @generated_exts, 'acn', 'acr', 'alg';
$clean_ext .= ' %R.ist %R.xdy';

I've based this on both the latexmk example file and this answer to a similar question.

Alternatively, as suggested in this question (I assume this is the one you were referring to), is to use the script builder. To do this, in your LaTeXTools.sublime-settings file (or, better, in the settings section of your Sublime project file, you need to change the builder setting to script and then change the builder_settings block to something like this:

"builder_settings": {
    "osx": {
        "script_commands": [
            "pdflatex -interaction=nonstopmode -synctex=1",
            "makeglossaries",
            "pdflatex -interaction=nonstopmode -synctex=1",
            "pdflatex -interaction=nonstopmode -synctex=1"
        ]
    }
}

Personally, I'd choose the former of these, as the second option will run the whole script every time you build, which could take an unnecessary amount of time if you're working on a really long document.

Related Question