4

There are quite some questions about getting accents like è into the lstlisting environment. But I actually want to have a free floating accent. However, Latex always changes it to some other symbol so copy pasting the code will not work.

Here a MWE:

\documentclass{article}
\usepackage{listings}

\begin{document} \begin{lstlisting} if(...) \end{lstlisting}

\end{document}

user202729
  • 7,143
NOhs
  • 858

1 Answers1

5

You can use the upquote package:

\documentclass{article}
\usepackage{listings}
\usepackage{upquote}

\begin{document}
\begin{lstlisting}
    `if`(...)
\end{lstlisting}

\end{document}

enter image description here

For using BeraMono:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{beramono}
\usepackage{listings}
\usepackage{upquote}
\lstset{basicstyle=\ttfamily,columns=fullflexible}

\begin{document}
\begin{lstlisting}
    `if`(...)
\end{lstlisting}

\end{document}

enter image description here

egreg
  • 1,121,712