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.

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'd like to use the luximono face for monospaced typesetting under XeLaTeX. Since it is already installed in the MikTeX distribution under T1 encoding, I switch to the latter when I need monospaced type. In order to do this, I have defined corresponding commands, as shown in the MWE below. Now, if I do not redefine the control sequence \nobreakspace in a form such as, e.g., I have done for my MWE, I get the error message Command \nobreakspace unavailable in encoding T1. My redefiniton is a workaround to this problem, and it has to it more of a patch than of a satisfactory solution. Could anyone possibly explain what is going on and how to solve it in a more appropriate way?





            {\xlxmono #1}


    {\ttfamily This is one line set in a monotype face with a nobreakspace command~here.}

    \texttt{This makes for yet another line with~it.}

share|improve this question
You should not be using fontenc with fontspec: the latter uses special 'Unicode encodings' as the way things work with XeTeX and LuaTeX is very different from 'traditional' LaTeX encodings. – Joseph Wright Aug 13 '12 at 13:39
@Joseph Wright: I do agree, but in this case it is not a troublemaker. I would delete it ftom my MWE, but since it is mentioned in other contributed comments and answers, I think it's better to keep it. – Marcos Aug 13 '12 at 17:59
@JosephWright It seems to be sometimes necessary: see tex.stackexchange.com/q/115627/18401. – Denis Bitouzé Apr 20 at 8:47
@DenisBitouzé The encoding is wrong: hyphenation for slots 128-255 will be incorrect if you do this. You really can't use traditional TeX fonts reliably with XeTeX/LuaTeX, at least without a lot of effort. – Joseph Wright Apr 20 at 8:52
@DenisBitouzé Unless all of your text is in English, I'm afraid so. The LaTeX team have been 'worrying' about this area recently and although one can imagine approaches (loading multiple hyphenation patterns) they are complex and probably not generally useful. – Joseph Wright Apr 20 at 8:59
up vote 9 down vote accepted

If you modify your example to


You will see

> \nobreakspace=macro:
->\protect \nobreakspace  .
l.9 \show\nobreakspace


> \nobreakspace=macro:
->\EU1-cmd \nobreakspace \EU1\nobreakspace .
l.11 \show\nobreakspace

which means that the EU1 encoding setup has changed \nobreakspace from being an encoding-independent command to an encoding-dependent command, but without setting up a default definition so it works in all encodings. Re-instating the original definition as the default is probably the simplest thing, however note you should not be mixing fontenc and fontspec encoding definitions in a single document.

The original definition is

   \leavevmode\nobreak\ }

So you could declare a default via

 \DeclareTextCommandDefault{\nobreakspace}{\leavevmode\nobreak\ } 

as noted in the comments.

Note that your definition would not work if it was used in vertical mode, eg the start of a paragraph as in that position the \nobreak would prevent a page break not a line break.

Unrelated to the question you have lots of white space tokens in your definition which will produce white space in the output: put a % at the end of every line within the definitiosn that ends with } or {.

Note also you need to use xelatex to use fontspec but you also load microtype which generates a warning that it does not work with xelatex:

Package microtype Warning: You don't seem to be using pdftex.
(microtype)                `microtype' only works with pdftex.
(microtype)                Try running `pdflatex' instead of `xelatex'.

Unless you have the beta version as pointed out by @UlrikeFischer. See. http://tlcontrib.metatex.org/cgi-bin/package.cgi/action=view/id=423

share|improve this answer
fontspec can change things to be encoding-dependent as input encodings for UTF-8 input are not really the same thing as for 'traditional' LaTeX. – Joseph Wright Aug 13 '12 at 13:41
Yes didn't notice (or it didn't sink in) that fontspec and fontenc were both loaded until I saw your comment on the question. – David Carlisle Aug 13 '12 at 13:44
Its xunicode which changes \nobreakspace: It maps the command to U+00A0. I would use either \DeclareTextCommand{\nobreakspace}{T1}{\leavevmode\nobreak\ } or \DeclareTextCommandDefault{\nobreakspace}{\leavevmode\nobreak\ } which would not destroy the xunicode declaration for EU1. Regarding microtype: There exist beta versions which works with xelatex: tlcontrib.metatex.org/cgi-bin/package.cgi/action=view/id=423 – Ulrike Fischer Aug 13 '12 at 14:24
@ David Carlisle: Thanks so much for such a detailed answer. Only a couple of comments: Ulrike Fischer is right in everything she says (in her comment on this post ;-)); in particular, on Microtype (beta) v2.5, which I am using. I think the white spaces in my commands do not really add any typeset spaces, although it's true one must be very careful about it when it comes to TeX, and my MWE is not a benchmark of LaTeX code editing. Finally, if I try my MWE with your answer, it works fine, but if I do in my original project, I end up with an error message. – Marcos Aug 13 '12 at 18:14
@David Carlisle: (Continues from last comment) That project is a long class which loads many packages. The error I get is File ended while scanning use of @LN. I do not get any error message if I use my original tentative workaround -- as in my MWE. Any possible hints on this? I'm afraid I don't think that I can provide an MWE for this. – Marcos Aug 13 '12 at 18:19

I'd simply provide a suitable definition for \nobreakspace in the T1 encoding and define \ttfamily so that it chooses both LuxiMono and the T1 encoding:

\DeclareTextCommand{\nobreakspace}{T1}{\leavevmode\nobreak\ }

Since \texttt relies on \ttfamily, it's not necessary to act on it.

share|improve this answer
Thanks for drawing my attention to the package xpatch. Yours is an interesting solution, and would consider it as another valid answer, but I'm afraid I can only select one. – Marcos Aug 13 '12 at 18:22

use this preamble:




\renewcommand*\texttt[1]{{\xlxmono #1}}
share|improve this answer
Thanks for your answer. I'd rather not switch to unicode-math for this project in particular -- actually, I'm stil more comfortable with the "regular" TeX math packages than with the Unicode-based -- mostly for the small number of alternatives the latter convey at the current stage of development. – Marcos Aug 13 '12 at 15:34

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.