2

Trying to include a source-file into my latex document using the listings package, i got problems with the open box character. Using,

\usepackage{listings}
\lstset{language=Python}
\lstset{
numbers=left,
numberstyle={\small},
literate={␣}{**WHAT DO I INPUT HERE?**}1}
\begin{document}

enter image description here

I couldn't find anywhere the encoding of the open box character. What is it ?

  • If you are referring to the visible space character, it sits in slot 32 of the ttfamily font, as in \texttt{\char32}.. By the way, please provide a complete minimum working example (that compiles) so that we can better assist you. Welcome to the site. – Steven B. Segletes Jan 8 '19 at 11:54
1

If you are referring to the visible space character, it sits in slot 32 of the \ttfamily font, as in {\ttfamily\char32}.

\documentclass{article}
\usepackage{listings}
\lstset{language=Python}
\lstset{
numbers=left,
numberstyle={\small},
literate={␣}{{\ttfamily\char32}}1}
\begin{document}
\begin{lstlisting}
{
 Testing␣a␣visible␣space
}
\end{lstlisting}
\end{document}

enter image description here

Alternately, you can use \textvisiblespace, as in literate={␣}{\textvisiblespace}1.

\documentclass{article}
\usepackage{listings}
\lstset{language=Python}
\lstset{
numbers=left,
numberstyle={\small},
literate={␣}{\textvisiblespace}1}
\begin{document}
\begin{lstlisting}
{
 Testing␣a␣visible␣space
}
\end{lstlisting}
\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.