❀✿❀ SuperLaserNino ✿❀✿

LaTeX

2 June 2015

Modified: 13 March 2016

2108 words

I have helped typeset three theses and many shorter documents in LaTeX and I realized that I find myself googling the same things over and over again. Therefore I decided to collect all the problems I have solved so far on this page. At the bottom there is a list of unsolved problems. The reader is invited to give me advice in the comments.

I will update this page when I learn new things.

This page is meant mostly as a reference for myself or others, for how to solve certain problems, technically. There won’t be much discussion of why you should do something a particular way. If you want to know more about that, I suggest you start with Practical Typography and if you’re still interested in typography after that, you can move on to The Elements of Typographic Style or something.

Contents

Standard packages for every document

\usepackage[a4paper, left=4.5cm, right=4.5cm, top=3cm, bottom=4.5cm, marginparwidth=4cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb}
\usepackage[hidelinks=true]{hyperref}
\usepackage[T1]{fontenc}

You probably know what most of these do. The geometry settings used here work well for symmetrical layouts. For asymmetrical layouts I like to use 2cm/6cm for inner/outer. That way I can put footnotes and pictures in the margins.

Microtype

\usepackage[activate={true,nocompatibility},final=true,kerning=true,spacing=true,tracking=true,shrink=30,stretch=30,factor=0]{microtype}
\microtypecontext{spacing=french}

Apart from the standard packages above, the microtype package is the single most important package in existence and should be included in every document. It does a number of things:

Fonts

I don’t have a huge problem with Computer Modern, but (1) it is overused, and (2) since it’s the default, most typographic sins are committed with Computer Modern, so I sometimes get a bad feeling about it (like with Times).

These are some acceptable fonts:

Palatino

\usepackage[osf,sc]{mathpazo}

Palatino is like the Times New Roman of pretty fonts. It’s like everyone who’s unsatisfied with Times goes through their system fonts and says, “oh, that looks fancy!” and chooses Palatino. This means it comes close to being overused, but it still looks good enough that you can use it without feeling bad. Also, the mathpazo package offers real small caps (sc), oldstyle numerals (osf), and most of the mathematical symbols you will ever need.

It also works well with Euler math if you’re into that kind of thing.

\usepackage{euler}

The Johannes Kepler Project

\usepackage[oldstylenums]{kpfonts}

I’ve not used this font yet but, apart from the capital T, I like the look of it. Like Palatino, Kepler offers real oldstyle figures, real small caps, and extensive math support. There is also a sans serif version of Kepler that you might want to use in combination with the serif version, but I haven’t looked at that, so it might suck.

If you’re inclined to save ink, Kepler also has a light option.2

A note on numerals

In normal text, you want to use oldstyle figures3 (lowercase numbers). You only want to use lining figures (uppercase numbers) in combination with all caps, in mathematical expressions, or in tables. With the settings I’ve described above, Palatino and Kepler will automatically switch to lining figures in math mode. If you want to set all the numbers in a block as lining figures, you can place

\fontfamily{pplx}\selectfont

for Palatino, and

\fontfamily{jkpx}\selectfont

for Kepler at the beginning of the block.

Spacing

\usepackage{setspace}
\setstretch{1.1}
\setlength{\parskip}{0pt}
\setlength{\parindent}{1.4em}

The default line spacing (\setstretch) is usually too narrow. For most texts, a setting of 1.1 looks good, for very math-heavy or German texts I go up to 1.14 to avoid collisions between ascenders, descenders, accented mathematical symbols, etc.

I prefer indented paragraphs to vertically spaced paragraphs. If you like vertical space between your paragraphs, set \parindent to 0; if you like indented paragraphs, set \parskip to 0. Otherwise LaTeX may add spacing between paragraphs, which will look hideous if the paragraphs are indented.

Colors

To define colors:

\usepackage{color}
\definecolor{color-name}{gray}{0.8}
\definecolor{other-color}{rgb}{0.8, 0.9, 1}

To use colors:

\color{color-name}

Tables

\usepackage{booktabs,suinitx}

