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.

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

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.