CV in LaTeX with moderncv

It’s easy:

\documentclass[11pt,a4paper]{moderncv}
[...] % load your usual packages

% moderncv themes
\moderncvcolor{grey} % color options 'blue' (default), 'orange', 'green', 'red', 'purple', 'grey' and 'black'
\moderncvstyle{casual} % style options are 'casual' (default), 'classic', 'oldstyle' and 'banking'

% Your contact data
\firstname{Max}
\familyname{Mustermann}
\address{Thisstreet 1}{12345 Exampleville}
\phone{ (01\,23)~45\,67\,89\,00}  
\email{me@myself.de}    
\photo[64pt]{myself}

\begin{document}
\maketitle

\section{Education}
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}
[...]
\end{document}

I had the problem that when you specify months and years instead of only years, the left margin is too small. You can adjust that with these two lines:

\setlength{\hintscolumnwidth}{0.25\textwidth}
\AtBeginDocument{\recomputelengths}

Also, the languages take up a lot of space, you can just put it into two columns to save space. This is better than the cvdoubleitem in my opinion, because you are more flexible to change the order. I suppose you can still add the comment, if you need to, try it out.

\begin{multicols}{2}
\cvitem{Language 1}{Skill level}
[...]
\end{multicols}

Letters in LaTeX

My standard letter in LaTeX with the class scrlttr2 (created by a German to adhere to German letter guidelines):

\documentclass[fromalign=location, fromphone=true, fromemail=true, locfield=wide]{scrlttr2}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\setkomavar{fromname}{Max Mustermann}
\setkomavar{fromaddress}{Musterstr.\ 1\\12345 Musterstadt}
\setkomavar{fromphone}{01234/56789000}
\setkomavar{fromemail}{mustermx@provider.xy}
\setkomavar{signature}{Max Mustermann}
\setkomavar{subject}[]{}
\setkomavar{date}{7.\ August 2013}

\begin{document}
\begin{letter}{Jane Doe\\
Example street 2\\
54321 Exampleville
}
\opening{Dear Mrs.\ X,}
this is the letter I promised.
\closing{Kind regards,}
\end{letter}
\end{document}

The variables ‘from…’ set the sender, the recipient is given right after begin letter. The sender information can be set at strange places, for a very simple letter I use ‘fromalign=location’ which results in the sender information somewhere at the top right, a bit higher than the recipient, but not in the headline. With the standard settings the e-mail address is too wide for the sender field, so I widen it with ‘locfield=wide’.

Ugly LaTeX

How to make your LaTeX document look ugly. More specific: The request is to use Arial, 12pt, 1.5 line spacing. Looks very ugly but here it is:

\documentclass[12pt]{scrartcl} % use 12pt
[...]
\usepackage{setspace} % manipulate line spacing
\renewcommand{\rmdefault}{phv} % Arial for serif typeface (normal text)
\renewcommand{\sfdefault}{phv} % Arial for sans-serif (headings)
[...]
\begin{document}
[...]
\onehalfspacing % use 1.5 line spacing
[...]

Hebrew hyphenation patterns for babel

So… in the last post I convinced LaTeX to typeset Hebrew with texlive and babel. There are still a few details to work out, so this deals with the first one: Hyphenation patterns.

The error:

Package babel Warning: No hyphenation patterns were loaded for
(babel)                the language `Hebrew'
(babel)                I will use the patterns loaded for \language=0 instead.

As Hebrew is not hyphenated at all, this is of no concern that no hyphenation patterns are found. But LaTeXs "solution" of taking English hyphenation patterns leads to very strange results. So tell babel that it shouldn’t try and really there are no hyphenation patterns for Hebrew with:

\makeatletter\let\l@hebrew\l@nohyphenation\makeatother

If this doesn’t work, you might fall back to define a hyphenation pattern length of 255 (see Stackexchange).

Using babel with Hebrew in texlive

Many articles say that to use Hebrew with LaTeX, you should use xelatex instead of Tex Live (which is default on Ubuntu). It IS possible to write Hebrew using Tex Live, here is how. Working minimal example:

\documentclass{article}
\usepackage[utf8x]{inputenc} 
\usepackage[hebrew,english]{babel} 

\begin{document}
test
 \sethebrew
שלום
\end{document}

On my Ubuntu 12.10 installation this fails with this error (even though I have the packages ‘culmus’ and ‘texlive-lang-hebrew’):

kpathsea: Running mktextfm jerus10
mktextfm: Running mf-nowin -progname=mf \mode:=ljfour; mag:=1; nonstopmode; input jerus10
This is METAFONT, Version 2.718281 (TeX Live 2012/Debian)
kpathsea: Running mktexmf jerus10
! I can't find file `jerus10'.

