3

I have a beamer class file, with a plenty of frames. Almost all frames need the option [fragile] because I frequently use \verb| | to illustrate codes. So I want the frame to be equipped with [fragile] globally so that I don't need to type the option manually.

Also, I want all the stuff inside verbatim(or possibly inside \texttt, but I prefer verbatim) to be grey-shaded, just as TeX exchange is doing now.

Here is a minimal working example. Can you please modifiy it to resolve the issue?

\documentclass{beamer}
\begin{document}
\begin{frame}[fragile] % I used [fragile] since \verb in frame yields an error.
\frametitle{fragile frame and shaded verbatim}
\begin{itemize}
\item
I'm using the \verb|beamer| class.
\item
 want to set the \texttt{\colorbox{gray}{frame}} environment to be appended with the option \texttt{\colorbox{gray}{fragile}}.
\item
I want to set the stuff in the \texttt{\colorbox{gray}{verbatim}} command to be shaded just like \TeX exchange does.
\item
An ugly solution : \texttt{\colorbox{gray}{\textbackslash code\_example}}
\end{itemize}
\end{frame}
\end{document}

MWE

1
  • 1
    the proposed duplicate seems legit. However the approach proposed there does not work precisely with the fragile option (see comments in the linked question) Mar 9, 2020 at 10:50

1 Answer 1

0

Following the approach proposed here, you should write:

\documentclass{beamer}

\newenvironment{xframe}[1][]
{\begin{frame}[fragile,environment=xframe,#1]}
{\end{frame}}

\begin{document}
    \begin{xframe}% fragile option no longer required
        \frametitle{fragile frame and shaded verbatim}
        \begin{itemize}
            \item
            I'm using the \verb|beamer| class.
            \item
             want to set the \texttt{\colorbox{gray}{frame}} environment to be appended with the option \texttt{\colorbox{gray}{fragile}}.
            \item
            I want to set the stuff in the \texttt{\colorbox{gray}{verbatim}} command to be shaded just like \TeX exchange does.
            \item
            An ugly solution : \texttt{\colorbox{gray}{\textbackslash code\_example}}
        \end{itemize}
    \end{xframe}
\end{document}

I'm marking this question as duplicate, though.

1
  • 1
    I didn't know that there is a question like this. Thanks. But do you have any opinion about shaded verbatim?
    – shyzealot
    Mar 16, 2020 at 14:38

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