[Tex/LaTex] Do I need to use \usepackage[T1]{fontenc} if I use lualatex

compilingfont-encodingsluatexunicode

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?

Best Answer

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}