I would like to use listings to format bash commands in such a way that overly long lines are automatically broken with a backslash. I know about the prebreak option, but it appears as though it is impossible to pass a literal backslash character to prebreak.
I learned from this answer that I could specify backslashes with \textbackslash, but using it produces the following warning message:
LaTeX Font Warning: Font shape `OMS/cmtt/m/n' undefined
(Font) using `OMS/cmsy/m/n' instead for symbol `textbackslash' on input line 8.
While this still allows for document compilation, it looks like the \textbackslash somehow avoids being formatted according to the basicstyle option. As seen in the below example, listings is perfectly capable of correctly styling backslashes that are manually entered.
Is it possible to make listings automatically break long lines with a backslash that is correctly styled?
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\begin{document}
% Automatic line break
\begin{lstlisting}[basicstyle=\ttfamily,breaklines,breakatwhitespace,prebreak={\textbackslash}]
long string of text to test line breaking for the listings package
\end{lstlisting}
% Manual line break
\begin{lstlisting}[basicstyle=\ttfamily,breaklines,breakatwhitespace]
long string of text to test line breaking for the
listings package
\end{lstlisting}
\end{document}

\usepackage[T1]{fontenc}. – campa Nov 10 '20 at 12:41:-). But this is a question which pops up every once in a while so there is surely a duplicate somewhere. Alas, I have no time to search for it right now. – campa Nov 10 '20 at 12:47campasuggested... – MadyYuvi Nov 10 '20 at 13:08