# Serif numbers in monospaced environments in mathspec but not fontspec

I would like to use a serif font for both the body of my text and maths environments as well as a separate monospaced font for things like URLs.

When I compile this using fontspec:

\documentclass[12pt,a4paper]{article}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\setmonofont{Courier New}
\begin{document}
\noindent See the following article on Wikipedia about the year AD 2017:

\url{https://en.wikipedia.org/wiki/2017}

$2000 + 17 = 2017$
\end{document}

I get:

Which does not use the right maths font. Unsurprisingly, I get the same thing by just replacing fontspec with mathspec). But when I add \setmathsfont{Times New Roman} using mathspec, I still get the same result.

And when I compile:

\documentclass[12pt,a4paper]{article}
\usepackage{mathspec}
\setallmainfonts{Times New Roman}
\setallmonofonts{Courier New}
\begin{document}
\noindent See the following article on Wikipedia about the year AD 2017:

\url{https://en.wikipedia.org/wiki/2017}

$2000 + 17 = 2017$
\end{document}

I get:

Which changes the maths environment to the desired font but changes the numbers in the given URL to serif rather than monospaced, which is undesirable.

Does anyone have idea where I'm going wrong and how I can get something that looks like this:

• Have you tried unicode-math and its \setmathfont (in combination with fontspec)? – TeXnician Apr 17 '17 at 14:05
• I hadn't but that actually works quite well! – Miztli Apr 17 '17 at 16:26

url uses math to typeset the url and as mathspec changes mathcodes you get the wrong font. You could reset them:

\documentclass[12pt,a4paper]{article}
\usepackage{mathspec}
\setallmainfonts{Times New Roman}
\setallmonofonts{Courier New}

\makeatletter
\def\Url@FormatString{%
\UrlFont
\Url@MathSetup
\mathcode"30=28720 %0
\mathcode"31=28721 %1
\mathcode"32=28722 %2
%...
\mathcode"37=28727 %7
$\fam\z@ \textfont\z@\font \expandafter\UrlLeft\Url@String\UrlRight \m@th$%
}%
\begin{document}
\noindent See the following article on Wikipedia about the year AD 2017:

\url{https://en.wikipedia.org/wiki/2017}

$2000 + 17 = 2017$
\end{document}

But I would use unicode-math and a times like math font, e.g. like this

\documentclass[12pt,a4paper]{article}
\usepackage{unicode-math}
\setmainfont{Times New Roman}
\setmonofont{Courier New}
\setmathfont{TeX Gyre Termes Math}
\begin{document}
\noindent See the following article on Wikipedia about the year AD 2017:

\url{https://en.wikipedia.org/wiki/2017}

$2000 + 17 = 2017$
\end{document}

• What are the reasons for using TeX Gyre Termes Math rather than Times New Roman itself? – Miztli Apr 17 '17 at 16:14
• For math you need a math font (they have additional values needed for math typesetting, see e.g. tex.stackexchange.com/q/19570/2388) – Ulrike Fischer Apr 17 '17 at 16:16