Schlagwort-Archive: Sublime Text

Dr.

Sublime Text 3: use latexmk with ‚-shell-escape‘

Not only me, but also Andi spent an awful lot of time on this issue: get Sublime Text 3 (with LaTeXTools) to compile a LaTeX document with the -shell-escape option. The option enables shell execution of programs from within pdflatex to include external programs. We needed that for the minted package which supplies syntax highlighting to code blocks by accessing the Pygments library. But other LaTeX plugins require -shell-escape as well, so here is how we got it running:

Edit the file

~/Library/Application Support/Sublime Text 3/Packages/LaTeXTools/builders/traditionalBuilder.py

and look for the definition of DEFAULT_COMMAND_LATEXMK. Add an -shell-escape after the %E so that the definition looks like:

DEFAULT_COMMAND_LATEXMK = ["latexmk", "-cd",
				"-e", "$pdflatex = '%E -shell-escape -interaction=nonstopmode -synctex=1 %S %O'",
				"-f", "-pdf"]

After this change, restart Sublime Text 3. This is not a good solution because it alters the plugin and might get overwritten with a future update. But at least it runs. Credits go to Andi for finding this.

Bonus: minted and memoir

As a bonus, I got an additional error when trying to compile the document with both minted and memoir packages enabled:

usr/local/texlive/2014/texmf-dist/tex/latex/float/float.sty:68: LaTeX Error: Command \newfloat already defined. [      {}}}]

I don’t exactly know what is going on here, but apparently it’s a conflict between these two packages1. My quick’n’dirty hack is the following:

\let\newfloat\undefined
\usepackage{minted} 

Solution from this discussion.

  1. Or maybe another one and minted, but who knows. (La)TeX is this »special« language amongst the programming languages which get’s sulky sometimes for no obvious reason. []
Dr.

Make Sublime Text 2 automatically compile glossaries

Note: The LaTeXTools Plugin got an update, which made these changes useless because the build wouldn’t work anymore. You can now choose the build system by a tag in the beginning of the file, but the glossaries are not compiled automatically.

While trying to include the glossaries LaTeX package into my project, I figured that Sublime Text 2 doesn’t automatically compile the glossary list. Unfortunately it takes some work, so I will show you how.

First take this simple LaTeX file:

\documentclass{article}

% Load hyperref before glossaries
\usepackage[colorlinks]{hyperref}
\usepackage[acronym]{glossaries}

% Define the acronyms
\newacronym{led}{LED}{light-emitting diode}
\newacronym{eeprom}{EEPROM}{electrically erasable programmable
read-only memory}
\makeglossaries

\begin{document}
\tableofcontents

\section{Student Memoirs}

When I was a student I often left bits of electronic circuitry
in my pockets, such as \glspl{led} and \glspl{eeprom}, which
often ended up in the washing machine. The \glspl{led} didn't
fair too badly, but the \glspl{eeprom} frequently broke.

\printglossaries
\end{document}

So far so good. We include the glossaries package with the predefined acronym set (line 5), created some acronyms (line 8-11), included them in the text and printed the list of Acronyms (line 23). If you compile this, you will notice that the list is not printed. The reason for this is, like for bibliography, a list has to be compiled first, but of course it is not by default.
You could do it by manually running the makeglossaries command, but I’m using Sublime Text to reducing the steps to reach the final product1. So an automatism is needed.

Since Sublime Text is using latexmk for creating the PDF, we need a modified runscript for this. Save the following code somewhere on your Computer, where you find it most suitable. I’ve put it into the Sublime-Package-Users directory (~/Library/Application Support/Sublime Text 2/Packages/User).

# The main command for pdflatex
$pdflatex = 'pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %O %S';

# Always create PDFs
$pdf_mode = 1;

# Use Skim.app to preview generated PDFs
$pdf_previewer = 'open -a Skim.app %S';

# Use continous mode by default
#$preview_continuous_mode = 1;

# output to the directory called output in the current directory
#$out_dir = './output';

# file extensions to remove when cleaning
$clean_ext = 'acn acr alg aux bbl bcf blg brf fdb_latexmk glg glo gls idx ilg ind ist lof log lot out run.xml toc dvi';

# make latexmk run makeglossaries automatically
add_cus_dep('glo', 'gls', 0, 'makeglossaries');
add_cus_dep('acn', 'acr', 0, 'makeglossaries');

sub makeglossaries {
    system "makeglossaries $_[0]";
    if ( -z "$_[0].glo" ) {
        open GLS, ">$_[0].gls";
        close GLS;
    }
    return 0;
}

Download LaTeX.latexmk

Now we need to tell Sublime Text to use this file. The compilation is managed by the LaTeX.sublime-build file in the plugin’s directory. Because an update will overwrite this file, you should make a copy to the Users directory:

cp ~/Library/Application Support/Sublime Text 2/Packages/LaTeXTools/LaTeX.sublime-build ~/Library/Application Support/Sublime Text 2/Packages/User

Now you open this file in a texteditor and edit the following

		"cmd": ["latexmk", "-cd",
				"-e", "\\$pdflatex = 'pdflatex %O -interaction=nonstopmode -synctex=1 %S'",
				//"-silent",
				"-f", "-pdf"],

to this:

		"cmd": ["latexmk", "-r",
				"/Users/USERNAME/Library/Application Support/Sublime Text 2/Packages/User/LaTeX.latexmk"],

Make sure to include your user on the place of USERNAME, otherwise this won’t work.

After this, everything should work and you have now a glossary at the end of your LaTeX generated PDF. More documentation about the »glossaries« package: latex-community.org, manual (PDF).

Have fun!

Based on this forum post and this blog entry.

  1. the PDF in this case []