What font to use for source code in a document?

The name of the pictureThe name of the pictureThe name of the pictureClash 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!
default



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.



ttfamily version



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









share|improve this question























  • You probably want to add columns=fullflexible, keepspaces=true, into your lstset...
    – Thruston
    1 hour ago














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!
default



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.



ttfamily version



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









share|improve this question























  • You probably want to add columns=fullflexible, keepspaces=true, into your lstset...
    – Thruston
    1 hour ago












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!
default



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.



ttfamily version



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









share|improve this question















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!
default



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.



ttfamily version



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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 19 mins ago

























asked 1 hour ago









JC_CL

128115




128115











  • 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















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










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.



enter image description here



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:



enter image description here



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.






share|improve this answer






















  • 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










  • 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

















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


enter image description here



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


enter image description here



There are several other monospaced fonts available, see the LaTeX font catalogue






share|improve this answer




















  • 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

















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.



inconsolata



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





share|improve this answer


















  • 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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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.



enter image description here



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:



enter image description here



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.






share|improve this answer






















  • 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










  • 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














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.



enter image description here



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:



enter image description here



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.






share|improve this answer






















  • 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










  • 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












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.



enter image description here



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:



enter image description here



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.






share|improve this answer














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.



enter image description here



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:



enter image description here



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.







share|improve this answer














share|improve this answer



share|improve this answer








edited 32 mins ago

























answered 1 hour ago









Thruston

24.8k23988




24.8k23988











  • 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










  • 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
















  • 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










  • 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















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










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


enter image description here



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


enter image description here



There are several other monospaced fonts available, see the LaTeX font catalogue






share|improve this answer




















  • 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














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


enter image description here



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


enter image description here



There are several other monospaced fonts available, see the LaTeX font catalogue






share|improve this answer




















  • 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












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


enter image description here



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


enter image description here



There are several other monospaced fonts available, see the LaTeX font catalogue






share|improve this answer












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


enter image description here



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


enter image description here



There are several other monospaced fonts available, see the LaTeX font catalogue







share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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










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.



inconsolata



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





share|improve this answer


















  • 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














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.



inconsolata



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





share|improve this answer


















  • 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












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.



inconsolata



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





share|improve this answer














Personally, for listing, the fundamental criterion is that the 0 is different from the letter O.
For the inconsolata font is perfect.



inconsolata



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






share|improve this answer














share|improve this answer



share|improve this answer








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












  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Comments

Popular posts from this blog

White Anglo-Saxon Protestant

Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

One-line joke