does anybody have a hack already to be able to put a listing environment
inside another, user-defined one ? The following example shows the
problem:
\documentclass{article}
\usepackage{listings}
\newenvironment{myenv}{%
\begin{lstlisting}[language=C]}{%
\end{lstlisting}}
\begin{document}
\begin{myenv}
int foo;
\end{myenv}
\end{document}
didier(pts/0)% latex minimal.tex 18:00 04/29/08
This is pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6)
%&-line parsing enabled.
entering extended mode
(./minimal.tex
LaTeX2e <2005/12/01>
Babel <v3.8h> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, arabic, farsi, croatian, ukrainian, russian, bulgarian, czech, slov
ak, danish, dutch, finnish, basque, french, german, ngerman, ibycus, greek, mon
ogreek, ancientgreek, hungarian, italian, latin, mongolian, norsk, icelandic, i
nterlingua, turkish, coptic, romanian, welsh, serbian, slovenian, estonian, esp
eranto, uppersorbian, indonesian, polish, portuguese, spanish, catalan, galicia
n, swedish, ukenglish, pinyin, loaded.
(/usr/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2005/09/16 v1.4f Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size10.clo))
(/usr/share/texmf-texlive/tex/latex/listings/listings.sty
(/usr/share/texmf-texlive/tex/latex/graphics/keyval.sty)
(/usr/share/texmf-texlive/tex/latex/listings/lstpatch.sty)
(/usr/share/texmf-texlive/tex/latex/listings/lstmisc.sty)
(/usr/share/texmf-texlive/tex/latex/listings/listings.cfg)) (./minimal.aux)
(/usr/share/texmf-texlive/tex/latex/listings/lstlang1.sty)
(/usr/share/texmf-texlive/tex/latex/listings/lstmisc.sty)
(/usr/share/texmf-texlive/tex/latex/base/omscmr.fd))
*X
*! Interruption.
<*>
? X
No pages of output.
Transcript written on minimal.log.
zsh: exit 1 latex minimal.tex
--
5th European Lisp Workshop at ECOOP 2008, July 7: http://elw.bknr.net/2008/
Didier Verna, did...@lrde.epita.fr, http://www.lrde.epita.fr/~didier
EPITA / LRDE, 14-16 rue Voltaire Tel.+33 (0)1 44 08 01 85
94276 Le Kremlin-Bicętre, France Fax.+33 (0)1 53 14 59 22 did...@xemacs.org
> Hello,
>
> does anybody have a hack already to be able to put a listing environment
> inside another, user-defined one ? The following example shows the
> problem:
See documentation of listings:
4.16 Environments
If you want to define your own pretty-printing environments, try the
following command. The syntax comes from LATEX’s \newenvironment.
\lstnewenvironment
--
Ulrike Fischer
Doesn't work either. OK, my minimal example was perhaps too minimal. I
need a listings environment inside another, not the other way around. It
is actually to put a listing inside a beamer block. Something like that:
\begin{block}<overlay>{title}
\begin{lstlisting}[all-sorts-of-options]
code...
\end{lstlisting}
\end{block}
I want a user-defined environment to do that, but it seems that listings
environments (whether explicit or created via \lstnewenvironment) don't
like to be put inside other ones.
--
5th European Lisp Workshop at ECOOP 2008, July 7: http://elw.bknr.net/2008/
Didier Verna, did...@lrde.epita.fr, http://www.lrde.epita.fr/~didier
EPITA / LRDE, 14-16 rue Voltaire Tel.+33 (0)1 44 08 01 85
94276 Le Kremlin-Bicêtre, France Fax.+33 (0)1 53 14 59 22 did...@xemacs.org
> Doesn't work either. OK, my minimal example was perhaps too minimal. I
> need a listings environment inside another, not the other way around. It
> is actually to put a listing inside a beamer block. Something like that:
>
> \begin{block}<overlay>{title}
> \begin{lstlisting}[all-sorts-of-options]
> code...
> \end{lstlisting}
> \end{block}
>
> I want a user-defined environment to do that, but it seems that listings
> environments (whether explicit or created via \lstnewenvironment) don't
> like to be put inside other ones.
And BTW, I can use \lstinputlisting instead of an environment (it
works in that case), but this is too boring for just a few lines of code.
--
5th European Lisp Workshop at ECOOP 2008, July 7: http://elw.bknr.net/2008/
Didier Verna, did...@lrde.epita.fr, http://www.lrde.epita.fr/~didier
EPITA / LRDE, 14-16 rue Voltaire Tel.+33 (0)1 44 08 01 85
94276 Le Kremlin-Bicętre, France Fax.+33 (0)1 53 14 59 22 did...@xemacs.org
This is all to do with catcodes, I think. I don't think it's possible
to nest lstlisting environments at all.
Joseph Wright
> I want a user-defined environment to do that, but it seems that listings
> environments (whether explicit or created via \lstnewenvironment) don't
> like to be put inside other ones.
>
\documentclass{beamer}%
\usepackage[T1]{fontenc}
\usepackage{xcolor,listings}
\pagestyle{empty}
\begin{document}
\defverbatim[colored]\lst{%
\begin{lstlisting}[basicstyle=\small\ttfamily]
foo
bar
baz
\end{lstlisting}
}
\begin{frame}[fragile]
\begin{block}<1->{title}
\lst
\end{block}
\end{frame}
\end{document}
Herbert
> \documentclass{beamer}%
> \usepackage[T1]{fontenc}
> \usepackage{xcolor,listings}
> \pagestyle{empty}
> \begin{document}
>
> \defverbatim[colored]\lst{%
> \begin{lstlisting}[basicstyle=\small\ttfamily]
> foo
> bar
> baz
> \end{lstlisting}
> }
> \begin{frame}[fragile]
> \begin{block}<1->{title}
> \lst
> \end{block}
> \end{frame}
>
> \end{document}
Hmmm. Nice way of saying RTFBM ! :-)
Thanks !
--
5th European Lisp Workshop at ECOOP 2008, July 7: http://elw.bknr.net/2008/
Didier Verna, did...@lrde.epita.fr, http://www.lrde.epita.fr/~didier
EPITA / LRDE, 14-16 rue Voltaire Tel.+33 (0)1 44 08 01 85
94276 Le Kremlin-Bicętre, France Fax.+33 (0)1 53 14 59 22 did...@xemacs.org
> Hmmm. Nice way of saying RTFBM ! :-)
But in fact, that doesn't make it very easy to /rilly/ write inline
code in your document. In the meantime, I figured a way to do that by
hacking something on top of the verbatim package...
The idea is to output the environment's contents into a temporary file,
and use \lstinputlisting afterwards.
There you go !
\documentclass{beamer}
\usepackage{listings}
\usepackage{verbatim}
\makeatletter
\newwrite\lstvrb@out
\newenvironment{ccode}{%
\begingroup
\@bsphack
\immediate\openout\lstvrb@out\jobname.lst
\let\do\@makeother\dospecials\catcode`\^^M\active
\def\verbatim@processline{%
\immediate\write\lstvrb@out{\the\verbatim@line}}%
\verbatim@start}{%
\immediate\closeout\lstvrb@out
\@esphack
\endgroup
\begin{block}{C Code}
\lstinputlisting[language=C]{\jobname.lst}
\end{block}}
\makeatother
\begin{document}
\begin{frame}[fragile]
\begin{ccode}
int foo (int bar)
{
return 3;
}
\end{ccode}
\end{frame}
\end{document}