3

The answers of Using \lstinline inside a \item work rather nicely with the beamer class.

But, as pointed out by the following MCEs when \beamerdefaultoverlayspecification{<+->} is uncommented, they don't work if incremental overlay specifications are used: the item labels are not printed.

Is there a way to use \lstinline inside a \item in beamer class in case of incremental overlay specifications?

  • Martin's answer:

    \documentclass{beamer}
    
    \usepackage{listings}
    
    \makeatletter
    \let\orig@item\item
    
    \def\item{%
        \@ifnextchar{[}%
            {\lstinline@item}%
            {\orig@item}%
    }
    
    \begingroup
    \catcode`\]=\active
    \gdef\lstinline@item[{%
        \setbox0\hbox\bgroup
            \catcode`\]=\active
            \let]\lstinline@item@end
    }
    \endgroup
    
    \def\lstinline@item@end{%
        \egroup
        \orig@item[\usebox0]%
    }
    \makeatother
    
    \begin{document}
    \begin{frame}[fragile]
      \frametitle{Foo}
    The arguments of the function are:
    
    % \beamerdefaultoverlayspecification{<+->}
    \begin{description}
    \item[\lstinline!foo!]
        Name of the file \\[1cm] % other [ ] still work as normal!
        something
    \item[\lstinline!bar!]
    Permissions
    \item[\lstinline!%^$]_!]
    verbatim
    \end{description}
    \end{frame}
    \end{document}
    
  • Elrond's answer:

    \documentclass{beamer}
    
    \usepackage{listings}
    
    \newcommand*{\lstitem}[1]{
      \setbox0\hbox{\lstinline{#1}}
      \item[\usebox0]
    }
    
    \begin{document}
    \begin{frame}[fragile]
      \frametitle{Foo}
      The arguments of the function are:
    
      % \beamerdefaultoverlayspecification{<+->}
      \begin{description}
        \lstitem{foo}
        Name of the file
        \\[1cm] % other [ ] still work as normal!
        something
      \lstitem{bar}  Permissions
      \end{description}
    \end{frame}
    \end{document}
    
Denis Bitouzé
  • 9,652
  • 4
  • 27
  • 85
  • Can you post a complete MWE? Even with the contents of the linked posts, this doesn't seem to be complete. (Files are missing, I think, though I'm not certain how it is supposed to work exactly.) – cfr Dec 17 '17 at 22:57
  • @cfr Sorry, the MCEs based on Martin's and Elrond's answers were wrong indeed. That's fixed now. – Denis Bitouzé Dec 18 '17 at 06:07
  • 2
    Have a look at the explanation of what fragile does in Beamer's manual. I think that's where the impossibility of this lies. – cfr Dec 19 '17 at 00:16

0 Answers0