Solution:

  1. Get the ‘jerus10.mf’ file from the hebtex LaTeX package (available on CTAN). Don’t install the package, it is deprecated (as in REALLY old).
  2. Put the ‘jerus10.mf’ file in the folder ~/texmf/fonts/source/hebrew/
  3. In terminal, run the command ‘texhash’. If it says ‘done’ without error, everything is fine.

The above file should work. It’s not particularily pretty and there are some compatibility issues with some packages that I might address another time. There are two possible error sources if you didn’t copy/paste carefully enough:

1. Enable UTF8X input

! Package inputenc Error: Keyboard character used is undefined
(inputenc)                in inputencoding `8859-8'.

or

! Package inputenc Error: Unicode char \u8:ש not set up for use with LaTeX.

If you want to write unicode Hebrew or copy-paste Hebrew from somewhere, you need to define the input encoding [utf8x], not only [utf8]:

\usepackage[utf8x]{inputenc} 

2. Be sure to change the language to Hebrew

! LaTeX Error: Command \hebshin unavailable in encoding OT1.

Fix this by declaring that the following text is Hebrew with

\sethebrew

Undefined references – LaTeX Warning

Sometimes LaTeX tells you this:

LaTeX Warning: There were undefined references.

If you get this warning, you will notice some ?? in your document at places where references should be. For references to sections, tables of figures, just run pdflatex again (and check for typos). For bibliography references you need to run bibtex.

Let’s assume you are writing a LaTeX file with the name ‘report.tex’. Do the following:

> pdflatex report.tex
[...]
LaTeX Warning: Citation `Liu2010' on page 1 undefined on input line 39.
[...]
LaTeX Warning: Reference `fig:results' on page 1 undefined on input line 65.
[...]
LaTeX Warning: There were undefined references.
[...]
LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.
[...]
> bibtex report
[...]
> pdflatex report.tex
[...]
LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.
[...]
> pdflatex report.tex
[...]

You need to run pdflatex again twice after calling bibtex. Twice, because layout may change and things end up somewhere else after you inserted the references.

Installing a LaTeX package

Let’s say you want to create a A0 poster with LaTeX. You find an example on the internet that starts like this:

\documentclass[final]{beamer}
\usepackage[orientation=landscape,size=a0,scale=1]{beamerposter}
\usepackage{lipsum} % lorem ipsum

You download the example ‘example.tex’, run pdflatex on it and it fails like this:

me@mycomputer: pdflatex example.tex
This is pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011)
 restricted \write18 enabled.
entering extended mode
(./example.tex
LaTeX2e <2011/06/27>
Babel  and hyphenation patterns for english, dumylang, nohyphenation, lo
aded.
(/usr/share/texlive/texmf-dist/tex/latex/beamer/beamer.cls

[...]

! LaTeX Error: File `beamerposter.sty' not found.

Type X to quit or  to proceed,
or enter new name. (Default extension: sty)

Enter file name: 

This means, that this particular LaTeX package ‘beamerposter’ is not installed on your machine. Bad luck.

What to do if you have admin permissions

On linux, open your favourite package manager (e.g., Synaptic), type the name of the LaTeX package (in this case ‘beamerposter’). If the result shows a linux package like ‘texlive-latex-extra’ install it and be happy.

What to do if you do not have admin permissions

1. Download the package

Go to CTAN. Search for the missing package name and click on the best result. In the beamerposter case, you will end up here. To get to a page where you can actually download the package, you need to follow the link listed under CTAN path in the box at the bottom of the page. Click on ‘Download’ and save the ‘beamerposter.zip’ somewhere on your computer.

We will also assume that the second package, ‘lipsum’, is also missing, you would find it on CTAN here.

2. Extract the package to the correct location

The READMEs of LaTeX package usually contain "Put it in your tex folder" or "Put it somewhere where LaTeX can find it" (if they contain anything on installation at all). What this actually means is, that there are several possibilities. LaTeX searches for sources in a few directories, depending on your system and LaTeX distribution. Some examples for linux and texlive are:

/usr/share/texmf/
/usr/share/texlive/texmf/
/usr/local/share/texmf/tex/latex/
~/texmf/

If you don’t have admin permissions, the easiest is to create a folder ‘texmf’ in your home directory (~). You will need in this folder a subfolder ‘tex’, and then ‘latex’. So in total you should have:

~
   |- texmf/
      |- tex
         |- latex

