Beginners Notes for Latex

This is just a random collection of notes about Latex covering hurdles I hit early on.

Including SVG images

Long story short, don’t bother, it’s not worth the hassle. In theory you can \usepackage{svg} but adding just that gave me a ton of errors mentioning xcolor names. Adding the line \PassOptionsToPackage{svgnames}{xcolor} to the preamble fixed that but when I tried to add an image I got an error starting Package svg Error: File `image-name_svg-tex.pdf' is missing.... I suspect under the hood the Latex SVG package converts the SVG image into a PDF+Latex and then includes that and something is going wrong.

The second answer to this Tex StackExchange question seems to be the simplest way to get the desired result. Essentially, you open the SVG in Inkscape and then export it as a PDF. When you select PDF as the export option have a look in the export options and you’ll find something about exporting text as a Tex file. That’s a little misleading, you’ll get a Tex file even if there is no text in the image The Tex file is when actually gets included in your document and it will import the image data (and draw and text).

If like me you have images in an images directory you’ll need to include the import library \usepackage{import} and then import the image created above like this:

\begin{figure}
    \centering
    \def\svgwidth{\columnwidth}
    \import{images}{image.pdf_tex}
\end{figure}

Notice that the file you are importing has the .pdf_tex extension. There is also excellent this guide which does a better job at explaining it than I do.

Images Always Appear at the Top of the Page

When I included an image with this code:

\begin{figure}
    \centering
    \def\svgwidth{5cm}
    \import{images}{image.pdf_tex}
\end{figure}

I found it always appeared at the top of the page, which wasn’t useful. The trick to get it to appear where it naturally should is to change the begin line to \begin{figure}[!htbp]. This is described here in more detail. Briefly, though, it tells Latex to just put the float where it appears in the source text and not to try and find the best position for it. See also this question.

Make Words Stick Together

In the dedication I was writing I had an awkward line break appearing in the middle of a name. This was causing just the surname to appear on a new line. What I wanted was the whole name to be on the next line or none of it. The solution is really simple, just include tildes ~ between words you want to stick together.

Use Greek Characters in Bibliography Entries

This one had me scratching my head for a while. I don’t know, for sure, that this is the whole solution but it’s a decent chunk of it. The problem I had was I had to write α-tin in one of my references. Latex, for all it’s wonderfulness, doesn’t seem to handle non-ascii characters very well. It feels like software from yesteryear. The solution is to \usepackage{textgreek} and then write the bibliography entry like this \textalpha-tin. Of course this makes perfect sense as soon as you realize that what’s in the Bib file just gets passed to Tex for processing once all the bits have been joined together to make a reference entry. See here for more background.