[pdftex] problem when using package color with floats

Heiko Oberdiek oberdiek at uni-freiburg.de
Fri Apr 13 13:33:01 CEST 2007


On Fri, Apr 13, 2007 at 02:07:16AM -0700, Bintu Vasudevan wrote:

> when i redefine the macro used for floats (including figures and tables)
> so that single spacing is used. My tex file compile and as work fine.
> 
> But when i want  to usepackage{color} is hangs througing with message:
> =============================================
> ! Too many }'s.
> \color at endbox ->\color at endgroup \egroup

Typical error message in case of wrong use of \setbox
that doesn't respect the color interface of LaTeX.
This isn't specific for pdfTeX at all, thus these mailing lists
are the wrong place.

> Here is Redefined the macro defined
> -----------------------------------------------------------------------------------------------------
>  % (Note \def\figure{\@float{figure}set single spacing} doesn't work
> %  because figure has an optional argument)
> \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
>        \multiply\@tempcnta\@xxxii\advance\@tempcnta\sixt@@n
>        \@tfor \@tempa :=#2\do
>             {\if\@tempa h\advance\@tempcnta \@ne\fi
>              \if\@tempa t\advance\@tempcnta \tw@\fi
>              \if\@tempa b\advance\@tempcnta 4\relax\fi
>              \if\@tempa p\advance\@tempcnta 8\relax\fi
>      }\global\count\@currbox\@tempcnta}\@fltovf\fi
>     \global\setbox\@currbox\vbox\bgroup
>     \def\baselinestretch{1}\@normalsize
>     \boxmaxdepth\z@
>     \hsize\columnwidth \@parboxrestore}
> -----------------------------------------------------------------------------------------------------

\setbox\@currbox\vbox\bgroup ... <color stuff> \egroup

The color stuff uses \aftergroup to reset the color.
However, in case of an unprotected \setbox, see above, these
stuff, delayed by \aftergroup, is executed *after* the box
is constructed and assigned by \setbox.

LaTeX uses an additional grouping level. Without \color the
group commands are no-ops (\relax), color redefines these
hooks as \begingroup and \endgroup.

Look at the original \@xfloat:
  ...
  \setbox\@currbox\color at vbox\normalcolor\vbox\bgroup
  ...

Without color:
  \color at vbox       = \relax
  \normalcolor      = \relax
  \color at endbox     = \relax
  \color at begingroup = \relax
  \color at endgroup   = \relax
With color:
  \color at vbox       = \vbox\bgroup\color at begingroup
  \normalcolor      = \let\current at color\default at color\set at color
  \color at endbox     = \color at endgroup\egroup
  \color at begingroup = \begingroup
  \color at endgroup   = \endgroup

Thus use either the LaTeX's higher level macros such as
  \savebox, \sbox, minipage, \parbox
or use the low level hook commands. The minimal requirement
for color is an additional grouping level:
  \setbox...=\vbox{\begingroup ...\endgroup}

Yours sincerely
  Heiko <oberdiek at uni-freiburg.de>
-- 


More information about the pdftex mailing list