Cannot use courier package and Times New Roman

fontspackages

For whatever reason, when I try to use Times New Roman (i.e., via \setmainfont{Times New Roman}) and the courier package together, LaTeX does not use Courier in \texttt… it looks like it uses the regular LaTeX CMU Serif font, but I could be wrong. Is there some conflict between these two, and if so, is there a workaround? For reference, I'm using Overleaf with the XeLaTeX compiler.

PoC:

\documentclass{article}
\usepackage{fontspec}
\usepackage{enumitem}
\usepackage{courier}
\usepackage[T1]{fontenc}
\setmainfont{Times New Roman}
\title{Font tests}

\begin{document}

\section{Introduction}
The quick brown fox jumps over the lazy dog. \texttt{This should be in courier but it isn't...}

\end{document}

Output:
Times New Roman and Courier fonts not working correctly

Best Answer

The courier package is a legacy 8-bit font package, so fontspec will override it if you load both.

You would want something like,

\usepackage{fontspec}
\setmainfont{Times New Roman}
\setmonofont{Courier New}

or

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

This uses GUST’s free clones of Times, Helvetica and Courier.