I am trying to use a custom font (.otf files) on a template document that I am building. I looked for different ways of doing so and am currently using the XeLatex compiler to create a new font family and I am trying to apply it to my entire document (that's my goal, not to just use it for a certain part, but the whole thing).
The code and output that I am getting are:
...
\usepackage{fontspec}
\newfontfamily\coolfont[Path=config/CoolFont/,
Extension=.otf,
UprightFont=*-Regular,
ItalicFont=*-RegularItalic,
BoldFont=*-Bold,
BoldItalicFont=*-BoldItalic
]{CoolFont}
...
\begin{document}
\coolfont
...
\end{document}
My problem is that the section header and the figure caption are not in the font I selected (the body text looks good, correctly applying bold and italics as well). This also happens for page numbers, table captions, etc. I have also tried calling the \coolfont
in the preamble, which just gave me an error and I tried using \setmainfont
, but that didn't even change the body text font.
What is the best way to use custom font files to set a font for the whole document? (I am using Overleaf for this project)
Thank you so much for the help!
EDIT:
The following is my failed attempt at making it work with \setmainfont
, while trying to leave most of the configuration I was already using in my document.
% ----------------------------- PREAMBLE -----------------------------
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage{epsfig, url}
\usepackage{epstopdf}
\usepackage{graphicx}
\usepackage{datetime}
\usepackage{multirow}
\usepackage{indentfirst}
\usepackage{amssymb}
\usepackage{geometry}
\geometry{a4paper}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{newtxtext}
\usepackage{float}
\usepackage{titling}
\usepackage{xcolor}
\usepackage{fontspec}
\usepackage{titlesec}
\setmainfont[Path=config/CoolFont/,
Extension=.otf,
UprightFont=*-Regular,
ItalicFont=*-RegularItalic,
BoldFont=*-Bold,
BoldItalicFont=*-BoldItalic
]{CoolFont}
% ------------------------- DOCUMENT START -------------------------
\begin{document}
\section{The quick brown fox jumps over the lazy dog}
\label{intro}
The quick brown fox jumps over the lazy dog. 0123456789
\textbf{The quick brown fox jumps over the lazy dog. 0123456789}
\textit{The quick brown fox jumps over the lazy dog. 0123456789}
\textit{\textbf{The quick brown fox jumps over the lazy dog. 0123456789}}
\begin{figure}[hbt!]
\centering
\includegraphics[scale=0.1, angle=0]{imagens/image.png}
\caption{The quick brown fox jumps over the lazy dog}
\label{fig:image}
\end{figure}
\end{document}
\setmainfont
and friends. So you should focus on why\setmainfont
didn't even change the text body font. To help with that, we will need a minimal, but complete (including a document class etc.) example demonstrating the issue.inputenc
in XeLaTeX (you should have gotten a warning that it was ignored).newtxtext
package. I will have to change a few things to account for that, but the problem is solved! Thank you again!