1

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
    if mag(ball1.pos-ball2.pos) < ball1.radius+ball2.radius:
        print("The two balls collided")
\end{minted}

\end{document} 
1

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

I changed a bit your preamble, separating package loading and declarations.

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
    if mag(ball1.pos-ball2.pos) < ball1.radius+ball2.radius:
        print("The two balls collided")
\end{minted}

\end{document} 

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.