Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font for programming source code with LaTeX

Tags:

latex

listings

Listing style is normally used for source code listing, but to me the default font used is not so pretty for source code listing. Attached is a comparison between listing and verbatim.

http://img27.imageshack.us/img27/8906/screenshot20100717at115.png

  • How can I use the font for verbatim when I use listing environment?
  • What would be a good font for source code listing?
like image 340
prosseek Avatar asked Jul 18 '10 05:07

prosseek


People also ask

What font size does LaTeX use?

The default font size for Latex is 10pt.

How do I use Cambria font in LaTeX?

If you are free to use LuaLaTeX or XeLaTeX, and if fonts named Verdana and Cambria are installed on your computer system, all you need to do is load the fontspec package, issue a suitable \setmainfont directive, and issue two \newfontfamily directives to specify how to make the text font switch over to Cambria and ...


2 Answers

I agree the defaults of listings aren't that appealing. Usually I write something like

\lstset{columns=fullflexible,basicstyle=\ttfamily}

You might also need to play around with the identifierstyle, commentstyle, etc., keys if the style for your code uses these separately.

The columns=fullflexible keyval suppresses listings's layout thing that it does to make proportional-width text fit into a monospace grid; it's not necessary if you choose a monospace font to begin with.

like image 111
Will Robertson Avatar answered Nov 13 '22 13:11

Will Robertson


Did you try \texttt? It's the teletypefont family, a fixed-width font. It should look better.

like image 36
Vitor Py Avatar answered Nov 13 '22 11:11

Vitor Py