I am trying to input r code using the listing package. However, at the moment my file will not compile and returns the following error:

! Too many }'s.
\color@endbox ->\color@endgroup \egroup

I have worked backwards and figured out that the error only occurs when I use a style file given to us by my department. I have copied the .sty file that causes the error and I have also attached an example that shows the error in action. You will notice if you take out the \usepackage[y4project]{edmaths} that the error will disappear.

I have searched but couldn't get the following fix to work. http://www.latex-community.org/forum/viewtopic.php?f=45&p=18575


\usepackage[y4project]{edmaths} %%%% REMOVE THIS TO FIX ERROR

\lstset{ %
  backgroundcolor=\color{white},   % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}
  basicstyle=\footnotesize,        % the size of the fonts that are used for the code
  breakatwhitespace=false,         % sets if automatic breaks should only happen at whitespace
  breaklines=true,                 % sets automatic line breaking
  captionpos=b,                    % sets the caption-position to bottom
  commentstyle=\color{mygreen},    % comment style
  deletekeywords={...},            % if you want to delete keywords from the given language
  escapeinside={\%*}{*)},          % if you want to add LaTeX within your code
  extendedchars=true,              % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
  frame=single,                    % adds a frame around the code
  keepspaces=true,                 % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
  keywordstyle=\color{blue},       % keyword style
  language=Octave,                 % the language of the code
  morekeywords={*,...},            % if you want to add more keywords to the set
  numbers=left,                    % where to put the line-numbers; possible values are (none, left, right)
  numbersep=5pt,                   % how far the line-numbers are from the code
  numberstyle=\tiny\color{mygray}, % the style that is used for the line-numbers
  rulecolor=\color{black},         % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
  showspaces=false,                % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
  showstringspaces=false,          % underline spaces within strings only
  showtabs=false,                  % show tabs within strings adding particular underscores
  stepnumber=2,                    % the step between two line-numbers. If it's 1, each line will be numbered
  stringstyle=\color{mymauve},     % string literal style
  tabsize=2,                       % sets default tabsize to 2 spaces
  title=\lstname                   % show the filename of files included with \lstinputlisting; also try caption instead of title

%  End of preamble

\author{TESTING }
\title{TEST FILE}

    Sig. level      & 1$\%$ & 5$\%$ & 10$\%$ \\ \hline
    $\tau$ & -3.90 & -3.34 & -3.04  \\ \hline

#include <stdio.h>
#define N 10
/* Block
 * comment */
int main()


Here is the .sty file for edmaths:

%%  Package `edmaths' (26.8.2008)
\ProvidesPackage{edmaths}[2007/02/05 Edinburgh maths thesis/report style v0.95]


% Set up the page size and margins %

\setlength{\paperheight}{297mm}    % A4 Paper
\setlength{\paperwidth}{210mm}     %
\setlength{\oddsidemargin}{14.6mm} %  Left/Inside: 4.0cm (rel. -1in)
\setlength{\evensidemargin}{-.4mm} %  Right/Outside: 2.5cm (rel. -1in)
\setlength{\topmargin}{-17.4mm}    % \
\setlength{\headheight}{6mm}       % | Top: 2.0cm (rel. -1in), out of which 6mm for the header
\setlength{\headsep}{6mm}          % /
\setlength{\textwidth}{145mm}      % Margins: 2.5cm + 4cm
% Textheight delayed until we know the line spacing.

% The following is removed in favour of the `report' class options "oneside/twoside".
%\@twosidefalse \@mparswitchfalse  % Single-sided by default

% Provide some fancy option        %

