Schlagwort-Archive: LaTeX


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/

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:


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. []

How to Correctly Write Units in Texts


Small mistakes in your texts are unavoidable and will happen to anyone, but keeping them to a minimum helps the reader to understand the text. Especially, when it comes to formatting a text you should follow a common procedure to avoid confusion and increase recognizability. Being consistent, also across texts and authors, is the aim of standardization. When it comes to units, the International System of Units (SI) was defined to make sure everyone uses the same units of measure like meter or second and not arbitrary things like the average length of your thumbnail or the shortest time it takes to empty a beer bottle1.

Having said this, I’m always seeking for standards and try to stick to them2. Handling units of measure is quite important in physics, so I had a look into how the formatting is done — to get away from these »we have been doing it like this forever« or »I like it like this« statements. So, after this lengthily introduction, a short overview of some points in how to correctly write down numbers and units.

Official Document

The International System of Units is defined by the French »Bureau International des Poids et Measures« and can be accessed on their website The most recent brochure is the 8th edition from 2006 (direct link).
Out of this 88 pages long document I’ve selected some things I found most interesting and/or relevant for writing a thesis in physics. For each bullet point I gave a page number of the brochure in brackets.

Selected Definitions

  • SI prefixes (like kilo, mega, milli) refer strictly to powers of 10. Hence, a kilobit is 1000 bit, not 1024 bit (= 210 bit). If you need a power of 2, use kibi (Ki), mebi (Mi), gibi (Gi), … to be consistent with the SI definition. [121]
  • Unit symbols are always printed upright, disregarding the surrounding text. [130]
  • Unit symbols are lower case (like m for meter), except those derived from a proper name (e.g. Pa from Pascal). [130]
  • Unit symbols are mathematical entities and not abbreviations. Therefore, no period or plural s is used after a unit3. [130] (See also Andi’s post for more upright/italics defintion)
  • Also because of this entity character, a combination of value and unit is seen as a product of both. So T = 273 K can be also written as T/K = 273. Therefore, the correct labeling of a graph’s axis is »T/K« and not »T [K]«. [132]
  • Having the entity character in mind helps to remember the formatting of value and unit: Always use a space between value and symbol representing a multiplication sign. Recommended for that is a thin space. The only exception are the plane angle units (°, ‚, „) which are written without a space between value and unit (20° 11‘) [133]
  • Large numbers can be formatted to help readability by introducing a thin space between groups of 3 digits, counting from the decimal marker (1 234.567 8). Spaces can be left out but no dots nor commas are used for this purpose. [133]
  • Interesting for German readers: A multiplication of two numbers should be shown either by brackets or the multiplication sign × but not by a vertical centered dot. [134]


It takes some effort to consider all these rules and don’t mess them up in a long document. If you are writing you text in LaTeX you can use the siunitx package. Have a look at it, it might make your life easier.

  1. of average size []
  2. One thing I also like is the standardization of giving a date. According to ISO 8601 it is YYYY-MM-DD instead of YYYY/DD/MM or DD.MM.YYYY and whatever other combination are out there. []
  3. Only exception for the period is the end of a sentence. []

Use TrueType fonts with LaTeX

Usage of custom fonts in LaTeX is quite easy - if you use xelatex as a compiler.

This article shows you how to include custom fonts (TrueType) into your LaTeX project.

LaTeX is a great tool to write a nicely set text, respecting all the important constraints for typesetting. So far so good, but out of the box it lacks some customization features. One very important one (at least for me) is the use of custom fonts. It is nice, to highlight a new chapter with a different font than everything else and the title page might also get a bit more interesting.

So, how to do it? There is a complicated way with pdflatex, the more or less default compiler to generate a PDF from the TeX source. And there is a newer compiler, xelatex, which comes with some nice features, like the support of TrueType fonts. So I will concentrate on the xelatex solution and leave you and Google alone, if you want to try to get it running with pdflatex1.

Get the fonts you like

Download Googles fonts

Click on the arrow button on the top right to get a .zip with the selected fonts.

Long introduction, but let’s get started. First you need fonts, preferably in the TrueType format .ttf. A good source for fonts that are free to use is Google’s Web Fonts library. Browse through there, select the fonts you want and at the end download them with the little arrow button on the top right. Or browse through the corresponding Google Source project.

Once you have the fonts, extract them and put the .ttf files into a subfolder of your LaTeX project. In this example we choose ./fonts/.

Prepare your project

You have to do two things: compile with xelatex and add the font in the source.

For the first I can only tell you how to do it with this great editor Sublime Text 2, because this is how I do it. If you don’t know this editor yet, give it at least a short look. Anyhow, in the master .tex file you add the following line at the very top:

%!TEX program = xelatex

This tells Sublime Text, which compiler to use. When you then hit Cmd+B (on OSX, Windows is probably Strg+B), you should see a PDF generated by xelatex. Easy, right?

You also need to add the font definition into the source code. I show you an example with the font RobotoSlab, that is also used in the teaser image2:

  Path = font/,
  UprightFont = RobotoSlab-Light,
  ItalicFont = RobotoSlab-Thin,
  BoldFont = RobotoSlab-Bold,
  BoldItalicFont = RobotoSlab-Bold
The names in the definition should match the file names.

The names in the definition should match the file names.

As you can see, I was a bit creative with the mapping. It is a good idea to map all of these styles, but sometimes fonts don’t support them. Like RobotoSlab, which doesn’t come with an italic version. The names after the equal sign have to match the file names in your directory (see screenshot on the right).

Use the font

To use the font, just use the \RobotoSlab command we just created, like this excerpt from my title page:


\huge \textbf{\Title}\vspace{12mm}

\Large \Author

Thats it, not so difficult I think. Still questions? → Comments

  1. I did try it with pdflatex, because I didn’t know if the change to xelatex causes troubles. It is quite complicated, because you have to generate several files before you can use it, see for example here or here. In the end I gave up and tried xelatex. []
  2. from Google Web Fonts []

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:


% Load hyperref before glossaries

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


\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.


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 to preview generated PDFs
$pdf_previewer = 'open -a %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'",
				"-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:, manual (PDF).

Have fun!

Based on this forum post and this blog entry.

  1. the PDF in this case []