Too good to throw away – too hard to remember

Main menu

Post navigation

About swk

I am a computational linguist, teacher of computer science and above all a huge fan of LaTeX. I use LaTeX for everything, including things you never wanted to do with LaTeX. My latest love is lilypond, aka LaTeX for music. I'll post at irregular intervals about cool stuff, stupid hacks and annoying settings I want to remember for the future.

If you print a professional book where graphics go until the very edge of the page, you need to give a file with cropmarks (Beschnittmarken) to the printer. This is how to produce them in LaTeX, it is actually very simple with the package crop:

\usepackage[cam,width=154truemm,height=216truemm,center]{crop}

The book in question was A5 paper which has a size of 148mm x 210mm. I wanted to have 3 more milimeters to each side. This makes the final paper size I want to have 154mm x 216mm, which I have given above. As I want the markings equally on each side, I use the option center to center the content in the middle of the larger page. The option cam print standard cropmarks (this is also the default).

Now the only thing left to do is adjust the graphics. For every page where a graphic goes to the edge of the page, increase it a little bit over the margin. There are several ways to do that, depending on what exactly it is you do. This is an example for a colored background image that fills the whole page. The important part is \dimexpr\paperwidth+6mm which just adds 6mm to the height of the picture:

I have files copied from Windows computers in ancient times. The filenames contain special characters and they have been messed up somewhere along the way. For example I got a file named 9.5.2 Modelo de aceptaci??n (espa??ol).doc in the folder 9 Garant??a del Estado.

First, I want to find and list these files. Stackexchange tells us how to do that:

LC_ALL=C find . -name '*[! -~]*'

This will find all names that have non-ASCII letters, not only those that are broken. But in my case I have folders where ALL of the names are broken, so I don’t mind.

Second, I want to fix the names. I did it manually, but for future reference, if I ever were to do anything like that again, I might use one of the solutions proposed in this thread on serverfault.com.

Unison is a tool to compare and synchronize two folders. You can configure it by GUI, but at least for me (Kubuntu 18.04) not all settings work. Specifically, I cannot set the value “0”. But there is an easy way around the problem. Unison puts a file called Profilename.prf (where “Profilename” should be replaced with the actual name of your profile) into the folder .unison in your home directory. This is simply a text file with key-value pairs, that you can edit at your leisure.

Here are standard settings for comparing two directories without comparing the file permissions:

Now for the coolest feature of Unison: It is written in OCaml!! OCaml was used in my third semester to teach functional programming. I remember clearly the teacher telling us about the “usefulness” of the language. She had one slide with examples of programs written in OCaml. And she must have looked very hard to find any. There were a grand total of three programs on the slide. Two formal logic resolvers or something to that effect (we were like “yeah, really useful”). And MLDonkey (peer-to-peer filesharing was BIG in those days before Netflix, Spotify and fast internet) which she clearly didn’t know what it was for. So now, if she still has that slide, I can add another program! And a really useful one at that!

Here are dirty hacks for page layout in LaTeX and a few useful standard settings.

I load the following document class:

\documentclass[bibliography=totoc,12pt,a4paper,headsepline]{scrbook}

The option bibliography=totoc puts the bibliography into table of contents. The option 12pt sets normal font size to 12pt instead of the usual 11pt. This font size was a requirement for my thesis. The option a4paper sets DIN A4 paper (which should be the default anyway). The option headsepline adds a line below the header content on pages without a title.

A useful additional option may be oneside, which creates symmetric margins for one-sided print. Again, that was a requirement for the manuscript of my thesis. For the final print, I needed a normal two-sided print. A useful option there is titlepage=firstiscover, which gives equal margins for the first two pages (the book cover).

Usually you don’t want to tamper with the margins that LaTeX gives you. But in some cases, you may have specific guidelines that you need to adhere to. Or you have a fixed number of pages and run out of space, so you want smaller margins. Anyway, this is not recommended, I am just showing you how it works, because I can.

We have loaded the documentclass scrbook which is the KOMA-Script document class for an DIN A4 page book with a font size of 12pt. At that paper and font size, KOMA-Script uses a value of DIV=12 to calculate margins and text area sizes. The page has a width of 157.50mm and a height of 222.75mm for the text area. The top margin is 24.75mm and the inner margin 17.50mm. You can increase or decrease the margins by setting a different DIV value. So if you use the option DIV=13 for example, you will have a bigger text area (161mm wide instead of only 157mm). You can play around with the values until you find something you like. Here are the measurements for different DIV values for an DIN A4 page:

If you don’t find anything you like, you can set all values by hand with the geometry package. Use at your own peril. This is an example with a larger text height:

One of my “customers” wanted a book that didn’t look so “sciency” (i.e., like LaTeX). In addition to the look of the chapter and sections headings (described in my last post), my “customers” wanted the table-of-contents to also look “non-sciency”. So this is what I did.

The package to use for manipulations of the table-of-contents is titletoc:

\usepackage{titletoc}

The entry for a chapter specifies that chapters are prefaced with the chapter label (which is “Teil X” in our case) and otherwise pretty standard:

One of my “customers” wanted a book that didn’t look so “sciency” (i.e., less like LaTeX). The first few tweaks (described in my last post) were more general, this one deals with the look of chapter and section headings.

I use the package titlesec for the task:

\usepackage{titlesec}

Each chapter should start on its own page. On top it will say “Teil X”, then a line, then the chapter name centered. At the bottom of the page a picture is included. This is the code for it:

\titlespacing{\section}{0pt}{1ex}{0pt} % less space for sections
\titlespacing{\subsection}{0pt}{0pt}{0pt} % subsection is like a paragraph

In a previous version of the book, the images were supposed to be placed next to the section headings. My attempt at doing that was to include the image in the “after-code” of the section format and add a bit of space at the right margin for it. It looked ok, but there were some issues with one-line vs. multi-line titles that I didn’t fix, because the images moved to the chapters instead.

I want an environment for example sentences where sentences are numbered and can be referenced. This is common in publications in the area of linguistics and there are a few packages that do the trick. But here is my own.

First, we need a counter that provides the number for the sentence:

\newcounter{mySentence}

We reset sentence counter for each chapter:

\@addtoreset{mySentence}{chapter}

We print the sentence number as (chapter.sentence):

\renewcommand*{\themySentence}{(\thechapter.\arabic{mySentence})}

Then we define an environment for one example sentence, where the number will be printed in the beginning of the line and then the sentence follows: