3

This question already has an answer here:

Some keywords defined with the otherkeywords key are not formatted as expected when breaklines is set to true. Here is my MWE:

\documentclass[12pt, a4paper]{article}
\usepackage{listings}
\lstset{
  basicstyle=\itshape\ttfamily, 
  keywordstyle=\upshape,
}
\lstdefinestyle{syntax}{
  language=[ANSI]C,
  otherkeywords={(,)},
  breaklines=true,
}

\begin{document}
\begin{lstlisting}[style=syntax]
  const ( int | float ) text
\end{lstlisting}
\end{document}

The result looks something like this (but nicely monospaced...):

const ( int | float ) text

If I set breaklines=false, it looks as expected:

const ( int | float ) text

Am I missing something obvious? As for versions, "This is pdfTeX, Version 3.1415926-2.4-1.40.13 (MiKTeX 2.9)" on Windows (at work, they force me...).

marked as duplicate by jub0bs, Jesse, Masroor, Benedikt Bauer, Werner Jun 23 '14 at 16:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

Based on https://tex.stackexchange.com/a/149203/36296

\documentclass{article}
\usepackage{listings}
\usepackage{etoolbox}

\lstset{
    basicstyle=\itshape\ttfamily, 
    keywordstyle=\upshape,
}

\lstdefinestyle{syntax}{
    language=[ANSI]C,
    breaklines=true,
    otherkeywords={(,)},
}

\makeatletter
\patchcmd{\lsthk@SelectCharTable}{)}{`}{}{} 
\makeatother 

\begin{document} 
    \begin{lstlisting}[style=syntax]        
const ( int | float ) text 
    \end{lstlisting}               
\end{document}

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.