\begin{table}[htb]\fontfamily{pplx}\selectfont
\begin{center}
    \begin{tabular}{lrcS[table-format=1.1]}
    \toprule%
    left & right & centered & \multicolumn{1}{c}{aligned numbers}\\\midrule{}
    1 & 2 & 3 & 4.5 \\
    \bottomrule{}
    \end{tabular}
    \caption{Description}
    \label{tab:label}
\end{center}
\end{table}

The S alignment option aligns numbers by their decimal point. Because the column title isn’t a number, it needs to be wrapped inside the weird \multicolumn command. The [table-format=x.y] aligns the column in a way that numbers with x digits to the left and y digits to the right of the decimal point are centered. You can omit this option if everything looks fine, but it’s useful as soon as you have different numbers of digits in each row.

If you use S, the numbers will be set in math-mode, so they will automatically be lining figures. If you use l, r, or c, you will have to declare the \fontfamily at the top of the table to get them to look right.

Colored cells

Include the package

\usepackage{colortbl}

and call

\cellcolor{color-name}

inside your table-cell. The cell coloring doesn’t go all the way to horizontal rules, making the coloring discontinuous. That looks weird when you want to have entire columns in one color. I haven’t figured out how to prevent that.

Table with colored cells.

Prettier unordered lists

\newcommand{\sbt}{\,\begin{picture}(-1,1)(-1,-3)\circle*{2.2}\end{picture}\ }
\renewcommand{\labelitemi}{\sbt}
\renewcommand{\labelitemii}{\sbt}

The bullet character (•) is too large. To get better looking bulleted lists, this snipped works wonders. You can manipulate the size of the circle by changing the 2.2 above to something else. If you need more than two levels in your lists, you can duplicate the last line and change \labelitemii to \labelitemiii.

Prettier ordered lists

\usepackage{enumerate}

\begin{enumerate}[1]
\item Item One
\item Item Two
\end{enumerate}

Make numbered lists less cluttered.

Better lists

Headers and footers

If you’re using the book document class, never ever use the default headers. I don’t know whose idea it was to make the headers ITALIC ALL CAPS, but trust me, it was a terrible idea. This setting was surprisingly difficult to change, too.

