Writing verbatim inside verbatim

More strange problems, still teaching LaTeX. So I wanted to teach people how to get text or code formatted exactly as they type it with the verbatim environment. This is the part of code I wanted to use as an example:

\begin{verbatim}
text inside a      verbatim environment
is printed \emph{exactly} as     you\\
type      it ! % no comment!
\end{verbatim}

What I usually do is I have a block that shows the code they have to write and then the result. And of course for showing the code they need to write, I use verbatim. So can you include verbatim inside verbatim?

Well, yes you can, but of course you cannot include \end{verbatim}, as this would be interpreted as ending the verbatim environment. So I had to add this separately afterwards, using \verb (inline verbatim). Voila:

\begin{block}{What you write}
\begin{verbatim}
\begin{verbatim}
text inside a      verbatim environment
is printed \emph{exactly} as     you\\
type      it ! % no comment!
\end{verbatim}
\verb|\end{verbatim}|
\end{block}

Now there’s only a small problem, namely that there is some spacing after the environment, so it seems like there is an empty line between the end of the verbatim text and the \end{verbatim}. For this example it doesn’t matter, I use it to show them that empty lines are also printed exactly as they are given.

But next example is how to include verbatim inside a beamer frame. The example code I wanted to show inside the usual verbatim environment:

\begin{frame}[fragile]
   \begin{verbatim}
      test
   \end{verbatim}
\end{frame}

So you see that here I don’t really want an empty line between \end{verbatim} and \end{frame}. So my final hacky solution jumped back up over that space after the environment:

\begin{block}{What you write}
\begin{verbatim}
\begin{frame}[fragile]
   \begin{verbatim}
      test
\end{verbatim}
\vspace{-0.9\baselineskip}
\verb|   \end{verbatim}|\\
\verb|\end{frame}|
\end{block}

Which works fine, but the more easy solution is probably this one (or use lstlisting or any other code-environment):

\begin{block}{What you write}
\verb|\begin{frame}[fragile]|\\
\verb|   \begin{verbatim}|\\
\verb|      test|\\
\verb|   \end{verbatim}|\\
\verb|\end{frame}|
\end{block}

Mini-titlepages

Another strange problem. I am teaching LaTeX and I usually have slides that say “write this” and “get this”, e.g., write \textbf{bold text} and get bold text.

So I wanted to do the same for the part where I teach beamer. Of course my slides are beamer slides, so I was curious what would happen if I simply include a title page or a table of content inside a minipage. Yes, it works, it inserts the part with the title respectively the table of contents. Of course what is missing is the frame layout, so I had to do a bit of adjusting there. But in the end I have a miniature version of the actual title page and table of content right there in the slide. This is how it works:

First, I used a minipage to get the frame aspect ratio right:

\begin{minipage}[c][0.7\textwidth][c]{\textwidth}
\end{minipage}

Around that a resizebox so that it comfortably fits onto my page below the code that explains how to do it, and an fbox to get some “frame feeling”.

\fbox{\resizebox{0.4\textwidth}{!}{
\begin{minipage}[c][0.7\textwidth][c]{\textwidth}
\end{minipage}
}}

And basically that’s it for the title page, only a bit more space below the text:

\fbox{\resizebox{0.4\textwidth}{!}{
\begin{minipage}[c][0.7\textwidth][c]{\textwidth}
\titlepage
\vfill
\end{minipage}
}}

For the table of contents I had to re-make the frame layout with the navigation bars and the frametitle. The theme is Madrid, which is pretty simple, so I only had to do a blue bar on top and another one at the bottom. For that I used a beamercolorbox which I guess is also used in the theme itself. The values for height and the rest are pure trial and error. I didn’t include the title, author, date etc. at the bottom, although that shouldn’t be too difficult.

\fbox{\resizebox{0.4\textwidth}{!}{
\begin{minipage}[c][0.7\textwidth][c]{\textwidth}
\vspace{-0.55\baselineskip}
\begin{beamercolorbox}[dp=1ex, ht=3ex, wd=1.065\textwidth]{frametitle}
\usebeamerfont{frametitle}Outline
\end{beamercolorbox}
\vspace{\baselineskip}
\vfill
\tableofcontents
\vfill
\begin{beamercolorbox}[ht=1.5ex, wd=1.065\textwidth]{frametitle}
\end{beamercolorbox}
\vspace{-0.6\baselineskip}
\end{minipage}
}}

Maybe not useful, but really cool to have on the slides!