\newboolean{with-fourier}           % Use the `fourier' package for Adobe Utopia font
\newboolean{with-hyperref}          % Use the `hyperref' package for clickable links and bookmarks, all black
\newboolean{with-colour}            % Add sane colours to the hyperref links
\newboolean{with-fancyhdr}          % Use the `fancyhdr' package to provide header and footer

\ifthenelse{\isundefined{\degreetext}}{\newcommand{\degreetext}{Specify a degree option!}}{}

\DeclareOption{phd}{\renewcommand{\degreetext}{Doctor of Philosophy}}
\DeclareOption{firstyear}{\renewcommand{\degreetext}{First-Year Report\\Graduate School of Mathematics}}
\DeclareOption{secondyear}{\renewcommand{\degreetext}{Second-Year Report\\Graduate School of Mathematics}}
\DeclareOption{thirdyear}{\renewcommand{\degreetext}{Third-Year Report\\Graduate School of Mathematics}}
\DeclareOption{y4project}{\renewcommand{\degreetext}{Year 4 Project\\School of Mathematics}}
\DeclareOption{masterph}{\renewcommand{\degreetext}{Master of Philosophy}}
\DeclareOption{mastersc}{\renewcommand{\degreetext}{Master of Science by Research}}


%\DeclareOption{oneside}{\@twosidefalse \@mparswitchfalse}  % Single-sided by default
%\DeclareOption{twosides}{\@twosidetrue \@mparswitchtrue}


  { \RequirePackage{cmap}
  } {}

    \RequirePackage[pdftitle={\@title}, pdfauthor={\@author}, pdfcreator={PDFLaTeX with edmaths}, pdfpagelayout=OneColumn, colorlinks=true, linkcolor=black, urlcolor=black, citecolor=black]{hyperref}
      \hypersetup{linkcolor=Sepia, urlcolor=NavyBlue, citecolor=Sepia}
    } {}
  } {}

  } {}

% Set up the text body height      %

% For the text height, we calculate the largest number of lines that gives us no more than 4cm bottom margin.
% This depends on the line spacing, which we need first.


% Debug only: In the next line, \XXXfactor contains the number of lines on a text-only page.
%\newlength{\XXXunit}\setlength{\XXXunit}{1pt}\newlength{\XXXfactor}\setlength{\XXXfactor}{1pt + ((672pt - \topskip) / \baselineskip) * \XXXunit}
\newlength{\scratchlength}\setlength{\scratchlength}{\topskip + ((672pt - \topskip) / \baselineskip) * \baselineskip + \baselineskip}

% Make the title page etc          %

    \null\vskip 4.1cm
    {\Large\degreetext \par University of Edinburgh \par\@date \par}

  I declare that this thesis was composed by myself 
  and that the work contained therein is my own, 
  except where explicitly stated otherwise in the text.




    \Large\it #1

%% A special declaration for Year 4 reports
 This project report is submitted in partial fulfilment of the requirements for the degree of
  • Welcome to TeX.SX! I run your example and it runs fine without any error. Please, minimize the example to a minimal working example (MWE) and try an uptodate TeX distribution. Commented Mar 15, 2014 at 14:10
  • Heiko Oberdiek I am sorry. For some reason I put in the wrong MWE. I have now added an MWE that will work if you remove the edmaths.sty. The only thing I have changed is I have added in a table. It is the table environment and edmaths that is clashing.
    – user32330
    Commented Mar 15, 2014 at 14:26
  • 2
    No problem here. Delete all .aux files and recompile.
    – Werner
    Commented Mar 15, 2014 at 14:31
  • Werner. I'm afraid that doesn't fix the problem. Can I double check I am doing this correctly. I have a edmaths.sty in the same folder as Test.tex. Is this the correct way to do it? Mine only works when either: 1) I remove the edmath package or 2) I remove the table from the MWE
    – user32330
    Commented Mar 15, 2014 at 14:52
  • I get no error, too. What TeX distribution are you running? Can you make the example really minimal?
    – egreg
    Commented Mar 15, 2014 at 14:57

1 Answer 1


(don't vote I'll delete later but too long for a comment)

I get no error. Add \listfiles and then check the file dates in the list shown at the end of your run.

 *File List*
  report.cls    2007/10/19 v1.4h Standard LaTeX document class
  size12.clo    2007/10/19 v1.4h Standard LaTeX file (size option)
 amssymb.sty    2013/01/14 v3.01 AMS font symbols
amsfonts.sty    2013/01/14 v3.01 Basic AMSFonts support
 amsmath.sty    2013/01/14 v2.14 AMS math features
 amstext.sty    2000/06/29 v2.01
  amsgen.sty    1999/11/30 v2.0
  amsbsy.sty    1999/11/29 v1.2d
  amsopn.sty    1999/12/14 v2.01 operator names
  amsthm.sty    2004/08/06 v2.20
 edmaths.sty    2007/02/05 Edinburgh maths thesis/report style v0.95
    calc.sty    2007/08/22 v4.3 Infix arithmetic (KKT,FJ)
  ifthen.sty    2001/05/26 v1.1c Standard LaTeX ifthen package (DPC)
setspace.sty    2011/12/19 v6.7a set line spacing
   amscd.sty    1999/11/29 v2.0
listings.sty    2013/08/26 1.5b (Carsten Heinz)
  keyval.sty    1999/03/16 v1.13 key=value parser (DPC)
 lstmisc.sty    2013/08/26 1.5b (Carsten Heinz)
listings.cfg    2013/08/26 1.5b listings configuration
   color.sty    2005/11/14 v1.0j Standard LaTeX Color (DPC)
   color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
  pdftex.def    2011/05/27 v0.06d Graphics/color for pdfTeX
infwarerr.sty    2010/04/08 v1.3 Providing info/warning/error messages (HO)
 ltxcmds.sty    2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
lstlang1.sty    2013/08/26 1.5b listings language file
    umsa.fd    2013/01/14 v3.01 AMS symbols A
    umsb.fd    2013/01/14 v3.01 AMS symbols B
  omlcmr.fd    1999/05/25 v2.5h Standard LaTeX font definitions
  omscmr.fd    1999/05/25 v2.5h Standard LaTeX font definitions

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .