# Incompatible color package and defining a xfloat environment -> “ Too many }'s”

I am pepping up a thesis. Among others I am using a package based on Modified UDO thesis by; Jose A. Flores, November 2011. Unfortunately, I cannot find the original. One part of the package seems to redefine the float definition and I boiled the error down to the following code. I created a small style file: (killer.sty) containing:

\def\@xfloat#1[#2]{\ifhmode \@bsphack\@floatpenalty -\@Mii\else
\@floatpenalty-\@Miii\fi\def\@captype{#1}\ifinner
\@parmoderr\@floatpenalty\z@
\else\@next\@currbox\@freelist{\@tempcnta\csname ftype@#1\endcsname
\@tfor \@tempa :=#2\do
}\global\count\@currbox\@tempcnta}\@fltovf\fi
\global\setbox\@currbox\vbox\bgroup
\def\baselinestretch{1}\@normalsize
\boxmaxdepth\z@
\hsize\columnwidth \@parboxrestore
}


Actually, I have no experience with TeX programming, but from my point of view braces and if-fi are ok. In the most simple case it compiles (pdflatex) and looks ok. If I put the color package, however, it produces following error messages:

mini.tex(16): Error: Too many }'s.
mini.tex(16): Error: LaTeX Error: \begin{document} ended by \end{figure}.
mini.tex(16): Error: Extra \endgroup.


A minimal non-working example looks like this (put your pdf figure): mini.tex

\documentclass[12pt,a4paper,twoside,openright]{report} %
%====
\usepackage{graphicx}
\usepackage{killer}
\usepackage{color}%this works if this line is commented
%====
\begin{document}
\begin{figure}[H]
\centering\includegraphics[width=1\columnwidth]{your.pdf}
\caption[]{Schematic representation}
\label{fig:yourFig}
\end{figure}
\end{document}


Why is this incompatible with color. I was expecting a lot, but not that.

(MikTex 2.9 on Win7 64, SP1)

• That is bizarre I had never heard of that class then someone asked about it yesterday, it uses definitions from an early version of latex2.09 so puts back your document over 25 years. – David Carlisle Dec 3 '14 at 17:30
• Truly bizarre, as these are definitely two independent incidents. – mikuszefski Dec 4 '14 at 9:36

The problem seems very similar to the one in Problems with TikZ when I change document class

The solution given there should work also for your setting:

\documentclass[12pt,a4paper,twoside,openright]{report} %
%====
\usepackage{graphicx}

% save a copy of \@xfloat
\makeatletter\let\latex@xfloat\@xfloat\makeatother
\usepackage{killer}

% redefine \@xfloat to have the intended behavior
\usepackage{etoolbox}
\makeatletter
\let\@xfloat\latex@xfloat
\makeatother

\usepackage{color}%this works if this line is commented
%====
\begin{document}
\begin{figure}
\centering\includegraphics[width=1\columnwidth]{your.pdf}
\caption[]{Schematic representation}
\label{fig:yourFig}
\end{figure}
\end{document}


(Don't use [H], you'll regret it if you do.)

If the bad code is in the class (I'll call it killer), then do

% save a copy of \@xfloat
\makeatletter\let\latex@xfloat\@xfloat\makeatother

\documentclass{killer}

\usepackage{graphicx}

% redefine \@xfloat to have the intended behavior
\usepackage{etoolbox}
\makeatletter
\let\@xfloat\latex@xfloat
\makeatother

\usepackage{color}%this works if this line is commented

\begin{document}
\begin{figure}
\centering\includegraphics[width=1\columnwidth]{your.pdf}
\caption[]{Schematic representation}
\label{fig:yourFig}
\end{figure}
\end{document}

• Not loading killer would be a better fix – David Carlisle Dec 3 '14 at 17:33
• @DavidCarlisle Of course! – egreg Dec 3 '14 at 17:33
• @DavidCarlisle and @egreg. I agree, not using it, is probably the best solution. Compiling a simple example with and without, I don't see a big difference anyway. So I guess deleting this part from the UDOthesis.sty is best (tested: keeps working when removed). Do you agree? Nevertheless, I am curious what it is actually doing. Is it only changing a few distances? I also realize now that only [h] but not [H] is handled. And why is this making problems with color? Luckily @mkunkel from the other post @DavidCarlisle referred to, is not using color. (yet?) – mikuszefski Dec 4 '14 at 9:10
• The workaround does the trick, although I use \documentclass{report} and \usepackage{killer}. But if I understand this correctly, this results in ignoring the \def\@xfloat part from killer completely. (see comment above) – mikuszefski Dec 4 '14 at 9:14
• @mikuszefski the latex format colour support needs extra groups to keep colour local to boxes, these \colour@begingroup \color@endgroup commands are set to \relax for compatibility with latex 2.09 (ie the 1980s) but made into groups by color package. But even if the grouping is fixed, because the code is based on a 1987 latex format it removes everything added since then. [!ht] feature, the code to add H possibly doesn't match, the code to check the float fits on the page is removed... You could just remove the float part, but the rest of that file is of a similar vintage... – David Carlisle Dec 4 '14 at 9:21