[Tex/LaTex] Frame around minipage containing listing in beamer

beamerframedlistingsminipage

I am working on the sheets of a course on LaTeX and would like to have several sheets in which you see on the left an example of a source document and on the right its output. I have this working now with listings and minipage, but I also want a frame around the page of a fixed width and height.

what I have now is:

\documentclass{beamer}
\usepackage{listings}

\begin{document}

\begin{frame}[fragile]{The \LaTeX\ language}

% Source code:
\begin{columns}[T]
\column{0.45\textwidth}
\begin{center}
\LaTeX\ code:
%\begin{lrbox}\mylistingbox
\begin{minipage}[t][0.7\textheight]{\textwidth}
\begin{lstlisting}
An equation:
\[
  1 + 1 = 2
\]
\end{lstlisting}
\end{minipage}
%\end{lrbox}
%\fbox{\usebox\mylistingbox}
\end{center}

% Output
\column{0.45\textwidth}
\begin{center}
Output:
\fbox{
\begin{minipage}[t][0.7\textheight]{1\textwidth}
An equation:
\[
  1 + 1 = 2
\]
\end{minipage}}
\end{center}
\end{columns}
\end{frame}
\end{document}

This works, but only puts a frame around the right side (the output). If I try the same with \fbox{} on the left side it does not work.

How can I put a frame around the minipage with the listiting?

Best Answer

While this does not address you specific question, I would highly recommend that you consider using the showexpl pacakge which makes use of the listings package. This eliminates the duplication of the LaTeX code, so it is not as error prone.

To control the font use basicstyle=... to set it for the listings. The output font will be as per the rest of the document. If you want to adjust it just for the output of LTXexample you can use preset=... to specify commands to be executed before the sample code is typeset.

enter image description here

\documentclass{beamer}
\usepackage{xcolor}
\usepackage{showexpl}% already includes listings package

\usepackage{adjustbox}

\lstdefinestyle{demoLatexStyle}{
    basicstyle=\small\ttfamily,% control font of code
    preset=\small,% adjust font size of output
    numbers=left, numberstyle=\tiny, stepnumber=2, numbersep=5pt,
    frame=tlbr,
    pos=r,% want output on right
    backgroundcolor=\color{yellow!30},
    basicstyle=\ttfamily,
    width=0.50\linewidth,
}
\lstloadlanguages{[LaTeX]TeX}

\begin{document}

\begin{frame}[fragile]{The \LaTeX\ language}
\makebox[0.50\linewidth][c]{\LaTeX\ code:}%  Center titles over
\makebox[0.50\linewidth][c]{Output:}%        half the \linewidth

\begin{LTXexample}[style=demoLatexStyle]
An equation:
\[
  1 + 1 = 2
\]
\end{LTXexample}
\end{frame}
\end{document}