\newcommand{\spacedlowsmallcaps}[1]{\lowercase{\textsc{#1}}}
\usepackage[automark]{scrpage2}
\clearscrheadings
\renewcommand{\chaptermark}[1]{\markboth{\spacedlowsmallcaps{#1}}{\spacedlowsmallcaps{#1}}}
    \renewcommand{\sectionmark}[1]{\markright{\thesection\enspace\spacedlowsmallcaps{#1}}}
\lehead{\mbox{\llap{\small\thepage\kern2em}\hfil{\headmark}}}
\rohead{\mbox{\hfil{\headmark}\rlap{\small\kern2em\thepage}}}
\renewcommand{\headfont}{\small}

I don’t even want to look at those settings.

Example headers

You can take this as inspiration and go from there.

Chapter and section headings + spacing

\usepackage{titlesec}

\newfont{\chapterNumber}{eurb10 scaled 7000}

\titleformat{\chapter}[display]%
{\relax}{\mbox{}\marginpar{\vspace*{-\baselineskip}\color{chapternumbergray}\chapterNumber\thechapter}}{0pt}%
    {\LARGE\itshape}[\normalsize\vspace*{.8\baselineskip}\titlerule]%

\titlespacing*{\chapter}{0pt}{0cm}{1cm}
\titleformat{\section}{\Large}{\makebox[0cm][r]{\thesection\hspace{1em}}}{0em}{\scshape\lowercase}
\titlespacing*{\section}{0pt}{\baselineskip}{\baselineskip}
\titleformat{\subsection}{\large}{\thesubsection}{.6em}{\itshape}
\titlespacing*{\subsection}{0pt}{\baselineskip}{\baselineskip}
\titleformat{\subsubsection}{\bfseries}{}{}{}
\titlespacing*{\subsubsection}{0pt}{\baselineskip}{\baselineskip}

Headings

These settings are strongly inspired by Robert Bringhurst’s The Elements of Typographic Style. The chapter numbers are set in the Euler font.

Custom table of contents

\usepackage{tocloft}
\usepackage{textcase}
\setcounter{tocdepth}{2}

Chapters:

\renewcommand{\cftchappresnum}{\bfseries}
\renewcommand{\cftchapfont}{\normalfont}
\renewcommand{\cftchappagefont}{\color{pagenumbergray}\normalfont}
\renewcommand{\cftchapleader}{\hspace{1.5em}}
\renewcommand{\cftchapafterpnum}{\cftparfillskip}

Sections:

\renewcommand{\cftsecpresnum}{\scshape}
\renewcommand{\cftsecfont}{\normalfont}
\renewcommand{\cftsecpagefont}{\color{pagenumbergray}\normalfont}
\renewcommand{\cftsecleader}{\hspace{1.5em}}
\renewcommand{\cftsecafterpnum}{\cftparfillskip}

Subsections:

\renewcommand{\cftsubsecpresnum}{\scshape}
\renewcommand{\cftsubsecfont}{\normalfont}
\renewcommand{\cftsubsecpagefont}{\color{pagenumbergray}\normalfont}
\renewcommand{\cftsubsecleader}{\hspace{1.5em}}
\renewcommand{\cftsubsecafterpnum}{\cftparfillskip}

This is in part influenced by Bringhurst and in part by common sense. Most tables of content are typeset terribly.

Title page

An example for a title page. The contents of this will depend very strongly on the specific document you’re making.

\begin{titlepage}
\begin{center}
{\LARGE University Name}\\
\begin{figure}[h]
\hbox{}\hfill
    \begin{minipage}[t]{10cm}
    \begin{center}
        \includegraphics[width=5cm]{university-logo}
    \end{center}
    \end{minipage}
\hfill\hbox{}
\end{figure}
{\large Department or something\\[2cm]}
{\huge Bachelor's Thesis\\[1cm]}
{\Large\bf Title\\[1.0cm]}
{\small Author:}\\[0.2cm] {\large Author}\\[0.2cm]
{\small date}\\[0.8cm] {\small Advisor:}\\[0.2cm]
{\large Advisor name}\\[0.2cm]
Advisor's employer\\[2.2cm]
{\small Address}
\end{center}
\end{titlepage}

Figures

Regular floating figures

\begin{figure}[tbh]
\centering
\includegraphics[width=8cm]{bunnies.jpg}
\caption{A normal figure.}
\label{fig:normal}
\end{figure}

Sometimes you want to put a p in the position options, too.

Margin figures

\marginpar{ %
    \includegraphics[width=\marginparwidth]{picture}%
    \captionof{figure}{A margin figure.}%
    \label{fig:marginfig}%
}

For best results, use \raggedright or \RaggedRight.

Footnotes as margin notes

\usepackage{ragged2e}

\newcounter{mnote}
\renewcommand{\footnote}[1]{ %
    \refstepcounter{mnote}%
    \mbox{\textsuperscript{\themnote}}%
    \marginpar{\footnotesize\RaggedRight\mbox{\themnote}\hspace{5pt}#1}%
}

You can call these with \footnote. If you need to move the content of the footnote up along the margin, use

\newcommand{\fnhere}[1]{\refstepcounter{mnote}\marginpar{\footnotesize\RaggedRight\mbox{\themnote}\hspace{5pt}#1}}
\newcommand{\fnref}{\mbox{\textsuperscript{\themnote}}}

Then you can call \fnhere{Footnote content} where you want the note to appear in the margin and \fnref{} where you want the reference to appear in the text. This is only for moving footnotes up. They should move down automatically, if there are other \marginpars in the way.

\raggedright makes the text left-aligned, which looks better because margins are usually too narrow for proper justified text. \RaggedRight requires the ragged2e package and will re-enable hyphenation for the left-aligned text.

Some symbols

Some symbols I sometimes forget.

Kerning

a\kern+1ptb

This adds 1pt of separation between the letters a and b. When I have the time, I use this extensively for adding space to the insides of paretheses since they’re set too tight in most fonts. Also works in math mode.

Colored boxes

I rarely use these because I always run into problems. But it can be kinda pretty and you can probably fix the issues if your document isn’t too complex.

\definecolor{boxblue}{rgb}{0.8, 0.9, 1}

\usepackage[framemethod=tikz]{mdframed}
\newmdenv[innerlinewidth=0.5pt,roundcorner=2pt,backgroundcolor=boxblue, linecolor=boxblue,innerleftmargin=6mm,innerrightmargin=6mm,innertopmargin=6pt,innerbottommargin=6pt,skipabove=1ex,skipbelow=1ex]{mybox}

You use this with

\begin{mybox}
Content
\end{mybox}

Colored boxes

Prettier ellipsis

\newcommand{\dotdot}{.\hspace{.6pt}.\hspace{.6pt}.}

The normal \ldots{} command creates too much space between the dots and, even with french spacing turned on, the amounts of space to the left and right of the ellipsis aren’t the same, so it looks uneven. You may need to adjust the amount of \hspace, depending on the font.

Comparison:

Comparison between \ldots and \dotdot

Only numbering certain lines of an align environment

\begin{align}
  1 + 2 &= a\nonumber\\
  3 + 4 &= b \cdot e^{2\tau}\nonumber\\
  6 + 1 &= c
\end{align}

Only the third line has a number

What I haven’t figured out yet

Footnotes

  1. From Practical Typography:

    Lowercase letters don’t ordinarily need letterspacing. Nor do capital letters when they appear at the beginning of a word or sentence, because they’re designed to fit correctly next to lowercase letters. But when you use capital letters together, that spacing looks too tight.

    That’s why you always add 5–12% extra letterspacing to text in all caps or small caps, particularly at small sizes.

  2. From the documentation:

    Save up your toner and the environment, use the “light” option, it’s 20% toner less!

    The metrics are the same. The display is not very good, but the print is fine if you like light fonts.

  3. I never know which word to use. “Numerals”? “Figures”? “Numbers”? And then I just end up using them all interchangeably and it’s terrible.

Observations

27 May 2015

440 words

Observations:

I’m curious to see how this develops.

I have an excellent awkwardness memory

22 March 2015

336 words

People always tell me not to worry so much about seeming awkward in social situations. Like, “oh, nobody is ever going to remember you being weird or stuttery or that time where you didn’t know what to say, or said something wrong, or mispronounced something. They’re all just as caught up with thinking about their own awkwardness that they don’t even notice you’re being weird as well.”

And then I think, that makes sense, because I do spend a lot of time worrying about how I myself come across. And it’s good to keep in mind that other people probably do the same, because I tend to forget that other people are human as well and have emotions and issues themselves. (I think this is like a reverse typical mind fallacy. Does that already exist? If it doesn’t, we could call it the atypical mind fallacy.)

But when I think about it more, I realize that I am exceedingly good at detecting when other people might feel awkward – or, rather, when other people are in situations where I would feel awkward. And I always remember that. You know, that time when you were asked something by the teacher and you didn’t know the answer and looked really shameful and started blushing furiously and tried to force some words out, but you just didn’t know which ones and you were probably thinking, “Fuck, I should know this!” Or that time you were talking to a person at a party and you heard something wrong and replied something weird; chances are, I’ll obsess about your situations just as much as I would if it’d been me in the situation. And I’ll spend hours thinking what could you have done differently to avoid this?

So now I’m wondering: Is this whole “nobody notices/remembers how awkward you are”-thing all a big lie that therapists tell to calm me down, or do I just have an especially good awkwardness memory?

Joylent

4 February 2015

Modified: 13 July 2015

808 words

Last Friday I received my first batch of Joylent, which is like Soylent, only the J stands for “Europe.” I’d ordered the “variety pack” with 15 meals, which means 5 bags with differently flavored powder: vanilla, banana, chocolate, and strawberry.

I was one of the people who fell in love with Soylent when it was still a Kickstarter and you couldn’t order it yet, not even in America. I can enjoy food in a social setting, and there are some things that taste pleasant, but generally, I’m not a big fan of food. Some people find cooking relaxing — I find it emotionally draining. There are too many things going on, you have to be careful not to touch anything or you’ll burn your fingers, and the food will get horribly burned, too, if you stop stirring for half a second. Hence I just end up eating toast with cheese or Nutella or something, 99% of the time, and then I keep biting the inside of my mouth instead of the food, so everything tastes like blood anyway.

If drinking three glasses of gray liquid every day could make all that go away and the only price was that it didn’t taste as exciting? That would be fantastic.

So I opened the first package, vanilla, and took in the kind of un-vanilla-y smell of the enormously large quantity of powder. If you’re used to two spoons of protein powder in ≈450ml of milk or water, this will be a bit of a shock. And it doesn’t just look like a lot of powder, you can tell while you’re drinking it, too, because there’s not enough water to dissolve it all. I’m not going to lie: the first mouthful of that stuff was really disgusting. But I didn’t let that stop me.

While I continued to drink and did my best not to throw up all over the kitchen table, my hunger did start to fade, though I did eat other stuff as well because let’s be serious, 2100 calories for a full day? I haven’t tracked this with great accuracy, but I’m pretty sure I can eat at least 2500 calories and still lose weight.

Trying the next flavor, banana, on the second day, I realized my initial disgust may have been due, in part, to the fact that vanilla flavored Joylent tastes infinitely worse than any of the other kinds. Banana is better, chocolate is better still, and strawberry is about the same as chocolate. Of course it still feels like mud, but I got used to that surprisingly quickly.

My digestion wasn’t super excited about this whole experiment, but as long as I ate some solid food at some point during the day (which I was doing anyway, lest I starve) it seemed to work out fine. Also, it’s not like my digestion is super excited about anything. Maybe I should see a doctor about that. Okay, before everyone starts shouting “TMI, TMI!”, let’s move on to something more fun.

Things you can do to put more joy in Joylent

These were just the things I tried in the short time where this experiment went on. I’m sure there are a million other things you can do.

So, am I going to buy more?

At first it looked very much like I wasn’t even going to finish the 5 bags I had bought, but as soon as I went back to normal food, I started craving Joylent because the whole process just sucks so much less. First of all it’s faster to make and consume, and second of all, you know how after lunch you just want to sleep for an hour? That doesn’t seem to happen with Joylent.1 The hunger just goes away quietly after some time, while I’m still able to stay awake and think.

In conclusion, nutrition is not a solved problem, but at least I don’t have to use the toaster so often anymore.

Footnotes

  1. Update: After further experimentation, I have to report that, actually, it does.

The Power of Dimensions

27 January 2015

357 words

I suspect the majority of people who have any use for this already know about it and use it daily, but I have only recently realized how cool this is.

You know how you always forget what the relationship between c, λ, and ν is? Like, they give you the energy of a photon and you’re supposed to calculate the wavelength? You know E = h ν, but now you have to figure out how to convert the frequency to a wavelength. Now, instead of looking the formula up on Wikipedia, how about using dimensional analysis? You write down the unit of λ, which is m, and then you only need to figure out how to construct that unit with a speed and a frequency. Speed is m s–1 and frequency is s–1, so to cancel the seconds out, you divide the speed by the frequency and get m s–1 s = m, from which you can easily see that λ must be c / ν. And you’re done.

Another good example is when you have an exponential function or a sine or cosine. You know the argument for these functions must be dimensionless, so if you’re not sure what factors you have to put into the argument, you can just keep throwing stuff in there until all the units cancel and it’ll probably be right.

Or if you want to sanity check your calculations you need only look at your dimensions. When you see a sum of, say, a length and an area, you know you’ve done something wrong.

The same applies of course to the other kind of dimension — the one in vectors. When you try to put a three dimensional vector in an exponential function, you have a problem. You’re probably missing another vector to form a dot product with. Or if you’re trying to add a vector and a scalar, again, you know you’re missing something.

It seems pretty simple, but I was surprised how useful this is once you get the hang of it.