Some notes on fonts
Recently I’ve discovered some fun new things about fonts, in LaTeX and under linux. (Yes, it’s another geek-out post. Sorry mum.) All this stuff can be found online (that’s where I found it), but it’s a bit scattered around. And I can’t remember where any of it is.
Summary:
- XeTeX gives LaTeX access to non-TeX-installed fonts, and
fontspec
makes it easy. - XeTeX also lets you write in unicode;
biblatex
will play nicely if you usebiber
instead ofbibtex
as the backend. fc-list
lists installed fonts (giving the names that XeTeX needs).fontforge
will display every glyph in the font, nice and big (and you can print the result).fontmatrix
has a very slick interface for font-browsing, from “tag-this-font” to “inspect-this-glyph”.- All of these except
biblatex
andbiber
(which are still in beta) are packaged for various Linux flavours;biblatex
installation is easy, forbiber
I vaguely recall that I installed via CPAN, which is rather a pain. There may be easier alternatives by now though.
XeTeX lets you use all your fonts in LaTeX
XeTeX is a TeX replacement; you compile your document with xelatex
if you’ve been using pdflatex
, and nothing much changes apart from that. But behind the scenes quite a lot happens; among other things, you get to use the fontspec
package, which works with the font names that the rest of your Linux system knows about. (Another, less positive, feature of the move is that you XeTeX is incompatible with microtype
. Can’t have everything…)
\documentclass{article} \usepackage{fontspec} \usepackage{xunicode} \usepackage{xltxtra} \setmainfont[Mapping=tex-text]{Verdana} |
If you pick a font with italic and bold alternatives, \textit{}
and \textbf{}
and so on will just work. Just like that. Which is nice.
If your font has Greek and Russian characters (Greek text characters, not a math alphabet), you can just type ’em:
Lorem ipsem and so forth; ο ξυπόλητος πρίγκιπας; зону большого над, языке а; italic: \textit{in Latin και στα Ελληνικά}, |
Which is nice.
(I don’t know what the Russian says, nor do I remember where I got it. The Greek says “The barefoot prince” and “and in Greek”.)
That Mapping=tex-text
says that XeTeX should recognise the old LaTeX style for quotes, long dashes, and so on. But you don’t have to use it: you can type them directly as unicode characters (which is nice).
When he goes---``Hello World!''\\
She replies—“Hello dear!”
|
And if the font you’re using has fun OpenType features (and that’s the whole point, right?), you can access them easily too:
\fontspec[Ligatures={Common, Rare}]{Impact} \fontsize{12pt}{18pt}\selectfont Questo è strano assai! \fontspec[Numbers={OldStyle}]{Impact}Old style: 1234567\\ \fontspec[Numbers={Lining}]{Impact}Lining: 1234567 |
See the fontspec
documentation for much, much more. (If your pdf seems to have half its text missing, there’s something wrong with your pdf rendering library. I don’t remember what I did to fix this though; possibly just updated, or possibly changed to a different pdf viewer.)
biblatex
with biber
can handle unicode bibliographies
So part of the reason I was originally playing around with all this was to help Olga write documents mixing Greek and Latin characters, with both Greek and Latin in the bibliography, with a minimum of hassle. It turns out that bibtex
doesn’t like unicode, in particular it doesn’t know what to do with Greek. But biber
, which is being developed as a backend for the biblatex
package, is designed for unicode from the ground up. Both biber
and biblatex
are beta release software and there are still a few kinks to iron out, but they can already do a lot.
List installed fonts with fc-list
If you’re anything like me, the first thing you’re going to want to do once you see how XeTeX and fontspec
work is try out lots of fonts to see what you’ve got installed that you could use.
If you just want to know names, fc-list
is your friend. Be prepared for a lot of output though…
Here’s a handy trick: use the pgffor
package (part of the fantastic graphics package pgf
) and you don’t have to constantly retype Lorem ipsem:
\usepackage{pgffor} ... \foreach \f in { Droid Serif, Alfios, Alexander, Dustismo ... URW Bookman L% }{ \noindent\setmainfont{\f}\f: Lorem ipsem and so forth. \par\medskip } |
Viewing fonts (and individual glyphs) with fontforge
and fontmatrix
Somewhere along the line I picked up a free font with heaps of fleurons, and a font of 300 ampersands each by a different designer (yeah, a gimmick, but the proceeds went to charity). For both of these, I wanted a way to see all the glyphs the font contains, large enough to appreciate them as individual characters, and also with the codepoint information so I know how to get access to whichever one I might want to use.
The internet was silent on how to achieve this (or my google-fu was weak), until JanekZ helped me out on typophile. It seems fontforge
is the only way to get a conveniently-formatted listing of every glyph the font contains (“Encoding » Compact”); it can generate a pdf for printing but the pdf doesn’t contain codepoint information. But for simply browsing, fontmatrix
is a thing of beauty. Unfortunately it seems to be buggy: “print” doesn’t produce any output, and “view all mapped glyphs” refuses to scroll. But the stuff that works works beautifully.
Comments
Fontwise I like to play around --- "need" isn't the issue ^_^
Bibtex and unicode: my understanding is that bibtex assumes single-byte encodings (Philipp Lehman explains on comp.text.tex).
The nasty bit is that you can't tell that bibtex is doing anything wrong in the vast majority of cases: if you're just moving around strings it doesn't matter if it has the right idea or the wrong idea about their internals. The error only shows up (afaik) if the bibtex style counts characters. (Of course I prefer a style that happens to do this.)
On the upside, this means that if it's working for you there's no need to change. And for Polish and I guess Norwegian there is always the fallback to (La)TeX macros for the occasional non-ascii characters (only needed in the bibliography, and only in fields that the style will chop out characters from). For Greek that's not an option.
Oh, another thing that is likely to go wrong is bibtex-driven case changes.
quite neat, I didn't know about xetex. otoh I never needed any fonts other than those supplied by texlive, but if I ever need them it's nice to know how to use them.
now about unicode: I'm actually using latex-ucs package and it works fine, also for bibtex. perhaps it doesn't work for Greek for some reason, but it sure does work for Polish and Norwegian.