27.1 Background Colors in HTML

The framed package does not work with TEX4ht. So we are not using it by redefining the ColoredBackground environment.

The basic idea is to wrap colored environments with a

<div class="clsENVIRONMENT"> ... </div>

pair and write out a line

div.clsENVIRONMNET{background-color:COLOR;}

to the CSS (cascaded style sheet) myalps.css.

In order to avoid having several identical CSS entries in myalps.css, we redefine the command \backgroundcolor... after it has been used once.

The addition of

\ifvmode\IgnorePar\fi\EndP

has been suggested by Eitan Gurari in order to avoid wrongly closed </p> in XHTML generation.

3314ht background colors 331  (327)
\renewenvironment{ColoredBackground}[1]%
  {\ifvmode\IgnorePar\fi\EndP
    \HCode{<div class="cls#1">}\csname background#1\endcsname{}}%
  {\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}

\def\@backgroundColor#1{%
  \expandafter\gdef\csname background#1\endcsname{}%
  \Configure{colorbox}%
    {\bgroup
      \let\A:color=\a:color
      \Configure{color}%
        {\let\a:color=\A:color \Configure{SetHColor}%
          {\Css{div.cls#1{background-color:\HColor;}}}}}%
    {\egroup}%
  \colorbox
}

Uses ColoredBackground 202.