1

Edit: I have copied the entire main.tex for clarification.

I want the titles to be in Helvetica, and the main text and equations to be in Times New Roman. How do I go about specifically changing the fonts for equations and main body text?

\documentclass[a4paper,portrait]{article}

\usepackage[style=authoryear, backend=biber]{biblatex}
\usepackage{hyperref}
\hypersetup{
  colorlinks=true,
  linkcolor=blue,
  citecolor=green,
  urlcolor=blue
}
\addbibresource{references.bib}

\usepackage{helvet}
\renewcommand\familydefault{\sfdefault}

\usepackage{sectsty}
\allsectionsfont{\normalfont\sffamily}

\usepackage{nicematrix}
\usepackage{caption}
\usepackage{mathtools}
\usepackage{nicematrix}
\usepackage{blkarray, bigstrut}
\usepackage{lipsum}
\usepackage{nicefrac}
\usepackage{cancel}
\usepackage{textcomp}
\usepackage{subfig}
\usepackage{float}
\usepackage{geometry}
\usepackage{hyperref}
\usepackage{graphicx, multicol}
\usepackage{xcolor}
\usepackage{pseudocode}
\usepackage[mmddyy]{datetime}
\usepackage{fancyhdr}
\usepackage[framed]{matlab-prettifier}
\usepackage[T1]{fontenc}

\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[C]{\begin{minipage}{\textwidth}\centering\thepage\end{minipage}}
\newcommand{\note}[1]{\marginpar{\scriptsize \textcolor{red}{#1}}}
\DeclareMathOperator*{\argmin}{arg\,min}

\geometry{
  left=2.27cm,
  right=2.27cm,
  top=0.27cm,
  bottom=0.27cm,
  columnsep=20pt,
}

%\renewcommand{\rmdefault}{bch}

\setlength{\columnseprule}{0.5pt}

\begin{document}

%\pagecolor{mybackgroundcolor4}
\pagenumbering{arabic}

\input{car2.tex}
%\lipsum[2-4]

\printbibliography
\end{document}
3
  • 1
    your first example is for pdflatex your second is for lualatex or xelatex. which are you using? Commented Feb 14 at 22:29
  • Welcome to TeX.SE. Please tell us which document class you employ.
    – Mico
    Commented Feb 14 at 22:41
  • 1
    I was using pdflatex, but it is not a conscious decision. I copied the main.tex file for your view.
    – user314174
    Commented Feb 14 at 22:54

1 Answer 1

1

The following setup works under both pdfLaTeX and LuaLaTeX.

enter image description here

\documentclass{article} % or some other suitable document class

\usepackage{iftex}
\ifpdftex % 'true' if we're running pdfLaTeX
   \usepackage[T1]{fontenc}
   \usepackage{newtxtext,newtxmath} % Times Roman clone
   \usepackage[scaled=0.86]{helvet} % Helvetica clone
\else
   \usepackage{unicode-math}
   \setmainfont{Times Roman}
   \setmathfont{XITS Math}[Scale=MatchLowercase]
   \setsansfont{Helvetica}[Scale=MatchLowercase]
\fi

\usepackage{sectsty}
\allsectionsfont{\sffamily} % use sans-serif in sectioning headers

\begin{document}

\section{Hello World}

Once upon a time\dots\quad $E=mc^2$ \quad xx\textsf{xx}

\end{document}
3
  • 1
    Thank you a thousand times! Exactly what I was looking for. Is there any way I can make the Table of Contents to be in Helvetica in this way? I copied the entire main.tex file below.
    – user314174
    Commented Feb 14 at 22:56
  • @kolmogorov - To render all section-level and subsection-level ToC entries, as well as the associated page numbers, in the sans-serif font, give \usepackage[titles]{tocloft} \renewcommand\cftsecfont{\sffamily} \renewcommand\cftsecpagefont{\sffamily} \renewcommand\cftsubsecfont{\sffamily} \renewcommand\cftsubsecpagefont{\sffamily} a try.
    – Mico
    Commented Feb 14 at 23:07
  • 1
    It works, thank you again!
    – user314174
    Commented Feb 14 at 23:09

You must log in to answer this question.