In this folder, i.e., ~/texmf/tex/latex/, you can put any style files and latex will find them. It is advisable to create separate folders for separate packages, so we will extract the ‘beamerposter.zip’ that we downloaded into the folder ~/texmf/tex/latex/beamerposter/ and ‘lipsum.zip’ into the folder ~/texmf/tex/latex/lipsum/. This is what the folder looks like now:

~
   |- texmf/
      |- tex
         |- latex
            |- beamerposter
               |- beamerposter.pdf
               |- beamerposter.sty
               |- beamerposter.tex
               |- example.tex
               |- README
            |- lipsum
               |- lipsum.dtx
               |- lipsum.ins
               |- lipsum.pdf
               |- README

As you can see, we now have a ‘beamerposter.sty’. So if this were the only package we needed, we could skip step 3. Unfortunately we are still missing ‘lipsum.sty’, so this is what step 3 is about.

3. Create a style file

As we see, there is no style file ‘lipsum.sty’. There is only a ‘lipsum.ins’ and a ‘lipsum.dtx’ file. The .dtx file is only to create the documentation and we can ignore it here. To create the style file, run latex (latex, not pdflatex!) on ‘lipsum.ins’:

me@mycomputer: latex lipsum.ins 

The result should look like this:

~
   |- texmf/
      |- tex
         |- latex
            |- beamerposter
               |- ...
            |- lipsum
               |- lipsum.dtx
               |- lipsum.ins
               |- lipsum.log
               |- lipsum.pdf
               |- lipsum.sty
               |- README

4. Try pdflatex again

And it should work (unless of course a different package is missing…).

Updating the Database

If you install fonts and in some other cases you need to update the LaTeX package database. On linux/texlive this is done with ‘texhash’:

me@mycomputer: texhash

More

This works for regular LaTeX packages. Bibtex packages go to texmf/bibtex. If there are fonts involved, you will need to put them in texmf/fonts and it might get tricky.

LaTeX at Wikibooks

Typesetting text in math mode

In information retrieval and text classification, tf-idf plays a big role. Read the Wikipedia article to learn what it is about, here I want to deal with the problem of typesetting the formula in LaTeX.

The formula is log-weighted term frequency tf times inverse document frequency idf, if we naivly write this down, we arrive at this:

tf-idf_{t,d} = (1 +\log tf_{t,d}) \cdot \log \frac{N}{df_t}

When you look at the LaTeX output, you will see that several things go wrong. In math mode, LaTeX interprets two letters next to each other as a product of two variables. So the name tf becomes the mathematical expression “t times f” and is typeset accordingly. Also, in case of tf-idf, the name contains a hyphen. In math mode a hyphen between two expression is interpreted as a minus sign. So this is definitely not what we want.

How do we solve the problem? What we want is that this part is interpreted as normal text. One possibility to add text to equations is the command \mbox{} (another is the command \text{} which requires the amsmath package). So this is it:

\mbox{tf-idf}_{t,d} = (1 +\log \mbox{tf}_{t,d}) \cdot \log \frac{N}{\mbox{df}_t}

Backup slides in LaTeX beamer

Sometimes you have a LaTeX beamer presentation and want to have some "backup" slides that you may show if the audience is really interested in this detail, but otherwise not. There is a simple solution for that, the package appendixnumberbeamer.

You need to load the package in the preamble:

\usepackage{appendixnumberbeamer}

Then you just need to use "appendix" before the slides you want to have as backup:

\begin{frame}
Thank you for your attention!
\end{frame}

\appendix
% start backup slides here

\begin{frame}
\frametitle{Detailed Results of User Study}
...
\end{frame}

Remember to run pdflatex twice for the changes to take effect!

The slides in the appendix will not count towards the total slide number that is displayed for the normal slides. Backup slides will have their own slide numbers and total slide numbers counted anew from the start of the appendix. Very handy!

You can organize your backup slides in sections, these section will not appear in the table of content. If you use a beamer template with navigation (miniframes like in Szeged, or split like in Malmoe), the backup slides will not appear in the navigation. A cool thing is that on the backup slides, the navigation will show the structure of the backup slides, so you can easily change to the slide you want. A disadvantage is of course that everybody will see that you have more backup slides than actual slides 😉

Change the encoding of a file

My favourite topic is "encoding" (of course that was sarcasm). So my first post is about how to change the encoding of some text file from Latin-1 to UTF-8 on command line:

iconv -f latin1 -t utf8 source_file > target_file

Of course we need to know what encoding the file is in… which may be a topic for some future post.