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 preparing a beamer presentation and using the lstlisting environment in order to put in TeX code. I am using the following code which is largely copied from here:

\definecolor{lightgrey}{rgb}{0.9,0.9,0.9} % defining color for listing
\definecolor{darkgreen}{rgb}{0,0.6,0} % defining color for listing

\lstset{language=[LaTeX]TeX, texcsstyle=*\bf\color{blue},
numbers=left, breaklines=true, keywordstyle=\color{darkgreen},
commentstyle=\color{red}, otherkeywords={$}, frame=leftline,
tabsize=2, backgroundcolor=\color{lightgrey}}

I would like to also copy the otherkeywords={$, \{, \}, \[, \]}, line from tom (here again). However, it is always giving me error messages with that line. Is there something wrong with that code?

Thanks, Max

In response to the comment: The error occurs I do this:

\documentclass{beamer}

\usepackage{remreset}
\usepackage{comment} % end and begin comment
\usepackage{dtklogos} % for \BibTeX

\usepackage{listings} % display code on slides; don't forget [fragile] option after \begin{frame}
\usepackage{bera} % pause in listing
\usepackage{color}
\definecolor{lightgrey}{rgb}{0.9,0.9,0.9} % defining color for listing
\definecolor{darkgreen}{rgb}{0,0.6,0} % defining color for listing

\makeatletter
\@removefromreset{subsection}{section} % creates navigation circles for every slide not section
\makeatother
\setcounter{subsection}{1} % creates navigation circles for every slide not section

\usetheme{Frankfurt}
\setbeamercovered{transparent}

\lstset{language=[LaTeX]TeX,
texcsstyle=*\bf\color{blue},
numbers=left,
breaklines=true,
keywordstyle=\color{darkgreen},
commentstyle=\color{red},
otherkeywords={$, \{, \}, \[, \]},
frame=leftline,
tabsize=2,
backgroundcolor=\color{lightgrey},
escapeinside=||
}


\begin{document}


\begin{lstlisting}
    \title[Title]{An Introduction to \LaTeX}
    \subtitle[Event]{ABC}
    \author[Author]{XXX} 
    \institute[University]{XYZ University}
    \maketitle
\end{lstlisting}

\end{document}

I does not occur if I substitute otherkeywords={$, \{, \}, \[, \]}, with otherkeywords={$},

share|improve this question
    
I did a simple test with your snippet and the line you want to use and got no errors, so something else must be going on in your document. Please edit your question and add a complete and minimal document allowing us to reproduce the problem mentioned. –  Gonzalo Medina Jun 7 '12 at 14:13
    
Thanks, Gonzalo! I added a minimal document! –  MCB Jun 7 '12 at 14:38

1 Answer 1

up vote 5 down vote accepted

Hmmm... aparently, you cannot use otherkeywords if morekeywords hasn't been previously used (this could be by design but I couldn't find a mention of this in the documenation); so simply adding the option morekeywords={} solves the problem:

\documentclass{beamer}
\usepackage{remreset}
\usepackage{comment} % end and begin comment
\usepackage{dtklogos} % for \BibTeX
\usepackage{listings} % display code on slides; don't forget [fragile] option after \begin{frame}
\usepackage{bera} % change font
\usepackage{color}

\definecolor{lightgrey}{rgb}{0.9,0.9,0.9} % defining color for listing
\definecolor{darkgreen}{rgb}{0,0.6,0} % defining color for listing

\makeatletter
\@removefromreset{subsection}{section} % creates navigation circles for every slide not section
\makeatother
\setcounter{subsection}{1} % creates navigation circles for every slide not section

\usetheme{Frankfurt}
\setbeamercovered{transparent}

\lstset{language=[LaTeX]TeX,
texcsstyle=*\bf\color{blue},
numbers=left,
breaklines=true,
keywordstyle=\color{darkgreen},
commentstyle=\color{red},
morekeywords={},
otherkeywords={$,\{ ,\} , [ , ] },
frame=leftline,
tabsize=2,
backgroundcolor=\color{lightgrey},
escapeinside=||
}

\begin{document}

\begin{frame}[fragile]
\begin{lstlisting}
    \title[Title]{An Introduction to \LaTeX}
    \subtitle[Event]{ABC}
    \author[Author]{XXX} 
    \institute[University]{XYZ University}
    \maketitle
\end{lstlisting}
\end{frame}

\end{document}

enter image description here

share|improve this answer
    
Thanks, Gonzalo. I am a new users and you are really helping me out here! –  MCB Jun 7 '12 at 22:27
    
Do you know why \subtitle and \institute don't turn blue? –  MCB Jun 7 '12 at 22:29
    
@MCB yes; they are not standard keywords; they are defined only in some classes like beamer. You need to explicitly add them using moretexcs={subtitle,institute}, –  Gonzalo Medina Jun 7 '12 at 22:35
    
You are helping me out all day. Can I make amends somehow? Send you a few bugs via paypal or something like that? –  MCB Jun 7 '12 at 22:42
    
@MCB no problem at all; I enjoy hanging around here to relax from work ;-) just by up-voting good answers and accepting the ones that best solved your problems (as you have been doing) is more than enough! –  Gonzalo Medina Jun 7 '12 at 22:45

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.