Please, compare next two listings inside a beamer
frame. The upper one is made with listings
and the second with tcblisting
(form tcolorbox
). Both use same source and listing options.
Following code shows that although latex
code is indented by 2 tabs, once tabs are converted to spaces (tab=2
), they are partially suppressed with gobble
(gobble=2
), but only in listings
output. tcblisitng
fails and all tabs are shown into the result. Is this a tcolorbox
known behavior or a bug? Do you know some way of suppressing indenting spaces with tcblisting
?
\documentclass{beamer}
\usepackage{lmodern}
\usepackage[listings]{tcolorbox}
\lstdefinestyle{mystyle}{language=[LaTeX]TeX,
basicstyle=\ttfamily,
texcsstyle=*\color{blue},
breaklines=true,
keywordstyle=\color{green!30!black},
commentstyle=\color{red},
morekeywords={},
otherkeywords={$,\{,\},[,],&},
backgroundcolor=\color{gray!30},
escapeinside=<>,
moretexcs={maketitle},
showtabs=true,
showspaces=true,
tabsize=2,
gobble=2
}
\begin{document}
\begin{frame}[fragile]
\frametitle{Listing}
\begin{lstlisting}[style=mystyle]
\documentclass{}
preamble
\begin{document}
document text
\end{document}
\end{lstlisting}
\begin{tcblisting}{listing options={style=mystyle}, listing only}
\documentclass{}
preamble
\begin{document}
document text
\end{document}
\end{tcblisting}
\end{frame}
\end{document}
Best Answer
Unfortunately,
gooble
really is ignored. This key has no effect on\lstinline
or\lstinputlisting
(taken from thelistings
manual) andtcblisting
uses\lstinputlisting
internally.The following links consider some tricks to circumvent the problem:
autogobble for lstinputlistings
How to extend the \lstinputlisting command
For the current MWE, this could be applied as the following:
Without
showspaces
this would look OK. Another option fortcblisting
would be to play with theleft
key to shift everything to the left.Hopefully,
\lstinputlisting
will supportgobble
some day.