4

Which font or fonts should be used while writing code lines inside a book?

I'm especially dealing with C code, but I'd also like to know what fonts are used for the codes of popular programming languages in books.

Ryan Gates
  • 4,442
  • 5
  • 49
  • 87
Mehper C. Palavuzlar
  • 9,619
  • 21
  • 55
  • 68

3 Answers3

3

Any good fixed-width legible font will do. Courier shows up a lot as many people use it in IDEs on the desktop and tends to be the default style for the <code> tag in HTML.

I tend to use Consolas in IDEs when I can and that might also be a good choice for a book.

If you have a particular book in mind then it is worth checking the near the back cover for a colophon which may detail the fonts.

I happen to have "POSIX Programmer's Guide" in front of me and the colophon says that it uses ITC Garamond for the main text and Courier for the code examples.

Linked: You may also want to read Recommended Fonts for Programming?

Community
  • 1
  • 1
GrahamS
  • 9,505
  • 8
  • 47
  • 61
  • The question asks for a *book* font, so arguing that *any* fixed-width font fits well in a book is definitely wrong. For example, Consolas has *a lot* of contrast and, AFAIK, you cannot get opticals for it. – Dmitri Nesteruk May 01 '12 at 18:33
  • @Dmitri Wow, you downvoted me for that? Tough crowd! *Courier* is used in most of the programming books I have, so I'm pretty sure it has suitable "opticals and contrast", whatever they are (I'm a programmer not a typography expert). I mentioned *Consolas* because its popularity means that for many it is the modern Courier. I'm sure there are many close equivalents to it with suitable "opticals". – GrahamS May 04 '12 at 10:29
1

I think if you can read it, it should be a good font. Maybe have a mix of fonts like a times new roman or arial for general explanations but when showing actual code put a sans serif font with the code indented or separated from the rest. If it is a different font from the rest of the it should be easy to see. Also I would not suggest anything too italicized or cursive. just think about what you enjoy reading and how it looks,

EDIT

also you can look here for different programming fonts. or use a search engine to find good readable font. Normally anything with sans serif is a good choice because it doesn't detract the eyes too much from the code.

Justin Gregoire
  • 2,598
  • 1
  • 19
  • 9
0

Use same font as most would on screen and IDE

Usually that's monospace, sans-serif, with legible 1/l/I and O/0.

Plus points for good bold (keywords), italic (comments), embedded bitmaps and scalable version that looks similar to small sizes.

If it's a printed book you want a font that scales, not a bitmap.

If it's online in html, you want something browsers already have.

Please don't use anything fancy, and never ever ever serifs!

DIma Q
  • 21
  • 1