Wednesday, 25 June 2008

LaTeX, monospace, bold, computer modern, bera

This isn't exactly "general interest", but if any other person trying to format their thesis has hit the same issue, it's useful to have this up there for Google to pick it up:

I've just been reformatting my PhD thesis (approved and graduated last year) as a technical report for the Computer Laboratory.  It's formatted in LaTeX, which is the typesetting system lots of computer science graduate students still use rather than stretchy rubber. If you use the Times font package, you might find that its monospaced font (something a bit like Courier) is rather wide, and looks very odd if you put a keyword in monospace in the middle of some Times prose.  The Computer Modern monospace font is a much less clashing size, much narrower than the other monospaced fonts I could find, and so that's what I used in my PhD when I printed it for submission.  Only it doesn't have a bold.  There's a trick on the Internet to put a bold monospace (typewriter) Computer Modern font in – but it's only good for print documents because it ends up being a bitmap font (looks blurry in most PDF viewers when viewed at the wrong size on the screen).  So, no good for the PDF technical report.

After some hunting around – Latin Modern is very similar to Computer Modern and does have a bold typewriter font – but not a bold italic monospace font – so bold italic ends up looking odd compared to not-bold italic.

After more searching around, a solution.  The Bera (Bitstream Vera) package has a small note in its documentation, in a file called bera.txt, saying: 
\usepackage[scaled]{...}    selects a default scaling of 90%, which makes the Bera fonts approximately match the size of the Computer Modern fonts.

(Actually I find scaled=0.88 fits better with surrounding Times text)

In otherwords, if you do \usepackage[scaled]{beramono} you'll have a monospace font that doesn't jar quite so much with surrounding Times text, and does have bold and bold italics, etc.

Oh, theres also a note saying Bera only works with T1 encoding, so you need:
as well (I put it before the \usepackage[scaled=0.88]{beramono}.


Anonymous said...

the package luximono will solve the problem in a similar way.

The Latex Companion remarks that one can achieve exactly the same running length with LuxiMono and Computer Modern typewriter with the scaling factors 0.87478 (10pt font) and 0.86124 (11pt font).

Ted said...

According to this site, the pslatex package is a version of times with a narrower monospaced font.

louic said...

Thanks for sharing the information! This is exactly what I was looking for in my thesis. :)