2

I am trying to add some code to my document, but whenever there is a space inside a string in the code, it shows up with a bucket(?) thing. I have provided the code and the output below:

\documentclass[a4paper]{article}

\usepackage{listings}
\begin{document}

\section*{Code}
\begin{lstlisting}[language=python]
# comment
a = 24
print (a)
string = "some string"
\end{lstlisting}

\end{document}

space inside string inside lstlisting replaced by this symbol

1
  • You may be looking for the term "visible space character". Here's a discussion
    – Chris H
    Mar 14 at 16:06

1 Answer 1

7

This is not a bug, it is a feature! With your current settings, spaces inside a string will be visualized using this "bucket", as you call it. This can be especially helpful if you have more than one space.

If you do not want them you can disable them by setting showstringspaces=false, either only for your current listing (option 1) or for the whole document (option 2).

\documentclass[a4paper]{article}

\usepackage{listings}
%\lstset{showstringspaces=false} % option 1

\begin{document}
\section*{Code}
\begin{lstlisting}[
    language=python,
    showstringspaces=false, % option 2
]
# comment
a = 24
print (a)
string = "some string"
\end{lstlisting}
\end{document}

Result

You could even enable this for "normal" spaces, i.e. outside of strings, by setting showspaces=true, if you want to.

1
  • thanks for the clear answer! I have since learned that it is called an underbracket. But if I were to name it, it would be a hottub.
    – mudders
    Mar 22 at 18:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .