10

When producing documents with pdflatex that may contain special utf-8 characters, it is recommended to add the following to the preamble

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

I know that with lualatex the inputenc line is not necessary, since everything is set up to use utf-8 encoding by default. But I don't know what to do about that fontenc line. Do I need to include it or not if I am using lualatex?

8
  • 1
    See @egreg's answer here. Spoiler alert, the answer is no. But I don't know exactly why, so I'll not answer the question. – Phelype Oleinik Jan 29 '18 at 21:18
  • 1
    no you should not have either of those lines for luatex – David Carlisle Jan 29 '18 at 21:19
  • 3
    Short answer: no. Long answer: NO. – user139954 Jan 29 '18 at 22:47
  • You can if you use the luainputenc package instead of inputenc. But it is mainly for backward compatibility with old (PDF)LaTeX documents. If you really want to stick to the old input and font encodings, better use (PDF)LaTeX instead of LuaLaTeX. – Franck Pastor Jan 29 '18 at 23:09
  • As I understand it, somebody might want that line. However, that's only true if you know precisely why you want it and what the consequences are. If you aren't sure whether you need it, not only don't you need it, you shouldn't have it. Consider \usepackage{fontspec} instead. – cfr Jan 30 '18 at 0:17
7

If you want to use pdflatex, you should use in your preamble:

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

If you want to use lualatex or xelatex, you should use in your preamble:

\usepackage{fontspec}
\setsansfont{CMU Sans Serif}%{Arial}
\setmainfont{CMU Serif}%{Times New Roman}
\setmonofont{CMU Typewriter Text}%{Consolas}

If you want to compile your document time to time with lualatex or with pdflatex without changing preamble, you can use ifluatex package. Typical preamble for this purpose can looks like:

%%============================ Compiler Directives =======================%%
%%                                                                        %%
% !TeX program = lualatex                                   
% !TeX encoding = utf8
% !TeX spellcheck = english
%%                                                                        %%
%%============================== Document Class ==========================%%
%%                                                                        %%
\documentclass[14pt]{article}
\usepackage{ifluatex}
%%                                                                        %%
%%========================================================================%%

\ifluatex 
    \usepackage{fontspec}
    \setsansfont{CMU Sans Serif}%{Arial}
    \setmainfont{CMU Serif}%{Times New Roman}
    \setmonofont{CMU Typewriter Text}%{Consolas}
    \defaultfontfeatures{Ligatures={TeX}}
\else
    \usepackage[utf8]{inputenc}
    \usepackage[T2A,T1]{fontenc}
\fi

\usepackage[english]{babel}

\begin{document}



\end{document}
1

No, Luatex does not require using the fontenc package.

0

I still like to use 8 bit fonts for IPA (T3 encoding) and non-math Greek (LGR encoding)

I use them via the "substitutefont" package, and I believe that still requires that fontenc be loaded.

Anyway one thing I noticed is that if you load fontenc after fontspec then things break so if you do use fontenc, load it before fontspec.

Loading it before fontspec doesn't seem to harm anything.

EDIT:

I did a test. When loading fontenc after fontspec stuff, as long as TU is last specified encoding, things work. Take away the TU in this code and you'll see how it breaks.

\documentclass[letterpaper, fontsize=14pt]{scrbook}
\usepackage{fontspec}
\defaultfontfeatures{
  Ligatures = TeX,
  Extension = .ttf}
\setmainfont
  [ UprightFont = *-Regular ,
    ItalicFont  = *-Italic ,
    BoldFont    = *-Medium ,
    BoldItalicFont = *-MediumItalic ]
  {ClearSans}
\setsansfont
  [ UprightFont = *-Regular ,
    ItalicFont  = *-Italic ,
    BoldFont    = *-Bold ,
    BoldItalicFont = *-BoldItalic ]
  {ClearSans}
\usepackage[LGR,T1,TU]{fontenc}
\begin{document}
\chapter{Chapter One}
This is content.
\section{Section One}
This is more content.
\end{document}
6
  • Note that you do not need 8-bit fonts for either: every character and font that the T3 or LGR encodings support is also available in Unicode. – Davislor Jul 19 at 0:09
  • Yes, they are, but it is a lot easier to type them from my Latin keyboard using Latin characters that then get mapped to the correct glyph at compile time. And it's also incredibly useful when I want to ensure the document compiles with both pdflatex and luatex. My understanding is that fontspec actually calls fontenc itself - the problem is that the LAST encoding is the default encoding so when calling fontenc after fontspec, T1 (or whatever) is last, breaking fontspec. – AnymouseProphet Jul 19 at 0:55
  • You can use the TIPA mappings with the unitipa package, and I’ve seen a few methods to enable Beta Code mappings for Greek in LuaTeX. – Davislor Jul 19 at 1:00
  • Sure, there is always more than one way to do things. For me personally, the way that works in both pdfLaTeX and LuaLaTeX is the better way because it is more portable between engines. As fontspec calls fontenc anyway, there isn't a conflict with the package itself and fontspec, just a conflict with calling it after fontspec has loaded. – AnymouseProphet Jul 19 at 1:07
  • I think as long as TU is the last argument given to fontenc then it will work even after having called fontspec - just like (for western Latin users) we always had to make sure T1 was last called with pdflatex. But I haven't tested. – AnymouseProphet Jul 19 at 1:13

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.