2

When I use the babel package for Hebrew support, framed listings in the document look weird, same for listings with background color.

Any idea how to solve?

Here is a MWE:

\documentclass[]{article}
\usepackage[hebrew,english]{babel}
\usepackage{listings}
\usepackage{color}

\begin{document}

\section*{First Listing}
\begin{lstlisting}[]
this
is
a 
simple
listing
\end{lstlisting}

\section*{Second Listing}
\begin{lstlisting}[frame=single]
this
is
a 
simple
listing with frame
\end{lstlisting}

\section*{Third Listing}
\begin{lstlisting}[backgroundcolor=\color{red}]
this
is
a 
simple
listing with background color
\end{lstlisting}

\section*{Forth Listing}
\begin{lstlisting}[frame=single,backgroundcolor=\color{red}]
this
is
a 
simple
listing with frame and background color
\end{lstlisting}

\end{document}

The result is: enter image description here

Thanks.

1 Answer 1

2

hebrew changes \everypar and listings doesn't like this. You can reset the original definition at the begin of the listing:

Side-remark: you can make better frames and backgrounds with tcolorbox.

\documentclass[]{article}
\usepackage[hebrew,english]{babel}
\usepackage{listings}
\usepackage{color}

\makeatletter
\lst@AddToHook{PreInit}{\let\everypar\o@everypar }
\makeatother
\begin{document}
\section*{First Listing}
\begin{lstlisting}[]
this
is
a
simple
listing
\end{lstlisting}

\section*{Second Listing}
\begin{lstlisting}[frame=single]
this
is
a
simple
listing with frame
\end{lstlisting}

\section*{Third Listing}
\begin{lstlisting}[backgroundcolor=\color{red}]
this
is
a
simple
listing with background color
\end{lstlisting}

\section*{Forth Listing}
\begin{lstlisting}[frame=single,backgroundcolor=\color{red}]
this
is
a
simple
listing with frame and background color
\end{lstlisting}
\end{document}

enter image description here

1
  • @UlrikeFischery our answer solved by problem, thanks! (will look into tcolorbox) Commented Oct 11, 2018 at 9:08

You must log in to answer this question.

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