[Tex/LaTex] XeLaTex: ‘Font Shape undefined’

fontspecxetex

I'm trying to use custom fonts, but I can't get it to work. Compiling with XeLaTex

\documentclass[a4paper]{article} 

\usepackage{fontspec}
\usepackage[T1]{fontenc} 
\usepackage[usenames,dvipsnames]{xcolor}

\definecolor{primary}{HTML}{2b2b2b}

\setmainfont[Color=primary, 
Path = fonts/lato/,
BoldItalicFont=Lato-RegIta,
BoldFont=Lato-Reg,
ItalicFont=Lato-LigIta]{Lato-Lig}

\begin{document}

Test example

\end{document}

Build Log Output:

LaTeX Font Warning: Font shape `T1/Lato-Lig(0)/m/n' undefined
(Font)              using `T1/cmr/m/n' instead on input line 13.

Folder Structure (ls -R)

fonts  test.tex   
./fonts: lato
./fonts/lato: Lato-BlaIta.ttf  Lato-Bol.ttf     Lato-LigIta.ttf  Lato-Reg.ttf Lato-Bla.ttf     Lato-HaiIta.ttf  Lato-Lig.ttf Lato-BolIta.ttf  Lato-Hai.ttf     Lato-RegIta.ttf

Best Answer

Old question, but I’ll expand on the comments for a real answer.

You shouldn’t use fontenc with fontspec. Simply remove the line \usepackage[T1]{fontenc}.

You don’t clarify why you need to load an 8-bit legacy font in addition to the Unicode font. Unicode is a strict superset of all legacy encodings and any character in them is also in Unicode.

If, for whatever reason, you do need to use legacy 8-bit font and a modern font in the same document, you would need to install the 8-bit version of the font, look up its NFSS font family, for example lmr, and then add the option NFSSFamily=lmr to the Fontspec-style font definition. Another alternative is substitutefont to select a replacement font when you tell LaTeX to switch to an encoding that your main font does not come in. In these cases, you would want to set up the T1 encoding first and then load Unicode (TU) as your default encoding. Use \textencoding{T1} to switch.