3

I'm creating (beamer) slides explaining the basics of using LaTeX. For this purpose I would like to illustrate how some source code

\documentclass{article}
\title{My first paper}
\begin{document}
...

looks like. That is, I'd like to compile some LaTeX code using the article document class and display it on my slide (without manually compiling a separate document and then including the produced pdf). What's the best/easiest way of achieving this?

At first look the showexpl package or similar look like they might work, but it breaks beamer when including things like \section in the sample code, and things like \title display beamer-style.

1 Answers1

3

tcolorbox is a nice way to show source code and its output along site. Now your question is about showing the output without the source as you want to "skipping some lines for brevity".

My suggestion would be to use firstline=24, lastline=42 to select the lines, that you want to show, but if you insist to not show the source:

% !TeX program = txs:///arara
% arara: pdflatex: {shell: yes}
\documentclass{article}
\usepackage[most]{tcolorbox}

\begin{document}

\begin{tcblisting}{
          listing options={%
            style=tcblatex,
            firstline=0,
            lastline=0
          },
          listing and comment,
          pdf comment,
          compilable listing,
          run pdflatex,
          lower separated=false,
          top=-\baselineskip
        }

\documentclass{article}
\title{Theory of Everything}
\begin{document}
\maketitle
\end{document}
\end{tcblisting}

\end{document}

enter image description here

  • Thanks, that's pretty much what I want - however I still can't get it to compile (! Package pgfkeys Error: I do not know the key '/tcb/pdf comment ...). Must be something with my latex setup, but no idea what (using pdflatex). – Henning Koehler May 05 '17 at 21:47
  • @HenningKoehler pdflatex is fine, I used it for the above example, too. Which tex distribution do you have? Which version of tcolorbox? – samcarter_is_at_topanswers.xyz May 05 '17 at 21:50
  • The answers to that would be This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian) and Package: tcolorbox 2014/02/06 version 2.70 text color boxes. Essentially the defaults for Ubuntu 14.04. (which I'm not planning to upgrade anytime soon). – Henning Koehler May 06 '17 at 22:36
  • @HenningKoehler https://tex.stackexchange.com/questions/1092/how-to-install-vanilla-texlive-on-debian-or-ubuntu – samcarter_is_at_topanswers.xyz May 07 '17 at 10:07