how do I set KP-monospaced font to be used as tt font with fontspec?

I tried this:

\texttt{120 test}

But it does not work

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Do you have the fonts installed in opentype or truetype format? As far as I can tell, TeX Live includes type1 versions but nothing else, in which case you probably need to load them in the 'traditional' way rather than using fontspec i.e. \usepackage{} or specific commands for just the monospaced font, for example. – cfr Oct 4 '14 at 21:18
  • @cfr I only have the version that comes with the CTAN package. don't know what that is. How do I load the package in the traditional way? If I add usepackage{kpfonts} nothing changes and the tt font is not in kp-monospaced. – Trak Oct 4 '14 at 21:20
  • It works for me if I delete the fontspec and \set... lines. – cfr Oct 4 '14 at 21:22
  • @cfr No, sorry, I was not clear. I need to load fontspec for other purposes in my document. So my question is: how to load the tt font in a traditional way while using fontspec? – Trak Oct 4 '14 at 21:24
  • Ah. That's more complex as you need to enforce a non-unicode encoding against the will of fontspec. See my answer below. (Code doesn't work well in comments!) – cfr Oct 4 '14 at 21:32

I'm not certain this is the right way to do it but the following seems to work for me, with very minimal testing. Caveat emptor...

  \texttt{120 test}
|improve this answer|||||
  • Is the instruction \usepackage[T1]{fontenc} necessary? – Mico Oct 4 '14 at 21:38
  • Ok, with a preliminary test it works. thank you (can't upvote) – Trak Oct 4 '14 at 21:39
  • @Mico I'm not sure. This test worked without it but I was worried that it might be necessary for something more subtle I wasn't aware of. Would it be safe to remove it? – cfr Oct 4 '14 at 22:14
  • One commonly-given pieces of advice when using LuaLaTeX is not to load the fontenc and inputenc packages. Your MWE definitely seems to work without the \usepackage[T1]{fontenc} instruction. – Mico Oct 4 '14 at 22:15
  • @Mico That is the general rule, yes. However, my understanding is that fontenc is sometimes appropriate for use with Xe/LuaLaTeX, but that you have to be careful. Typically, it is a bad idea but typically, you are not using the T1 encoding because using the T1 encoding is a bad idea. In this case, though, you have to rely on the T1 encoding. So we are already outside the remit of standard recommendations. I can't find anything yet which omitting it breaks, but I'm not at all sure that there is no such thing! – cfr Oct 4 '14 at 22:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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