What font to use for source code in a document?

Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I'm currently writing some text where I discuss a python script.
So naturally, there's a lot of code in the document and it seems like listings is the default way to do so.
However, unlike what I'm used to when using latex, the default looks atrocious!
Non-monospaced source code!? WTF? (side question: or is there really a typographic "rule" for this?)
OK, I can fix that after a quick read of the docs with ttfamily.

But this is still very weird, mostly the italic part for the comments. It just looks totally off to me.
Is this because I just happen to be used to weird fonts in my editors (Monospace Regular, not too weird, I'd guess) and this is normal and typographically sound, or is there a better option?
And if so, what would that option be? I'd rather not use some random font that I, personally, like but that is objectively bad, especially in combination with my default fonts for the text (all from Komas scrbook).
MWE:
documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
lstsetlanguage=Python, numbers=left, numberstyle=tiny, stepnumber=1, numbersep=5pt, tabsize=4%, basicstyle=ttfamily}
begindocument
This is some other text.
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument
fonts code lstlisting
add a comment |Â
up vote
2
down vote
favorite
I'm currently writing some text where I discuss a python script.
So naturally, there's a lot of code in the document and it seems like listings is the default way to do so.
However, unlike what I'm used to when using latex, the default looks atrocious!
Non-monospaced source code!? WTF? (side question: or is there really a typographic "rule" for this?)
OK, I can fix that after a quick read of the docs with ttfamily.

But this is still very weird, mostly the italic part for the comments. It just looks totally off to me.
Is this because I just happen to be used to weird fonts in my editors (Monospace Regular, not too weird, I'd guess) and this is normal and typographically sound, or is there a better option?
And if so, what would that option be? I'd rather not use some random font that I, personally, like but that is objectively bad, especially in combination with my default fonts for the text (all from Komas scrbook).
MWE:
documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
lstsetlanguage=Python, numbers=left, numberstyle=tiny, stepnumber=1, numbersep=5pt, tabsize=4%, basicstyle=ttfamily}
begindocument
This is some other text.
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument
fonts code lstlisting
You probably want to addcolumns=fullflexible, keepspaces=true,into yourlstset...
â Thruston
1 hour ago
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm currently writing some text where I discuss a python script.
So naturally, there's a lot of code in the document and it seems like listings is the default way to do so.
However, unlike what I'm used to when using latex, the default looks atrocious!
Non-monospaced source code!? WTF? (side question: or is there really a typographic "rule" for this?)
OK, I can fix that after a quick read of the docs with ttfamily.

But this is still very weird, mostly the italic part for the comments. It just looks totally off to me.
Is this because I just happen to be used to weird fonts in my editors (Monospace Regular, not too weird, I'd guess) and this is normal and typographically sound, or is there a better option?
And if so, what would that option be? I'd rather not use some random font that I, personally, like but that is objectively bad, especially in combination with my default fonts for the text (all from Komas scrbook).
MWE:
documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
lstsetlanguage=Python, numbers=left, numberstyle=tiny, stepnumber=1, numbersep=5pt, tabsize=4%, basicstyle=ttfamily}
begindocument
This is some other text.
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument
fonts code lstlisting
I'm currently writing some text where I discuss a python script.
So naturally, there's a lot of code in the document and it seems like listings is the default way to do so.
However, unlike what I'm used to when using latex, the default looks atrocious!
Non-monospaced source code!? WTF? (side question: or is there really a typographic "rule" for this?)
OK, I can fix that after a quick read of the docs with ttfamily.

But this is still very weird, mostly the italic part for the comments. It just looks totally off to me.
Is this because I just happen to be used to weird fonts in my editors (Monospace Regular, not too weird, I'd guess) and this is normal and typographically sound, or is there a better option?
And if so, what would that option be? I'd rather not use some random font that I, personally, like but that is objectively bad, especially in combination with my default fonts for the text (all from Komas scrbook).
MWE:
documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
lstsetlanguage=Python, numbers=left, numberstyle=tiny, stepnumber=1, numbersep=5pt, tabsize=4%, basicstyle=ttfamily}
begindocument
This is some other text.
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument
fonts code lstlisting
fonts code lstlisting
edited 19 mins ago
asked 1 hour ago
JC_CL
128115
128115
You probably want to addcolumns=fullflexible, keepspaces=true,into yourlstset...
â Thruston
1 hour ago
add a comment |Â
You probably want to addcolumns=fullflexible, keepspaces=true,into yourlstset...
â Thruston
1 hour ago
You probably want to add
columns=fullflexible, keepspaces=true, into your lstset...â Thruston
1 hour ago
You probably want to add
columns=fullflexible, keepspaces=true, into your lstset...â Thruston
1 hour ago
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
4
down vote
In my opinion the defaults in lstlisting are very odd, but it's not hard to tame them. Here is your example with a few extra keys and some colour.

documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagexcolor
definecolortextbluergb.2,.2,.7
definecolortextredrgb0.54,0,0
definecolortextgreenrgb0,0.43,0
usepackagelistings
lstsetlanguage=Python,
numbers=left,
numberstyle=tiny,
stepnumber=1,
numbersep=5pt,
tabsize=4,
basicstyle=ttfamily,
keywordstyle=colortextblue,
commentstyle=colortextred,
stringstyle=colortextgreen,
frame=none,
columns=fullflexible,
keepspaces=true,
xleftmargin=parindent,
showstringspaces=false
begindocument
This is some other text.
beginlstlisting
for i in list:
print i, "OK"
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument
If you wanted comments in italics, then you just add it to the commentstyle line:
...
commentstyle=colortextreditshape,
...
this produces:

For more details do texdoc listings...
If you don't like the look of the default ttfamily then try some different ones. You may also need to change the body font to match the monofont of course, the default fonts may not be quite what you want, but at least they go together well.
This is stillttfamilythough, so having the comments in italics would just result in the same weirdness? Which of the settings controls the italics (or lack thereof), it's not readily apparent from the code.
â JC_CL
1 hour ago
@JC_CL Add to the preamble the lineusepackagesourcecodepro, does this improve the result? OK, you need to have an installation including the Sourcecode Pro fonts.
â Keks Dose
45 mins ago
commentstyle=colortextreditshapeI see. was searching foritaliin the lstlisting docs and didn't find anything. The colors are all nice, but my main gripe is that italics look totally off, but (as per most editor defaults) comments should be in italics.usepackagesourcecodeprogives me an error, even though I installed the font, but this probably gets me into "how to mix and match fonts in a document?" hell, as does the linked question, something I'd have hoped to avoid.
â JC_CL
21 mins ago
add a comment |Â
up vote
2
down vote
It's not simply the serif font that makes the listing awful: it's mainly the font not being monospaced, so the characters look like being thrown on the page at random.
You might color the listing: good for screen reading, less good for printed paper.
Otherwise, you could look for different monospaced font (I don't like the italic default typewriter type too).
Here's a try with SourceCode Pro, just to see whether the result looks better.
documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
lstset
language=Python,
numbers=left,
numberstyle=tiny,
stepnumber=1,
numbersep=5pt,
tabsize=4,
basicstyle=ttfamily,
columns=fullflexible,
keepspaces,
begindocument
This is some other text.
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
This is some other text.
% roughly emulate usepackagesourcecodepro
lstset
basicstyle=fontfamilySourceCodePro-TLFselectfont
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument

OK, let's assume you like it. But it's definitely too big: we can fix it.
documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
usepackage[scale=0.85]sourcecodepro
lstset
language=Python,
numbers=left,
numberstyle=tiny,
stepnumber=1,
numbersep=5pt,
tabsize=4,
basicstyle=ttfamily,
columns=fullflexible,
keepspaces,
begindocument
This is some other text.
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument

There are several other monospaced fonts available, see the LaTeX font catalogue
I don't like the zero with a point inside, I find it unreadable.
â AndréC
6 mins ago
I on the other hand don't mind the dot⦠However, this font looks kinda off, compared to computer modern, and I'm no typographer that can judge if they fit. But it certainly is better than the atrocious italics in the default.
â JC_CL
just now
add a comment |Â
up vote
0
down vote
Personally, for listing, the fundamental criterion is that the 0 is different from the letter O.
For the inconsolata font is perfect.

documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
lstsetlanguage=Python, numbers=left, numberstyle=tiny, stepnumber=1, numbersep=5pt, tabsize=4, basicstyle=ttfamily
usepackageinconsolata
begindocument
This is some other text.
the 0 is not crossed out like the letter O
beginlstlisting
for i in list:
print i
# prints every entry in a list
# the 0 is crossed out unlike the letter O
endlstlisting
This here is also non, sourcecode text.
enddocument
1
0 vs. O is certainly important (and also not handled too well in the default), but it appears that inconsolata can't deal with italic comments. Also, I'm afraid that this the dreaded mixing of unmatching fonts.
â JC_CL
12 mins ago
@JC_CL Indeed, the inconsolata font has no italics.
â AndréC
8 mins ago
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
In my opinion the defaults in lstlisting are very odd, but it's not hard to tame them. Here is your example with a few extra keys and some colour.

documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagexcolor
definecolortextbluergb.2,.2,.7
definecolortextredrgb0.54,0,0
definecolortextgreenrgb0,0.43,0
usepackagelistings
lstsetlanguage=Python,
numbers=left,
numberstyle=tiny,
stepnumber=1,
numbersep=5pt,
tabsize=4,
basicstyle=ttfamily,
keywordstyle=colortextblue,
commentstyle=colortextred,
stringstyle=colortextgreen,
frame=none,
columns=fullflexible,
keepspaces=true,
xleftmargin=parindent,
showstringspaces=false
begindocument
This is some other text.
beginlstlisting
for i in list:
print i, "OK"
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument
If you wanted comments in italics, then you just add it to the commentstyle line:
...
commentstyle=colortextreditshape,
...
this produces:

For more details do texdoc listings...
If you don't like the look of the default ttfamily then try some different ones. You may also need to change the body font to match the monofont of course, the default fonts may not be quite what you want, but at least they go together well.
This is stillttfamilythough, so having the comments in italics would just result in the same weirdness? Which of the settings controls the italics (or lack thereof), it's not readily apparent from the code.
â JC_CL
1 hour ago
@JC_CL Add to the preamble the lineusepackagesourcecodepro, does this improve the result? OK, you need to have an installation including the Sourcecode Pro fonts.
â Keks Dose
45 mins ago
commentstyle=colortextreditshapeI see. was searching foritaliin the lstlisting docs and didn't find anything. The colors are all nice, but my main gripe is that italics look totally off, but (as per most editor defaults) comments should be in italics.usepackagesourcecodeprogives me an error, even though I installed the font, but this probably gets me into "how to mix and match fonts in a document?" hell, as does the linked question, something I'd have hoped to avoid.
â JC_CL
21 mins ago
add a comment |Â
up vote
4
down vote
In my opinion the defaults in lstlisting are very odd, but it's not hard to tame them. Here is your example with a few extra keys and some colour.

documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagexcolor
definecolortextbluergb.2,.2,.7
definecolortextredrgb0.54,0,0
definecolortextgreenrgb0,0.43,0
usepackagelistings
lstsetlanguage=Python,
numbers=left,
numberstyle=tiny,
stepnumber=1,
numbersep=5pt,
tabsize=4,
basicstyle=ttfamily,
keywordstyle=colortextblue,
commentstyle=colortextred,
stringstyle=colortextgreen,
frame=none,
columns=fullflexible,
keepspaces=true,
xleftmargin=parindent,
showstringspaces=false
begindocument
This is some other text.
beginlstlisting
for i in list:
print i, "OK"
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument
If you wanted comments in italics, then you just add it to the commentstyle line:
...
commentstyle=colortextreditshape,
...
this produces:

For more details do texdoc listings...
If you don't like the look of the default ttfamily then try some different ones. You may also need to change the body font to match the monofont of course, the default fonts may not be quite what you want, but at least they go together well.
This is stillttfamilythough, so having the comments in italics would just result in the same weirdness? Which of the settings controls the italics (or lack thereof), it's not readily apparent from the code.
â JC_CL
1 hour ago
@JC_CL Add to the preamble the lineusepackagesourcecodepro, does this improve the result? OK, you need to have an installation including the Sourcecode Pro fonts.
â Keks Dose
45 mins ago
commentstyle=colortextreditshapeI see. was searching foritaliin the lstlisting docs and didn't find anything. The colors are all nice, but my main gripe is that italics look totally off, but (as per most editor defaults) comments should be in italics.usepackagesourcecodeprogives me an error, even though I installed the font, but this probably gets me into "how to mix and match fonts in a document?" hell, as does the linked question, something I'd have hoped to avoid.
â JC_CL
21 mins ago
add a comment |Â
up vote
4
down vote
up vote
4
down vote
In my opinion the defaults in lstlisting are very odd, but it's not hard to tame them. Here is your example with a few extra keys and some colour.

documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagexcolor
definecolortextbluergb.2,.2,.7
definecolortextredrgb0.54,0,0
definecolortextgreenrgb0,0.43,0
usepackagelistings
lstsetlanguage=Python,
numbers=left,
numberstyle=tiny,
stepnumber=1,
numbersep=5pt,
tabsize=4,
basicstyle=ttfamily,
keywordstyle=colortextblue,
commentstyle=colortextred,
stringstyle=colortextgreen,
frame=none,
columns=fullflexible,
keepspaces=true,
xleftmargin=parindent,
showstringspaces=false
begindocument
This is some other text.
beginlstlisting
for i in list:
print i, "OK"
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument
If you wanted comments in italics, then you just add it to the commentstyle line:
...
commentstyle=colortextreditshape,
...
this produces:

For more details do texdoc listings...
If you don't like the look of the default ttfamily then try some different ones. You may also need to change the body font to match the monofont of course, the default fonts may not be quite what you want, but at least they go together well.
In my opinion the defaults in lstlisting are very odd, but it's not hard to tame them. Here is your example with a few extra keys and some colour.

documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagexcolor
definecolortextbluergb.2,.2,.7
definecolortextredrgb0.54,0,0
definecolortextgreenrgb0,0.43,0
usepackagelistings
lstsetlanguage=Python,
numbers=left,
numberstyle=tiny,
stepnumber=1,
numbersep=5pt,
tabsize=4,
basicstyle=ttfamily,
keywordstyle=colortextblue,
commentstyle=colortextred,
stringstyle=colortextgreen,
frame=none,
columns=fullflexible,
keepspaces=true,
xleftmargin=parindent,
showstringspaces=false
begindocument
This is some other text.
beginlstlisting
for i in list:
print i, "OK"
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument
If you wanted comments in italics, then you just add it to the commentstyle line:
...
commentstyle=colortextreditshape,
...
this produces:

For more details do texdoc listings...
If you don't like the look of the default ttfamily then try some different ones. You may also need to change the body font to match the monofont of course, the default fonts may not be quite what you want, but at least they go together well.
edited 32 mins ago
answered 1 hour ago
Thruston
24.8k23988
24.8k23988
This is stillttfamilythough, so having the comments in italics would just result in the same weirdness? Which of the settings controls the italics (or lack thereof), it's not readily apparent from the code.
â JC_CL
1 hour ago
@JC_CL Add to the preamble the lineusepackagesourcecodepro, does this improve the result? OK, you need to have an installation including the Sourcecode Pro fonts.
â Keks Dose
45 mins ago
commentstyle=colortextreditshapeI see. was searching foritaliin the lstlisting docs and didn't find anything. The colors are all nice, but my main gripe is that italics look totally off, but (as per most editor defaults) comments should be in italics.usepackagesourcecodeprogives me an error, even though I installed the font, but this probably gets me into "how to mix and match fonts in a document?" hell, as does the linked question, something I'd have hoped to avoid.
â JC_CL
21 mins ago
add a comment |Â
This is stillttfamilythough, so having the comments in italics would just result in the same weirdness? Which of the settings controls the italics (or lack thereof), it's not readily apparent from the code.
â JC_CL
1 hour ago
@JC_CL Add to the preamble the lineusepackagesourcecodepro, does this improve the result? OK, you need to have an installation including the Sourcecode Pro fonts.
â Keks Dose
45 mins ago
commentstyle=colortextreditshapeI see. was searching foritaliin the lstlisting docs and didn't find anything. The colors are all nice, but my main gripe is that italics look totally off, but (as per most editor defaults) comments should be in italics.usepackagesourcecodeprogives me an error, even though I installed the font, but this probably gets me into "how to mix and match fonts in a document?" hell, as does the linked question, something I'd have hoped to avoid.
â JC_CL
21 mins ago
This is still
ttfamily though, so having the comments in italics would just result in the same weirdness? Which of the settings controls the italics (or lack thereof), it's not readily apparent from the code.â JC_CL
1 hour ago
This is still
ttfamily though, so having the comments in italics would just result in the same weirdness? Which of the settings controls the italics (or lack thereof), it's not readily apparent from the code.â JC_CL
1 hour ago
@JC_CL Add to the preamble the line
usepackagesourcecodepro, does this improve the result? OK, you need to have an installation including the Sourcecode Pro fonts.â Keks Dose
45 mins ago
@JC_CL Add to the preamble the line
usepackagesourcecodepro, does this improve the result? OK, you need to have an installation including the Sourcecode Pro fonts.â Keks Dose
45 mins ago
commentstyle=colortextreditshape I see. was searching for itali in the lstlisting docs and didn't find anything. The colors are all nice, but my main gripe is that italics look totally off, but (as per most editor defaults) comments should be in italics. usepackagesourcecodepro gives me an error, even though I installed the font, but this probably gets me into "how to mix and match fonts in a document?" hell, as does the linked question, something I'd have hoped to avoid.â JC_CL
21 mins ago
commentstyle=colortextreditshape I see. was searching for itali in the lstlisting docs and didn't find anything. The colors are all nice, but my main gripe is that italics look totally off, but (as per most editor defaults) comments should be in italics. usepackagesourcecodepro gives me an error, even though I installed the font, but this probably gets me into "how to mix and match fonts in a document?" hell, as does the linked question, something I'd have hoped to avoid.â JC_CL
21 mins ago
add a comment |Â
up vote
2
down vote
It's not simply the serif font that makes the listing awful: it's mainly the font not being monospaced, so the characters look like being thrown on the page at random.
You might color the listing: good for screen reading, less good for printed paper.
Otherwise, you could look for different monospaced font (I don't like the italic default typewriter type too).
Here's a try with SourceCode Pro, just to see whether the result looks better.
documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
lstset
language=Python,
numbers=left,
numberstyle=tiny,
stepnumber=1,
numbersep=5pt,
tabsize=4,
basicstyle=ttfamily,
columns=fullflexible,
keepspaces,
begindocument
This is some other text.
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
This is some other text.
% roughly emulate usepackagesourcecodepro
lstset
basicstyle=fontfamilySourceCodePro-TLFselectfont
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument

OK, let's assume you like it. But it's definitely too big: we can fix it.
documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
usepackage[scale=0.85]sourcecodepro
lstset
language=Python,
numbers=left,
numberstyle=tiny,
stepnumber=1,
numbersep=5pt,
tabsize=4,
basicstyle=ttfamily,
columns=fullflexible,
keepspaces,
begindocument
This is some other text.
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument

There are several other monospaced fonts available, see the LaTeX font catalogue
I don't like the zero with a point inside, I find it unreadable.
â AndréC
6 mins ago
I on the other hand don't mind the dot⦠However, this font looks kinda off, compared to computer modern, and I'm no typographer that can judge if they fit. But it certainly is better than the atrocious italics in the default.
â JC_CL
just now
add a comment |Â
up vote
2
down vote
It's not simply the serif font that makes the listing awful: it's mainly the font not being monospaced, so the characters look like being thrown on the page at random.
You might color the listing: good for screen reading, less good for printed paper.
Otherwise, you could look for different monospaced font (I don't like the italic default typewriter type too).
Here's a try with SourceCode Pro, just to see whether the result looks better.
documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
lstset
language=Python,
numbers=left,
numberstyle=tiny,
stepnumber=1,
numbersep=5pt,
tabsize=4,
basicstyle=ttfamily,
columns=fullflexible,
keepspaces,
begindocument
This is some other text.
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
This is some other text.
% roughly emulate usepackagesourcecodepro
lstset
basicstyle=fontfamilySourceCodePro-TLFselectfont
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument

OK, let's assume you like it. But it's definitely too big: we can fix it.
documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
usepackage[scale=0.85]sourcecodepro
lstset
language=Python,
numbers=left,
numberstyle=tiny,
stepnumber=1,
numbersep=5pt,
tabsize=4,
basicstyle=ttfamily,
columns=fullflexible,
keepspaces,
begindocument
This is some other text.
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument

There are several other monospaced fonts available, see the LaTeX font catalogue
I don't like the zero with a point inside, I find it unreadable.
â AndréC
6 mins ago
I on the other hand don't mind the dot⦠However, this font looks kinda off, compared to computer modern, and I'm no typographer that can judge if they fit. But it certainly is better than the atrocious italics in the default.
â JC_CL
just now
add a comment |Â
up vote
2
down vote
up vote
2
down vote
It's not simply the serif font that makes the listing awful: it's mainly the font not being monospaced, so the characters look like being thrown on the page at random.
You might color the listing: good for screen reading, less good for printed paper.
Otherwise, you could look for different monospaced font (I don't like the italic default typewriter type too).
Here's a try with SourceCode Pro, just to see whether the result looks better.
documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
lstset
language=Python,
numbers=left,
numberstyle=tiny,
stepnumber=1,
numbersep=5pt,
tabsize=4,
basicstyle=ttfamily,
columns=fullflexible,
keepspaces,
begindocument
This is some other text.
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
This is some other text.
% roughly emulate usepackagesourcecodepro
lstset
basicstyle=fontfamilySourceCodePro-TLFselectfont
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument

OK, let's assume you like it. But it's definitely too big: we can fix it.
documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
usepackage[scale=0.85]sourcecodepro
lstset
language=Python,
numbers=left,
numberstyle=tiny,
stepnumber=1,
numbersep=5pt,
tabsize=4,
basicstyle=ttfamily,
columns=fullflexible,
keepspaces,
begindocument
This is some other text.
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument

There are several other monospaced fonts available, see the LaTeX font catalogue
It's not simply the serif font that makes the listing awful: it's mainly the font not being monospaced, so the characters look like being thrown on the page at random.
You might color the listing: good for screen reading, less good for printed paper.
Otherwise, you could look for different monospaced font (I don't like the italic default typewriter type too).
Here's a try with SourceCode Pro, just to see whether the result looks better.
documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
lstset
language=Python,
numbers=left,
numberstyle=tiny,
stepnumber=1,
numbersep=5pt,
tabsize=4,
basicstyle=ttfamily,
columns=fullflexible,
keepspaces,
begindocument
This is some other text.
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
This is some other text.
% roughly emulate usepackagesourcecodepro
lstset
basicstyle=fontfamilySourceCodePro-TLFselectfont
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument

OK, let's assume you like it. But it's definitely too big: we can fix it.
documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
usepackage[scale=0.85]sourcecodepro
lstset
language=Python,
numbers=left,
numberstyle=tiny,
stepnumber=1,
numbersep=5pt,
tabsize=4,
basicstyle=ttfamily,
columns=fullflexible,
keepspaces,
begindocument
This is some other text.
beginlstlisting
for i in list:
print i
# prints every entry in a list
endlstlisting
This here is also non, sourcecode text.
enddocument

There are several other monospaced fonts available, see the LaTeX font catalogue
answered 15 mins ago
egreg
688k8418323080
688k8418323080
I don't like the zero with a point inside, I find it unreadable.
â AndréC
6 mins ago
I on the other hand don't mind the dot⦠However, this font looks kinda off, compared to computer modern, and I'm no typographer that can judge if they fit. But it certainly is better than the atrocious italics in the default.
â JC_CL
just now
add a comment |Â
I don't like the zero with a point inside, I find it unreadable.
â AndréC
6 mins ago
I on the other hand don't mind the dot⦠However, this font looks kinda off, compared to computer modern, and I'm no typographer that can judge if they fit. But it certainly is better than the atrocious italics in the default.
â JC_CL
just now
I don't like the zero with a point inside, I find it unreadable.
â AndréC
6 mins ago
I don't like the zero with a point inside, I find it unreadable.
â AndréC
6 mins ago
I on the other hand don't mind the dot⦠However, this font looks kinda off, compared to computer modern, and I'm no typographer that can judge if they fit. But it certainly is better than the atrocious italics in the default.
â JC_CL
just now
I on the other hand don't mind the dot⦠However, this font looks kinda off, compared to computer modern, and I'm no typographer that can judge if they fit. But it certainly is better than the atrocious italics in the default.
â JC_CL
just now
add a comment |Â
up vote
0
down vote
Personally, for listing, the fundamental criterion is that the 0 is different from the letter O.
For the inconsolata font is perfect.

documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
lstsetlanguage=Python, numbers=left, numberstyle=tiny, stepnumber=1, numbersep=5pt, tabsize=4, basicstyle=ttfamily
usepackageinconsolata
begindocument
This is some other text.
the 0 is not crossed out like the letter O
beginlstlisting
for i in list:
print i
# prints every entry in a list
# the 0 is crossed out unlike the letter O
endlstlisting
This here is also non, sourcecode text.
enddocument
1
0 vs. O is certainly important (and also not handled too well in the default), but it appears that inconsolata can't deal with italic comments. Also, I'm afraid that this the dreaded mixing of unmatching fonts.
â JC_CL
12 mins ago
@JC_CL Indeed, the inconsolata font has no italics.
â AndréC
8 mins ago
add a comment |Â
up vote
0
down vote
Personally, for listing, the fundamental criterion is that the 0 is different from the letter O.
For the inconsolata font is perfect.

documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
lstsetlanguage=Python, numbers=left, numberstyle=tiny, stepnumber=1, numbersep=5pt, tabsize=4, basicstyle=ttfamily
usepackageinconsolata
begindocument
This is some other text.
the 0 is not crossed out like the letter O
beginlstlisting
for i in list:
print i
# prints every entry in a list
# the 0 is crossed out unlike the letter O
endlstlisting
This here is also non, sourcecode text.
enddocument
1
0 vs. O is certainly important (and also not handled too well in the default), but it appears that inconsolata can't deal with italic comments. Also, I'm afraid that this the dreaded mixing of unmatching fonts.
â JC_CL
12 mins ago
@JC_CL Indeed, the inconsolata font has no italics.
â AndréC
8 mins ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Personally, for listing, the fundamental criterion is that the 0 is different from the letter O.
For the inconsolata font is perfect.

documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
lstsetlanguage=Python, numbers=left, numberstyle=tiny, stepnumber=1, numbersep=5pt, tabsize=4, basicstyle=ttfamily
usepackageinconsolata
begindocument
This is some other text.
the 0 is not crossed out like the letter O
beginlstlisting
for i in list:
print i
# prints every entry in a list
# the 0 is crossed out unlike the letter O
endlstlisting
This here is also non, sourcecode text.
enddocument
Personally, for listing, the fundamental criterion is that the 0 is different from the letter O.
For the inconsolata font is perfect.

documentclass[a4paper,11pt, headings=normal, toc=bibliography, toc=listof]scrbook
usepackage[T1]fontenc
usepackage[utf8]inputenc
usepackagelistings
lstsetlanguage=Python, numbers=left, numberstyle=tiny, stepnumber=1, numbersep=5pt, tabsize=4, basicstyle=ttfamily
usepackageinconsolata
begindocument
This is some other text.
the 0 is not crossed out like the letter O
beginlstlisting
for i in list:
print i
# prints every entry in a list
# the 0 is crossed out unlike the letter O
endlstlisting
This here is also non, sourcecode text.
enddocument
edited 11 mins ago
answered 20 mins ago
AndréC
3,526729
3,526729
1
0 vs. O is certainly important (and also not handled too well in the default), but it appears that inconsolata can't deal with italic comments. Also, I'm afraid that this the dreaded mixing of unmatching fonts.
â JC_CL
12 mins ago
@JC_CL Indeed, the inconsolata font has no italics.
â AndréC
8 mins ago
add a comment |Â
1
0 vs. O is certainly important (and also not handled too well in the default), but it appears that inconsolata can't deal with italic comments. Also, I'm afraid that this the dreaded mixing of unmatching fonts.
â JC_CL
12 mins ago
@JC_CL Indeed, the inconsolata font has no italics.
â AndréC
8 mins ago
1
1
0 vs. O is certainly important (and also not handled too well in the default), but it appears that inconsolata can't deal with italic comments. Also, I'm afraid that this the dreaded mixing of unmatching fonts.
â JC_CL
12 mins ago
0 vs. O is certainly important (and also not handled too well in the default), but it appears that inconsolata can't deal with italic comments. Also, I'm afraid that this the dreaded mixing of unmatching fonts.
â JC_CL
12 mins ago
@JC_CL Indeed, the inconsolata font has no italics.
â AndréC
8 mins ago
@JC_CL Indeed, the inconsolata font has no italics.
â AndréC
8 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f454492%2fwhat-font-to-use-for-source-code-in-a-document%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password

You probably want to add
columns=fullflexible, keepspaces=true,into yourlstset...â Thruston
1 hour ago