TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm making Beamer presentation. How I can display LaTeX code inside presentation?

share|improve this question
up vote 22 down vote accepted

Either simply within the verbatim environment or more sophisticated with the listings package.

share|improve this answer
Remember that any frames containing a verbatim or lstlisting material must be passed the 'fragile' parameter, i.e. \begin{frame}[fragile] .... \end{frame} – LianTze Lim Oct 14 '10 at 6:52
And don't get scared when you get a "file ended while scanning" error, it means that the \end{frame} of a fragile frame is not at the beginning of a line (but should be). – Ulrich Schwarz Dec 4 '10 at 22:04

If you want the input LaTeX codes displayed together with their corresponding outputs side by side (left/right or top/bottom), use showexpl.sty. It is a really cool package.

There are 2 modes:

  1. the input code is inserted into your document, or
  2. the input code is imported from external file.


The following figure shows showexpl.sty in action:

alt text

And the corresponding code is given as follows: Note: I gave some comments in the code to make it clearer.


   justification=justified,%default: RaggedRight. Other options: justified, centering
   labelsep=quad%default:colon. Options: period, space, quad, newline
  {\typeout{***Successfully patched \protect\SX@codeInput***}}
  {\typeout{***ERROR! Failed to patch \protect\SX@codeInput***}}
    breaklines=true,%default : false 
  breakindent=10pt,%default: 20pt 
    linewidth=\linewidth,%default : \linewidth,
    basicstyle=\ttfamily\tiny,% cannot take arguments
    showspaces=false,%default false
    showstringspaces=false,%default: true
    frame=single,%default frame=none 
    % the following must be defined to make hacking work.
    framerule=0.4pt,%expand outward 
    framesep=3pt,%expand outward
    xleftmargin=3.4pt,%to make the frame fits in the text area. 
    xrightmargin=3.4pt,%to make the frame fits in the text area. 
    tabsize=2%,%default :8 only influence the lstlisting and lstinline.
    %explpreset below will affect LTX only.
                            vsep=\fboxsep%vertical space between formatted and input.


Thank you to those who never get tired of helping me.
Thank you to those who never get tired of helping me.
Thank you to those who never get tired of helping me.
Thank you to those who never get tired of helping me.
Thank you to those who never get tired of helping me.

\item $\displaystyle \lim_{x\to 8}\frac{1}{(x-8)^2}=+\;\rotatebox{90}{$8$}$
\item $\displaystyle \lim_{x\to 7}\frac{1}{(x-7)^2}=+\;\rotatebox{90}{$7$}$
\item $\displaystyle \lim_{x\to 6}\frac{1}{(x-6)^2}=+\;\rotatebox{90}{$6$}$
share|improve this answer

How about to use verbatiminput? If you have the LaTeX examples in a file?

\verbatiminput{ my_test.tex }
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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