7

I am trying the following:

\begin{frame}[fragile]{OCP en Exceptions}
``If you throw a checked exception from a method in your code and the
\verb!catch! is three levels above, \textit{you must declare that
  exception in the signature of each method between you and
  the \verb!catch!}''
\end{frame}

Somehow I can't use the verbatim text inside the italic block. How do I solve this the right way?

7

You can't use verbatim material inside another macros argument. The already mentioned cprotect package works around that, but I would call it overkill using it here. Simply use a font declaration inside a group instead of a font macro, i.e. {\itshape text \verb+$%^+ text} instead of \textit{text \verb+$%^+ text}.

Applied to your code example:

\begin{frame}[fragile]{OCP en Exceptions}
``If you throw a checked exception from a method in your code and the
\verb!catch! is three levels above, {\itshape you must declare that
  exception in the signature of each method between you and
  the \verb!catch!}''
\end{frame}

Also using verbatim only to get the font effect is a misuse. Simply use tt font directly! For often used real verbatim material I would recommend to define them as macros using \verbdef of the verbdef package. (There is also \Verbdef of my newverbs package if you need it in an expandable form, but normally this is not the case.)

5

Use cprotect package. More details, see the manual.

\documentclass{article}
\usepackage{cprotect}
\begin{document}
\cprotect\textit{\verb|\LaTeX| is one of my primary weapons}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.