8

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?

2 Answers 2

8

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.)

6

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} 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.