6
\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{listings}

\lstdefinestyle{General} {
    basicstyle=\small\ttfamily,
    breaklines=true
}

\lstset{style=General}

\begin{document}

\chapter{MyChapter}
\lstinline|(a + b) / c|.
\end{document}

This results in

enter image description here

As you can see the space after the closing parenthesis is missing. This is caused by the breaklines=true command. If I would remove it the space is visible. But I need this command. Is there a way to hold the spaces nevertheless?

8

The class and \chapter are not relevant. A minimal example would be

\documentclass{article}

\usepackage{listings}

\lstdefinestyle{General} {
    basicstyle=\small\ttfamily,
    breaklines=true,
}

\lstset{style=General}

\begin{document}

\lstinline|(a + b) / c|

\end{document}

that prints

enter image description here

Add the keepspaces option:

\documentclass{article}

\usepackage{listings}

\lstdefinestyle{General} {
    basicstyle=\small\ttfamily,
    breaklines=true,
    keepspaces,
}

\lstset{style=General}

\begin{document}

\lstinline|(a + b) / c|

\end{document}

enter image description here

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.