# How can I use STIX Two with nextxtt?

I tried to load STIX Two with fontspec, STIX Two Math with unicode-math, and load newtxtt package directly. However, it seems that the document cannot be complied properly: If I load newtxtt before fontspec, then the monospace font will still be the default one; if I load it after fontspec (as well as the \setmainfont part, see the code sample) but before unicode-math, then the file cannot be compiled due to an 'Insufficient math symbols' error; if I load it after unicode-math, then though the math font is STIX 2 and the monospace font is newtxtt, the text font changed to the default computer modern.

\documentclass{scrartcl}

\usepackage{amsmath}
\usepackage{fontspec}
\setmainfont {STIX2Text-Regular}[
Extension=.otf,
BoldFont=STIX2Text-Bold,
ItalicFont=STIX2Text-Italic,
BoldItalicFont=STIX2Text-BoldItalic,
]
\usepackage[zerostyle=b]{newtxtt}
\usepackage{unicode-math}
\setmathfont{STIX2Math.otf}[StylisticSet=02, StylisticSet=08]
\usepackage{cabin}
\usepackage{dutchcal}
\usepackage{ulem}
\usepackage{leftidx}
\usepackage{physics}
\usepackage{mattens}
\usepackage[e]{esvect}
\usepackage{units}
\usepackage{minted}

\begin{document}

\usemintedstyle{murphy}
\begin{minted}{python}
# Propagate two balls with velocities v1 and v2, print "The
# two balls collided" if they collide:
while 1==1:
ball1.pos=ball1.pos+v1*dt
ball2.pos=ball2.pos+v2*dt
print("The two balls collided")
\end{minted}

\end{document}


You need to choose the T1 encoding inside minted, which doesn't seem directly possible, so a little hack is necessary.

For the STIX Two fonts, use your own method, but installing them as system fonts is more convenient as it makes easier to set them up in the document.

\documentclass{scrartcl}

\usepackage{amsmath}
\usepackage{fontspec}
\usepackage{unicode-math}

\usepackage[zerostyle=b]{newtxtt}
\usepackage{cabin}
\usepackage{dutchcal}
\usepackage{ulem}
\usepackage{leftidx}
\usepackage{physics}
\usepackage{mattens}
\usepackage[e]{esvect}
\usepackage{units}
\usepackage{minted}
\usepackage{xpatch}

\setmainfont{STIX Two Text}
\setmathfont{STIX Two Math}[StylisticSet=02, StylisticSet=08]

\makeatletter
\xpretocmd\FV@SetupFont{\fontencoding{T1}}{}{}
\makeatother

\begin{document}

\usemintedstyle{murphy}
\begin{minted}{python}
# Propagate two balls with velocities v1 and v2, print "The
# two balls collided" if they collide:
while 1==1:
ball1.pos=ball1.pos+v1*dt
ball2.pos=ball2.pos+v2*dt

• @Xintong I opened an issue at the minted site: github.com/gpoore/minted/issues/208 Jul 18, 2018 at 12:55