Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have this LaTeX code:

    \lstset{
    language=Java,
    tabsize=8,
    keepspaces,
    extendedchars=true,
    rulecolor=\color{black},
    basicstyle=\footnotesize,
    aboveskip=5pt,
    upquote=true,
    columns=fixed,
    showstringspaces=false,
    extendedchars=true,
    breaklines=true,
    frame=single,
    showtabs=true,
    showspaces=false,
    showstringspaces=false,
}

\begin{frame}[fragile]
\begin{lstlisting}
    public class Teddy {
        public MethodName(String name, int var) {
             this.name = name;
        }
    }
\end{lstlisting}
\end{frame}

Beamer ignores my tabs inside the lstlisting because my frame is fragile. But I need it to be fragile, because I get the "Runaway Argument"-Exception, when there is no fragile.

What can I do, except importing the Lsting from an external file?

I don't want to define a new command for each source code listing, like proposed in this solution: How to prevent beamer.sty from removing the tab alignment of lstlisting.sty ?

share|improve this question
1  
Simply replace your tabs with spaces. This should be easily possible with a decent editor. –  Martin Scharrer Nov 5 '11 at 11:21
    
Hey! this works! Thank you :-P –  Tobi Nov 5 '11 at 16:34

1 Answer 1

up vote 1 down vote accepted

use it this way:

\documentclass{beamer}
\usepackage{listings}
    \lstset{
    language=Java,
    tabsize=8,
    keepspaces,
    extendedchars=true,
    rulecolor=\color{black},
    basicstyle=\footnotesize,
    aboveskip=5pt,
    upquote=true,
    columns=fixed,
    showstringspaces=false,
    extendedchars=true,
    breaklines=true,
    frame=single,
    showtabs=true,
    showspaces=false,
    showstringspaces=false,
}
\begin{document}
\defverbatim\lst{%
\begin{lstlisting}
    public class Teddy {
        public MethodName(String name, int var) {
            this.name = name;
        }
    }
\end{lstlisting}
}
\begin{frame}
\lst
\end{frame}
\end{document}

enter image description here

share|improve this answer
    
yea, gut then I have to define a command for every listing –  Tobi Nov 5 '11 at 16:29

Your Answer

 
discard

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.