5

How do I use the inbuilt LaTeX standard fonts (in this case Times for roman, Helvetica for sans serif and Courier for mono) when using XeLaTeX and fontspec?

I have tried:

\documentclass[journal, a4paper]{IEEEtran}

\usepackage{fontspec}
\renewcommand\rmdefault{ptm}
\renewcommand\sfdefault{phv}
\renewcommand\ttdefault{pcr}

\begin{document}
     “Touché,” \textsf{he} \texttt{said}.
\end{document}

without success. Note that I want to be able to type utf8, non-English characters directly and therefore I use fontspec.

MunHo
  • 479
  • 1
    The encoding of this fonts is not suitable for xelatex -- even more if you want to use characters with accents. Switch to open type fonts. Eg. \setmainfont{Times New Roman} or use the tex gyre fonts. – Ulrike Fischer Sep 01 '14 at 07:43
  • The task at hand requires me to use the standard fonts specified by the class IEEEtran. Is it possible to use XeLaTeX then? – MunHo Sep 01 '14 at 07:45
  • 5
    Why would you want to use xelatex in this case? – Ulrike Fischer Sep 01 '14 at 07:49
  • 2
    If you are using a 'constrained' class for a specific reason, you should be cautious about adding any extra complexity. Perhaps consider sticking with pdfTeX and using \usepackage[utf8]{inputenc} or the even more 'traditional' approach of \'{e}, etc. – Joseph Wright Sep 01 '14 at 08:13
  • You're right maybe it's stupid. However, I like the freedom that XeLaTeX brings, to throw in text from any language every now and then. – MunHo Sep 01 '14 at 08:24
  • @MunHo Why not LuaTeX? – Manuel Sep 01 '14 at 08:41
  • @Manuel Yeah, maybe I should move over to LuaTeX. How would it be done in LuaTeX? – MunHo Sep 01 '14 at 09:52
  • lualatex would have exactly the same problem: The standard fonts are OT1/T1 encoded and this is not suitable for the unicode engines. You would have to make the non-ascii chars active to be able to use them and run into problems if you mix this with real unicode fonts. Also the hyphenation will probably not work correctly. – Ulrike Fischer Sep 01 '14 at 10:27
  • @UlrikeFischer I don't know, and probably you are right, but for instance, loading any OT1/T1 font with the usual LaTeX package, and using \usepackage[utf8]{luainputenc} gives the correct fonts in the document. – Manuel Sep 01 '14 at 13:20
  • @Manuel: I didn't say that it is not possible to use the fonts, but that it is not sensible. Did you try to mix them with some normal unicode fonts? Did you check the hyphenation? – Ulrike Fischer Sep 01 '14 at 13:29
  • @UlrikeFischer No, I did not (I don't know how to check hyphenation), that's why I said that you are probably right. I didn't try to mix them with unicode fonts since the OP didn't explicitly asked for that (but it doesn't work :D). – Manuel Sep 01 '14 at 13:34
  • 2
    the ieee seems more forgiving than most, but surely they'll use their chosen fonts when printing your paper. in this situation i would go for the simplest possible configuration of fonts. (it wasn't an issue when i was involved in publications in ieee journals...) – wasteofspace Sep 01 '14 at 13:42
  • @UlrikeFischer In this case, I am not planning to mix the text with Unicode fonts. But out of curiosity: what would be the problem with the hyphenation, if I did? – MunHo Sep 02 '14 at 06:46
  • If you don't want to use unicode fonts there is no much sense to use xelatex or lualatex. Hyphenation patterns depends on the font encoding: T1-encoded fonts need other patterns then unicode fonts. For T1 the differences should be small as a lot of positions are similar. – Ulrike Fischer Sep 02 '14 at 07:48

2 Answers2

5

There are many way to write with your preferred fonts. Just one simple example with XeLaTeX/LuaLaTeX

% !TEX program = xelatex
% !TEX encoding = utf8

\documentclass[journal,a4paper]{IEEEtran}

\usepackage{fontspec}
\defaultfontfeatures+[\sffamily,\ttfamily]{Scale=MatchLowercase}
\setmainfont{FreeSerif}
\setsansfont{FreeSans}
\setmonofont{FreeMono}

\begin{document}
“Touché,” \textsf{he} \texttt{said}.
\end{document}

Another way is based on the TeX Gyre fonts

\setmainfont{TeX Gyre Termes}
\setsansfont{TeX Gyre Heros}
\setmonofont{TeX Gyre Cursor}

If you want a Math support, you can use STIX Math fonts with unicode-math package.

  • I use This is XeTeX, Version 3.14159265-2.6-0.999991 (TeX Live 2019) (preloaded format=xelatex 2019.5.8). I copied this exact file and it threw the following error: ! Package fontspec Error: The font "FreeSerif" cannot be found. What is wrong? – Jacob Wegelin Feb 28 '21 at 19:39
4

The document @Sverre wrote, but with LuaLaTeX gives a correct output. However, as @UlrikeFischer said, it seems to be “wrong” in many ways.

%!TEX TS-program = lualatex
\documentclass{article}
\usepackage[utf8]{luainputenc}
\usepackage[T1]{fontenc}
\usepackage{mathptmx} % Times font
\usepackage{helvet} % Helvetica font
\usepackage{courier} % Courier font
\begin{document}
“Touché,” \textsf{he} \texttt{said}
\end{document}

enter image description here

EDIT:

If you want to be able to compile in pdfLaTeX without changing input you can

\usepackage{ifluatex}
\usepackage[utf8]{\ifluatex lua\fi inputenc}

PS: I added the fontenc package that I missed before, and the document seems to work the same way as with OT1.

Manuel
  • 27,118
  • This seems to work just like I had hoped for! What is the difference between luainputenc and inputenc? The latter does not work. – MunHo Sep 02 '14 at 06:43
  • @MunHo That it works in LuaTeX, which has a different treatment for input encodings. See my edit. – Manuel Sep 02 '14 at 08:29