[Tex/LaTex] How to use system font for equation in XeLaTeX

fontsmath-modexetex

I am trying to use system font for LaTeX. I am able to do it for text but not for the math part. Here is an example (compiled using XeLaTeX), where I use the font "Broadway", but it doesn't work for the math part. Any suggestion for how to define the font for the math part?

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\usepackage[xetex]{graphicx}
\usepackage{fontspec,xunicode}
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
\setmainfont[Scale=.95]{Broadway}
\setmonofont{Broadway}

\begin{document}
This is the formula for $(a+b)^2$
\begin{equation}
(a+b)^2=a^2+2ab+b^2
\end{equation}

\end{document} 

I found alternate ways from The LaTex Font Catalogue.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\usepackage{concmath}
\usepackage[T1]{fontenc}

\begin{document}
This is the formula for $(a+b)^2$
\begin{equation}
(a+b)^2=a^2+2ab+b^2
\end{equation}

\end{document}

I was looking for typewritter font and "concmath" is a good one and also provides math support. But I am more interested in courier font which is also available in catalogue

\usepackage{courier}
\renewcommand*\ttdefault{lcmtt}
\renewcommand*\familydefault{\ttdefault}
\usepackage[T1]{fontenc}

But now the maths appears in Roman. Is there any possible way to make the math part use the courier font. I am not sure if it can be done by modifying the corresponding .sty file somehow or if there is any other better way. All I am trying to do is to make the math part use the same font (for the text part only, not for the symbol) as text without any italic or bold.

Best Answer

Use mathspec package. Note however that most fonts include only Latin, Greek alphabets that can be used with mathspec. If you want the math fonts, alphabets and symbols alike, to be consistent, you need unicode-math package together with an OpenType fonts with MATH table. Such fonts are relatively rare, and the only font with complete Unicode coverage is XITS/STIX.


Basic usage of mathspec:

\usepackage{mathspec}
\setmainfont{Broadway}
\setmathsfont(Digits,Latin,Greek)[Numbers={Lining,Proportional}]{Broadway}

Several comments:

  • Do not load fontspec package. It will clash with mathspec.
  • Symbols not available in the text fonts will fall back to Computer Modern. If you like the operators provided by mnsymbol package, which is designed to work with Minion Pro, use the option \usepackage[MnSymbol]{mathspec}.

Basic usage of unicode-math:

This package is for fonts that contain an OpenType MATH table. Currently only these fonts are available:

The last one is recommended for its complete coverage and times-like appearance (most professional books use times-like fonts for math).

\usepackage{unicode-math}
\setmainfont{XITS}
\setmathfont{XITS Math}
\setmathfont[range={\mathcal,\mathbfcal},StylisticSet=1]{XITS Math}

The last line is only usable with XITS Math or STIX. It makes sure that \mathcal and \mathscr looks different and be consistent with looks in traditional TeX fonts.


Miscellaneous comments on your code:

  • Don't use inputenc with XeTeX or LuaTeX. The utf8 option of inputenc is a compilation of dirty hacks that implements a tiny fraction of Unicode while XeTeX natively suuports UTF-8 and UTF-16.
  • There is no need to specify xetex with graphicx package. In modern distributions it auto detects.
  • Your alternative solutions all utilize legacy code, like T1 fontenc, which should be avoided with xetex.