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.

14
  • 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. Sep 1, 2014 at 7: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 1, 2014 at 7:45
  • 5
    Why would you want to use xelatex in this case? Sep 1, 2014 at 7: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 1, 2014 at 8:13
  • 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...) Sep 1, 2014 at 13:42

2 Answers 2

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.

2
  • 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 2, 2014 at 6:43
  • @MunHo That it works in LuaTeX, which has a different treatment for input encodings. See my edit.
    – Manuel
    Sep 2, 2014 at 8:29
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.

1
  • 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? Feb 28, 2021 at 19:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .