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 am getting 'Missing \endgroup inserted morekeywords={class,run}]' on line 16 while running the tex. I am using TexStudio. How can I solve that problem?

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{listings}

\begin{document}

\clearpage

\begin{tabular}{|p{.4\textwidth}|p{.4\textwidth}|}

\begin{lstlisting}[basicstyle={\scriptsize\ttfamily},
identifierstyle={\color{black}},
tabsize=2,language={[AspectJ]Java},
numbersep=8pt,numbers=left,xleftmargin=0.5cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords={class,run}]

class PrintHelloThread ext Thread {
    void run(Dummy x) {
        out.println("Hello world")
    }
}
class X ext ProxifiedObject {
    PrintHelloThread thread
    void main(X x) {
        x.thread := new PrintHelloThread;
        x.thread.start(0);
        x.thread.join(0);
    }
}
\end{lstlisting}
&
\begin{lstlisting}[
basicstyle={\scriptsize\ttfamily},
identifierstyle={\color{black}},
tabsize=2,
language={[AspectJ]Java},
numbersep=8pt,
numbers=left,
xleftmargin=0.5cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords ={class,run}
]
class PrintHelloThread ext Thread {
    void run(Dummy x) {
        out.println("Hello world")
    }
}
class X ext ProxifiedObject {
    PrintHelloThread thread
    void main(X x) {
        x.thread := new PrintHelloThread;
        x.thread.start(0);
        x.thread.join(0);
    }
}
\\
\end{lstlisting}
\end{tabular}
\end{document}
share|improve this question

2 Answers 2

up vote 5 down vote accepted

I get same errors on TexLive 2013. Use \ltset{} in preamble for setting parameters of lstlisting environment:

    \documentclass{article}
    \usepackage[T1]{fontenc}
    \usepackage[latin9]{inputenc}
    \usepackage{listings,xcolor}
    \lstset{
    basicstyle={\scriptsize\ttfamily},
    identifierstyle={\color{black}},
    tabsize=2,language={[AspectJ]Java},
    numbersep=4pt,numbers=left,xleftmargin=0.5cm,frame=tlbr,framesep=2pt,framerule=0pt
}
    \lstset{emph={%  
       class, run%
        },emphstyle={\color{red}}%
    }%
    \begin{document}

    \clearpage

    \begin{tabular}{|p{.6\textwidth}|p{.6\textwidth}|}

    \begin{lstlisting}[]
    class PrintHelloThread ext Thread {
        void run(Dummy x) {
            out.println("Hello world")
        }
    }
    class X ext ProxifiedObject {
        PrintHelloThread thread
        void main(X x) {
            x.thread := new PrintHelloThread;
            x.thread.start(0);
            x.thread.join(0);
        }
    }
    \end{lstlisting}
    &
    \begin{lstlisting}[]
    class PrintHelloThread ext Thread {
        void run(Dummy x) {
            out.println("Hello world")
        }
    }
    class X ext ProxifiedObject {
        PrintHelloThread thread
        void main(X x) {
            x.thread := new PrintHelloThread;
            x.thread.start(0);
            x.thread.join(0);
        }
    }
    \\
    \end{lstlisting}
    \end{tabular}
    \end{document}
share|improve this answer
1  
Thanks! do you know why some words are red color in the code snippet? –  Hakan Mar 31 at 22:23
    
I deleted my comments (don't ask: I confused myself:-) –  David Carlisle Mar 31 at 22:42
    
@Hakan, yourwelcome. For red words, please watch at second \ltset settings. –  ferahfeza Mar 31 at 22:55

Sorry I mislead you on the previous question, you need an extra set of {} to hide listings from the table mechanism:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{listings}
\usepackage{color}
\begin{document}

\clearpage

\begin{tabular}{|p{.4\textwidth}|p{.4\textwidth}|}
{\begin{lstlisting}[basicstyle={\scriptsize\ttfamily},
identifierstyle={\color{black}},
tabsize=2,language={[AspectJ]Java},
numbersep=8pt,numbers=left,xleftmargin=0.5cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords={class,run}]

class PrintHelloThread ext Thread {
    void run(Dummy x) {
        out.println("Hello world")
    }
}
class X ext ProxifiedObject {
    PrintHelloThread thread
    void main(X x) {
        x.thread := new PrintHelloThread;
        x.thread.start(0);
        x.thread.join(0);
    }
}
\end{lstlisting}}
&
{\begin{lstlisting}[
basicstyle={\scriptsize\ttfamily},
identifierstyle={\color{black}},
tabsize=2,
language={[AspectJ]Java},
numbersep=8pt,
numbers=left,
xleftmargin=0.5cm,frame=tlbr,framesep=2pt,framerule=0pt,
morekeywords ={class,run}
]
class PrintHelloThread ext Thread {
    void run(Dummy x) {
        out.println("Hello world")
    }
}
class X ext ProxifiedObject {
    PrintHelloThread thread
    void main(X x) {
        x.thread := new PrintHelloThread;
        x.thread.start(0);
        x.thread.join(0);
    }
}
\end{lstlisting}}
\end{tabular}
\end{document}
share|improve this answer
    
that's okay :) thanks! but \hline does not work properly. Have you tried by inserting them after starting tabular and before ending tabular ? –  Hakan Mar 31 at 22:53

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.