3

I am using the lstlisting package and the semantic package. Now whenever I write a - (minus) inside a lstlisting it disappears after the compilation. Here is a minimal example:

\documentclass{article}

\usepackage{listings}
\usepackage{semantic}

\begin{document}
\begin{lstlisting}
->  
\end{lstlisting}
\end{document}

How do I get this fixed?

A similar thread already exists, but the solutions shown there do not work for my problem.

Bastian
  • 267
  • 1
  • 6

1 Answers1

3

Package semantic adds special treatment for some characters. In this example you can disable the behavior by \mathligsoff:

\documentclass{article}

\usepackage{listings}
\usepackage{semantic}

\begin{document}
\mathligsoff
\begin{lstlisting}
->
\end{lstlisting}
\mathligson
\end{document}

Result

The command can also be put into an init hook of lstlistings:

\documentclass{article}

\usepackage{listings}
\usepackage{semantic}

\makeatletter
\lst@AddToHook{Init}{\mathligsoff}
\makeatother

\begin{document}
\begin{lstlisting}
->  
\end{lstlisting}
$->$ and \lstinline|->|
\end{document}

Result

Heiko Oberdiek
  • 271,626