TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to set specific font just for listings in XeLaTeX.


    .... % my language definition
    \consolas  % do not work


I know it is possible to set default mono-space font for whole document with


and it is working but I do not want other mono-space things like URLs in that font.

Maybe if it is possible to set mono-space font to its default and use this

share|improve this question
Welcome to TeX.SX! Did you try \lstset{basicstyle=\consolas}? Also basicstyle=\ttfamily should work when you declare \setmonofont{Consolas}. – egreg May 1 '12 at 15:40
Wow... I am amazed, basicstyle=\consolas really works. basicstyle=\ttfamily with \setmonofont{Consolas} was affecting other mono-spaced things like URLs which I want with normal font. Can you write your answer as real answer so i can mark it as answer? :) – NightElfik May 1 '12 at 15:59
up vote 9 down vote accepted

The "correct" way is to use \setmonofont:



\lstdefinelanguage{MyLanguage}{ .... } % my language definition

Should you want a specific monospaced font for only your MyLanguage listings, you can do



I'd add also the columns=fullflexible option, but it's a matter of taste.

share|improve this answer

Your Answer


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.