↑↑ Home ↑ TeX tricks

## Favourite LaTeX hacks

### Changing the format of page headers

LaTeX calls the control sequence "\MakeUppercase" to prepare the text printed into the top line of the page. It usually puts the text into upper case, which is bad if the section heading printed there is long. Even though it is possible to redefine the page headline, there seems to be no way to obtain the name of the current chapter and section heading. It seems to be available only to LaTeX's own headline macro. The only way to put the chapter/section heading into the headline in a different style seems to be to redefine \MakeUppercase, for instance to typeset it in italics:

\def\MakeUppercase#1{{\it #1}}


\def\bfseries{\fontseries \bfdefault \selectfont \boldmath}

This somewhat changes the behaviour of \bfseries, but only if you use it together with math mode. This redefinition resembles the original one (which cannot easily be listed because it is contained in a macro called "\bfseries ", including the space; see here how to do it) except for the \boldmath command which sets all following maths symbols in bold face. (I also left out some error handling compared with the original definition.)

### Font sizes and line spacings

By reverse-engineering LaTeX's pre-defined font-size command sequences, one can define a macro that allows arbitrary font sizes and line distances. LaTeX normally automatically adapts the line spacing to the font size. This can lead to disproportionately large line distances, for instance in the slides style.

The following macro sets the font size and the line spacing separately.

\def\setsize{\csname @setfontsize\endcsname \setsize}

Its usage is like this:
\setsize{18}{24}

This sets the font size to 18 pt and the line spacing to 24 pt. If a different unit is to be used, it must be given explicitly, eg 12 mm. The line spacing can be a glue rather than a fixed lenght; by putting "plus ..pt" and/or "minus ..pt" after the (natural) length, you can define the amount by which it can be stretched or shrunk. Here the dots stand for the number of points of the stretch/shrink components (other units may also be used).

Since creating the \setsize macro, I have learnt that there is a LaTeX command, \fontsize, which does the same thing. As \setsize, it is followed by the font size and the line spacing in curly braces. It has to be followed by the command \selectfont to take effect. German-speakers can find here a nice slide show about font selection in LaTeX (internet archive copy; the original has apparently been removed.

TOS / Impressum