Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using Lyx's Insert|Program Listing to insert a code listing into my document. Unfortunately, Lyx seems to ignore the Typewriter font selection I made in DocumentOptions under Fonts ⇒ Typewriter. Interestingly enough, typewriter font does come out correctly elsewhere, but not in program linstings.

Can someone help me figure out why? I'm using Lyx 2.0.2 and am using XeTeX for output.

share|improve this question
    
Have you changed the listing to actually use typewriter fonts? By default, they are not used. –  Torbjørn T. Apr 25 '12 at 11:42
    
No, I haven't. I assumed they'd be used automatically. If that's not the case, how do I make this setting document-wide? Also, I think the letter spacing in program listings is wrong (wider than normal), is there any way to get it to 'default' levels? –  Dmitri Nesteruk Apr 25 '12 at 11:48
    
I added a suggestion about the spacing issue to my answer. –  Torbjørn T. Apr 25 '12 at 11:57

2 Answers 2

up vote 6 down vote accepted

Program listings does not actually use the typewriter font family by default, so you have to change this in the settings. To change it for a single listing, right click it, choose Settings and select Typewriter as Font family.

enter image description here

To make it a global change, go to Document --> Settings --> Listings, and type in the following option:

basicstyle={\ttfamily}

For the spacing, try adding

columns=fullflexible

to the options list for listings. I'm not entirely sure about this, though the different choices for columns is described in the listings manual (listings is the package used for these program listings), section 2.10 Fixed and flexible columns.

share|improve this answer
    
Thanks, I get it now. What about letter spacing - can that be fixed too? Or am I imagining things? –  Dmitri Nesteruk Apr 25 '12 at 11:55
    
Actually, I've just tried \basicstyle{\ttfamily} and XeTeX gave me an Undefined control sequence. –  Dmitri Nesteruk Apr 25 '12 at 13:32
    
@DmitriNesteruk There is no backslash before basicstyle and an = after. –  Torbjørn T. Apr 25 '12 at 13:39
    
Whoops, my bad. –  Dmitri Nesteruk Apr 25 '12 at 13:43

I still use LyX 1.6, the more recent version available for Windows 2000 (which I have in a couple of PCs). In LyX 1.6.10 you don't find the "Listings" module in the "Document->Settings" menu. So you solve this issue by adding

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

to the "Latex Preamble" box in the "Document->Settings" menu.

share|improve this answer
    
Welcome to TeX.SX. –  Claudio Fiandrino Apr 25 '13 at 16:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.