我正在准备一个beamer
演示文稿,并使用lstlisting
环境来输入 TeX 代码。我使用的代码大部分是从这里:
\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}}
我还想复制otherkeywords={$, \{, \}, \[, \]},
汤姆的这句话(又是在这里)。但是,它总是用该行给我错误消息。该代码有什么问题吗?
谢谢,马克斯
针对评论:发生错误我这样做:
\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}
otherkeywords={$, \{, \}, \[, \]},
如果我替换为, 则不会发生 otherkeywords={$},
答案1
嗯...显然,otherkeywords
如果morekeywords
以前没有使用过,你就不能使用它(这可能是设计使然,但我在文档中找不到对此的提及);所以只需添加选项即可morekeywords={}
解决问题:
\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}