2

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

3

1 Answer 1

7

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

0

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.