4

I'm just trying to insert source code into the LaTeX file with listings package. the TeX code goes as follows:

\documentclass{article}
\usepackage{listings}
\usepackage{color}
\usepackage{fontspec}
\newfontfamily\Monaco{Monaco}
\lstset{ 
  basicstyle=\footnotesize\Monaco
}

\begin{document}
\lstinputlisting[language=C++]{filename.cpp}
\end{document}

However, the - symbol in the code was not displayed in the font Monaco I used, instead, it's using the Math-Type minus. (As shown in the image below) Display

I searched it on google and found several fixes, e.g. column=texcl, but none of them worked. Thank you for your help in advance.

btw, The environment is TeXLive 2017 on Windows 10

muzimuzhi Z
  • 26,474

1 Answers1

9

You can change the definition like this:

\documentclass{article}
\usepackage{listings}

\usepackage{fontspec}
\newfontfamily\Arial{Arial}
\lstset{
basicstyle=\footnotesize\Arial
}
\begin{document}
\begin{lstlisting}
a-b
\end{lstlisting}
\makeatletter
\lst@CCPutMacro
    \lst@ProcessOther {"2D}{\lst@ttfamily{-{}}{-}}
    \@empty\z@\@empty
\makeatother

\begin{lstlisting}
a-b
\end{lstlisting}

\end{document}

enter image description here

Ulrike Fischer
  • 327,261