%%%% Une précaution.
\ifhtml\else\hva@warn{html/hevea is for html mode !!!}\endinput\fi
%%%% package used by all packages
\input{plain.hva}
\newif\ififthen\ifthenfalse
\input{ifthen.hva}
%%%%%%%%%%%%%%%%%%%%%%%
%%Style-sheet support %
%%%%%%%%%%%%%%%%%%%%%%%
%% External/internal style declarations are accumulated into approriate
%% token registers
% Linking to external style sheets
\newtokens{\css@link}%
\newcommand{\addcssfile}[1]{\addtokens{\css@link}{#1}}%
\newcommand{\loadcssfile}[1]{\addcssfile{\@print{<}\@getprint{link rel="stylesheet" type=\char34 text/css\char34\@print{ }href=\char34#1\char34\char62\@print{
}}}}%
%%%%%%
% Styles definition in the <HEAD> element
\newtokens{\hevea@css}%
\newcommand{\addstyle}[1]{\addtokens{\hevea@css}{#1}}%
\newcommand{\newstyle}[2]{\addstyle{\@getprint{#1\char123#2\char125\@print{
}}}}%
\newif\ifexternalcss\externalcssfalse
%
%%Style attributes are normaly set through an indirection.
%% Ie the class of the BLOCK elt that translates environment 'env' is
%%    \'env'@class
\newcommand{\class@attr}[2]{\ife#1\else\@getprint{class="#1"#2}\fi}
\newcommand{\setenvclass}[3][]{#1\def\csname{}#2@class\endcsname{#3}}
\newcommand{\getenvclass}[1]{\csname{}#1@class\endcsname}
\newcommand{\envclass@attr}[2][]{\class@attr{\getenvclass{#2}}{#1}}
%% Packages
\input{packages.hva}
%%%%%% Spacing
\input{spaces.hva}
\input{latexcommon.hva}
%%% Basic symbols
%%% Logos
\def\TeX{\@print{T<sub>E</sub>X}}
\def\LaTeX{\@print{L<sup>A</sup>T<sub>E</sub>X}}
\def\LaTeXe{\mbox{\@print{L<sup>A</sup>T<sub>E</sub>X}~$2\epsilon$}}
\newcommand{\hevea}{\@print{H}{\@incsize{-1}\@print{<sup>E</sup>}}\@print{V}%
{\@incsize{-1}\@print{<sup>E</sup>}}\@print{A}}
\newcommand{\hacha}{\@print{H}{\@incsize{-1}\@print{<sup>A</sup>}}\@print{C}%
{\@incsize{-1}\@print{<sup>H</sup>}}\@print{A}}
\newcommand{\html}{html}
%%% HTML related stuff (TEX equivalents are in the hevea.sty file)
%separate opening & closing of a elements (for cleveref)
\newcommand{\@openlocref}[1]{{\@nostyle\@print{<a href="#}\@getprint{\@tr@url{#1}}\@print{">}}}
\newcommand{\@closelocref}{{\@nostyle\@print{</a>}}}
%usual a elements
\newcommand{\@doaelement}[3][]
{{\@nostyle\@print{<a }\@getprint{#1}\@getprint{#2}\@print{>}}{#3}{\@nostyle\@print{</a>}}}
\newcommand{\@nestedaelement}[3][]{\hva@warn{Suppressing nested a element}#3}
\newcommand{\@aelement}[3][]
{\bgroup%
\let\@aelement\@nestedaelement%
\let\@openlocref\@gooble%
\let\@closelocref\relax%
\@doaelement[#1]{#2}{#3}\egroup}
%high level, html vision
\newcommand{\ahref}[3][]{\@aelement[#1]{href="#2"}{#3}}
\newcommand{\ahrefurl}[2][]{\@aelement[#1]{href="#2"}{\texttt{#2}}}
\let\footahref\ahref
\newcommand{\mailto}[2][]{\@aelement[#1]{href="mailto:#2"}{#2}}
\newcommand{\imgsrc}[2][]
{\@print{<img src="}\@getprint{#2}\ifpedantic\@print{" alt="}\@getprint{#2}\fi
\ifthenelse{\equal{#1}{}}{\@print{"}}{\@print{" }\@getprint{#1}}\@print{>}}
%% Hyper-text references inside the document, internal usage
\newcommand{\@locref}[3][]{\@aelement[#1]{href="\@print{#}\@tr@url{#2}"}{#3}}
\newcommand{\@locname}[3][]{\@aelement[#1]{id="#2"}{#3}}
\newcommand{\@locnameref}[4][]{\@aelement[#1]{id="#2" href="\@print{#}\@tr@url{#3}"}{#4}}
%% Two exported commands
\let\ahrefloc\@locref
\let\aname\@locname
\newcommand{\anchor}[2][]{\@locname[#1]{#2}{}}
%% Html footer, header and prefix for titles
\newsavebox{\@htmlhead}
\newsavebox{\@htmlfoot}
\newsavebox{\@htmlprefix}
\newcommand{\htmlhead}[1]{\sbox{\@htmlhead}{#1}}
\newcommand{\htmlfoot}[1]{\sbox{\@htmlfoot}{#1}}
\newcommand{\htmlprefix}[1]{\sbox{\@htmlprefix}{#1}}
\AtEndDocument
{\@close@par{\@nostyle\@print{<!--HTMLFOOT-->
}}%
\usebox{\@htmlfoot}%
{\@nostyle\@print{<!--ENDHTML-->
}}}
%%%%% Footnotes, html dependant part
\newcommand{\@noteref}[4]{\@locnameref{#2#3}{#1#3}{#4}}
\newcommand{\@notepointer}[3]{\@locref{#1#2}{#3}}
\newcommand{\@notetextstyle}[1]
  {{\@nostyle\@print{<sup>}}#1{{\@nostyle\@print{</sup>}}}}
\newcommand{\@notenotestyle}[1]{{\@clearstyle{}#1}}
%Styling fotnote text: use div because of possible \par in it
\newcommand{\@open@footnotetext}{\@open{div}{class="footnotetext"}}
\newcommand{\@close@footnotetext}{\@close{div}}
\newstyle{.footnotetext}{margin:0ex; padding:0ex;}
\newstyle{div.footnotetext P}{margin:0px; text-indent:1em;}
%Other styles
\setenvclass{thefootnotes}{thefootnotes}
\setenvclass{dt-thefootnotes}{dt-thefootnotes}
\setenvclass{dd-thefootnotes}{dd-thefootnotes}
\setenvclass{footnoterule}{footnoterule}
\newstyle{.thefootnotes}{text-align:left;margin:0ex;}
\newstyle{.dt-thefootnotes}{margin:0em;}
\newstyle{.dd-thefootnotes}{margin:0em 0em 0em 2em;}
\newstyle{.footnoterule}{margin:1em auto 1em 0px;width:50\%;}
\newcommand{\footnoterule}{\@hr[\envclass@attr{footnoterule}]{}{}}
\newenvironment{thefootnotes}[2][]
  {\@out@par{{\@nostyle\@print{<!--BEGIN }\@getprint{#1}\@print{NOTES }\@getprint{\@footnotelevel}\@print{-->
}}}\footnoterule%
  \setlistclass{thefootnotes}%
  \begin{list}{}{\renewcommand{\makelabel}[1]{##1}}}
  {\end{list}\@out@par{{\@nostyle\@print{
<!--END NOTES-->
}}}}
%%% Captions html dependent part
\newstyle{.caption}
{padding-left:2ex; padding-right:2ex; margin-left:auto; margin-right:auto}
\setenvclass{caption}{caption}
\newenvironment{hva@capted}
  {\@open{div}{\envclass@attr{caption}}\begin{tabular}{p{\linewidth}}}
  {\end{tabular}\@close{div}}
%%% for HaChA
\newcounter{cuttingdepth}
\setcounter{cuttingdepth}{1}
%% Old cutdef/cutend, no footnote managment
\newcommand{\cutdef*}[2][]
{\@out@par{{\@nostyle\@print{<!--CUT DEF }#2\@print{ }#1\@print{ -->}}}}
\newcommand{\cutend*}
{\@out@par{{\@nostyle\@print{<!--CUT END -->
}}}}
%%% New cutdef/cutend, with footnote managment
\hva@newstack{@foot}
\newcommand{\cutdef}[2][]{%
\@footnotesub\@push@foot{\@footnotelevel}\flushdef{#2}%
\@out@par{{\@nostyle\@print{<!--CUT DEF }#2\@print{ }#1\@print{ -->}}}}
\newcommand{\cutend}{%
\footnoteflush{\@footnotelevel}%
\@out@par{{\@nostyle\@print{<!--CUT END -->
}}}%
\@endfootnotesub\@pop@foot{\@footnotelevel}}
%%%Close/Re-open toplevel pars
\newcommand{\@secbegin}{\@close@par}
\newcommand{\@secend}{{\@nostyle\@print{<!--SEC END -->}}\@open@par}
\newcommand{\@secanchor}{}
%{{\@nostyle\@print{<!--SEC ANCHOR }\@fmt@sec\@print{-->}}}
\newcommand{\cuthere}[2]{%
\@footnoteflush{#1}%
{\@out@par{{\@nostyle\@print{<!--TOC }\@getprint{#1}\@print{ }}%
{\@nostyle{}\@print{id="}\@getprint{\@sec@id@attr}\@print{" }}%
\begin{@norefs}#2\end{@norefs}{\@nostyle\@print{-->
}}}}}
\newcommand{\@hacha@arg}[2]
{{\@nostyle\@print{<arg }\@getprint{#1}\@print{>}{#2}\@print{</arg>}}}
\newenvironment{@cutflow}[2]
{\@out@par{\@printnostyle{<!--FLOW }%
\@hacha@arg{footer}{#1}%
\@hacha@arg{title}{#2}%
\@printnostyle{-->
}}}
{\@out@par{\@printnostyle{<!--END FLOW-->
}}}
\newenvironment{cutflow}[1]{\begin{@cutflow}{YES}{#1}}{\end{@cutflow}}
\newenvironment{cutflow*}[1]{\begin{@cutflow}{NO}{#1}}{\end{@cutflow}}
\newcommand{\cutname}[1]
{\@out@par{{\@nostyle\@print{<!--NAME }\@getprint{#1}\@print{-->
}}}}
\newcommand{\@link@arg}[2]
  {\ifthenelse{\equal{#2}{}}{}
  {\@hacha@arg{#1}{#2}}}
\newsavebox{\@toplinks}
\newcommand{\toplinks}[3]
  {\sbox{\@toplinks}
    {\@printnostyle{<!--LINKS }%
    \@link@arg{PREV}{#1}%
    \@link@arg{UP}{#2}%
    \@link@arg{NEXT}{#3}%
    \@printnostyle{-->
}}}
\newsavebox{\@linkstext}
\newcommand{\setlinkstext}[3]
  {\sbox{\@linkstext}
    {\@printnostyle{<!--SETENV }%
    \@link@arg{PREVTXT}{#1}%
    \@link@arg{UPTXT}{#2}%
    \@link@arg{NEXTTXT}{#3}%
    \@printnostyle{-->
}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Using style CLASSES with DIV for local style-setting   %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\newenvironment{divstyle}[1]
  {\@open{div}{\class@attr{#1}{}}}{\@close{div}}%
\newenvironment{cellstyle}[2]
  {\@open{table}{\class@attr{#1}{}}\@open{tr}{}\@open{td}{\class@attr{#2}{}}}
  {\@close{td}\@close{tr}\@close{table}}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Echoing to the image file %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\def\@iopt@def{!*!}
\newcommand{\@imageopt}[1][!*!]
{\def\@itmp{#1}\ifx\@itmp\@iopt@def\else\begin{toimage}[#1]\end{toimage}\fi}
\newcommand{\@imagearg}[1]{\begin{toimage}{#1}\end{toimage}}
\newcommand{\@imagecommand}[2]
  {\@forcecommand{#1}{\begin{toimage}#1\end{toimage}#2}}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   \maketitle (is no longer redefined by fancysection)		%
%   Thus defining different styles explicitly will have to 	%
%     be done using the respective classes :			%
%     .title     : table containing the title and supplements   %
%     .titlemain : h1 containing title name		        %
%     .titlerest : h3 containing other fields (author,date,etc.)%
%   'checkbox' now takes three instead of two arguments,        %
%     one for the class.					%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\newcommand{\title@tohaux}[1]
{\@auxdowrite{\@print{\@titleaux}\{\@subst{#1}\}
}}
\newstyle{.title}{margin:2ex auto;text-align:center}
\newstyle{.titlemain}{margin:1ex 2ex 2ex 1ex;}
\newstyle{.titlerest}{margin:0ex 2ex;}
\let\title@flush@hook\relax
\newcommand{\maketitle}{%
  \bgroup
  \newcommand{\checkcmd}[4]
    {\@ifundefined{@##3}{##4{No ##3 given}}
     {\@open{##1}{\class@attr{##2}{}}%
      \@fmt@title{\csname @##3\endcsname}%
      \@close{##1}}}%
  \@opencell{class=\@print{"title"}}{}{style=\@print{"padding:1ex"}}%
  \checkcmd{h1}{titlemain}{title}{\hva@warn}%
  \checkcmd{h3}{titlerest}{author}{\hva@warn}%
  \checkcmd{h3}{titlerest}{date}{\@gooble}%
  \@closecell%
  \egroup%
  \ifthenelse{\equal{\@footnotelevel}{document}}{}
  {\@footnotesub%
   \gdef\title@flush@hook{\@endfootnotesub\@footnoteflush@sticky{document}}}%
\let\maketitle\relax}%
%
%%%%%%%%%
% Maths %
%%%%%%%%%
\ifmathml
\input{html/symb-mathml.hva}
\else
\ifsymbtext\input{iso-text.hva}\else\input{iso-html.hva}\fi
\fi
\renewcommand{\&}{\ifraw\@print{&}\else\@print{&amp;}\fi}
\renewcommand{\textless}{\ifraw\@print{<}\else\@print{&lt;}\fi}
\renewcommand{\textgreater}{\ifraw\@print{>}\else\@print{&gt;}\fi}
%%%%%%%%%%%% Bibliography
\newcommand{\@bibtagstyle}{}
\newcommand{\@bibref}[3]
  {\@locref{#1}{\ifx#2\@empty\@verbarg{#1}\else#2\fi}\@bib@post{#3}}
\newsavebox{\@bibbox}
\newcommand{\@biblabel}[1]{\@locname{\bibtaghook{#1}}{\@bibtagstyle[\@bibread{\bibtaghook{#1}}]}}
%%% Environment document.
\newcommand{\@charset}{US-ASCII}
\newcommand{\@def@charset}[1]
{\renewcommand{\@charset}{#1}\@set@out@translator{mappings/#1.map}}
\newcommand{\@bodyargs}{}
\newcommand{\@htmlargs}{}
\newcommand{\@meta}
{\@print{<meta http-equiv="Content-Type" content="text/html; charset=}%
\@getprint{\@charset}%
\@print{">
<meta name="generator" content="hevea }%
\@getprint{\usebox{\@heveaversion}}\@print{">
}%
\ife\hevea@css\else
\ifexternalcss\loadcssfile{\hva@dump@css}\else
\@print{<style type="text/css">}
\hevea@css\@print{</style>
}\fi\fi
\ife\css@link\else\css@link\fi
\undef\hevea@css\undef\newstyle}
\newenvironment{document}{%
\@end{document}%
\@atbegindocument%
\@restartoutput\unskip%
\@print{<!DOCTYPE html>
}\@print{<html }\@getprint{\@htmlargs}\@print{>
<head>}
\@meta%
\@print{<title>}%
\ifu\@title\jobname\else
\@notags{\begin{@norefs}\let\@print@u\@print@u@default\@getprint{\@title}\end{@norefs}}
\fi
\@print{</title>
}%
\ifmathml\@print{<style type="text/css">
  math.centered { text-align: center}
</style>
}\fi
\@print{</head>
}%
\@print{<body }\@notags{\@bodyargs}\@print{>
}%
\@print{<!--HEVEA command line is: }\usebox{\@heveacomline}\@print{-->
}%
{\@nostyle\@print{<!--CUT STYLE }\hacha@style\@print{-->}}%
\ife\@htmlhead\else{\@nostyle\@print{<!--HTMLHEAD-->
}}%
\usebox{\@htmlhead}%
{\@nostyle\@print{<!--ENDHTML-->
}}\fi%
\ife\@htmlprefix\else\@printnostyle{<!--PREFIX }%
\@hacha@arg{}{\usebox{\@htmlprefix}}%
\@printnostyle{-->
}\fi%
\usebox{\@toplinks}\usebox{\@linkstext}%
\cutdef*[\thecuttingdepth]{\cuttingunit}%
\renewcommand{\addstyle}[1]{\hva@warn{\addstyle{} must be used in document preamble}}%
\@open@par%Open first paragraph
}{%
\@clearstyle\@footnoteflush{\@footnotelevel}\cutend*\title@flush@hook%
\@atenddocument%
\@final@footer%
\@clearstyle%
\@print{</body>
</html>
}\@raise@enddocument}
\newstyle{.center}{text-align:center;margin-left:auto;margin-right:auto;}%
\newstyle{.flushleft}{text-align:left;margin-left:0ex;margin-right:auto;}%
\newstyle{.flushright}{text-align:right;margin-left:auto;margin-right:0ex;}%
% Avoid consecutive tables being stuck together
\newstyle{div table}{margin-left:inherit;margin-right:inherit;margin-bottom:2px;margin-top:2px}
\newstyle{td table}{margin:auto;}
\newstyle{table}{border-collapse:collapse;}
\newstyle{td}{padding:0;}
\newstyle{.cellpadding0 tr td}{padding:0;}
\newstyle{.cellpadding1 tr td}{padding:1px;}
\newstyle{pre}{text-align:left;margin-left:0ex;margin-right:auto;}
\newstyle{blockquote}{margin-left:4ex;margin-right:4ex;text-align:left;}
%Paragraphs in table cells are special (close to latex rendering)
\newstyle{td p}{margin:0px;}
\setenvclass{center}{center}%
\newenvironment{center}{\@open{div}{\envclass@attr{center}}}{\@close{div}}
\setenvclass{flushleft}{flushleft}
\newenvironment{flushleft}
  {\@open{div}{\envclass@attr{flushleft}}}
  {\@close{div}}
\setenvclass{flushright}{flushright}%
\newenvironment{flushright}
  {\@open{div}{\envclass@attr{flushright}}}
  {\@close{div}}%
\newcommand{\centerline}[1]{\begin{center}#1\end{center}}
%%quotations env.
\setenvclass{quote}{quote}%
\newenvironment{quote}
{\@close{}\@open{blockquote}{\envclass@attr{quote}}}
{\@close{blockquote}\@open{}{}}%
\setenvclass{quotation}{quotation}%
\newenvironment{quotation}
{\@open{blockquote}{\envclass@attr{quotation}}}{\@close{blockquote}}
\newcommand{\centering}{\@insert{div}{\envclass@attr{center}}}
\newcommand{\raggedleft}{\@insert{div}{\envclass@attr{flushright}}}
\newcommand{\raggedright}{\@insert{div}{\envclass@attr{flushleft}}}
\newcommand{\rule}[3][]{\@printHR{}{}}%
%For figure & tables
\newcommand{\@open@quote}[1]{\@open{blockquote}{#1}}
\newcommand{\@close@quote}{\@close{blockquote}}
%%%%%%%%%%%%%%%% LaTeX 2.09 style declarations
\newenvironment{tt}{\@span{style="font-family:monospace"}}{}
\newenvironment{bf}{\@span{style="font-weight:bold"}}{}
\newenvironment{em}{\@style{em}}{}
\newenvironment{it}{\@span{style="font-style:italic"}}{}
\newenvironment{rm}{\@anti{\it,\bf,\em,\sf,\tt}}{}
\newenvironment{tiny}{\@fontsize{1}}{}
\newenvironment{footnotesize}{\@fontsize{2}}{}
\newenvironment{scriptsize}{\@fontsize{2}}{}
\newenvironment{small}{\@fontsize{2}}{}
\newenvironment{normalsize}{\@fontsize{3}}{}
\newenvironment{large}{\@fontsize{4}}{}
\newenvironment{Large}{\@fontsize{5}}{}
\newenvironment{LARGE}{\@fontsize{5}}{}
\newenvironment{huge}{\@fontsize{6}}{}
\newenvironment{Huge}{\@fontsize{7}\@span{style="font-size:150\%"}}{}
% dirty hack for size 7, blame w3c for making css and html size non-convertible
%%%%%% Colors
\newenvironment{purple}{\@fontcolor{purple}}{}
\newenvironment{black}{\@fontcolor{black}}{}
\newenvironment{silver}{\@fontcolor{silver}}{}
\newenvironment{gray}{\@fontcolor{gray}}{}
\newenvironment{white}{\@fontcolor{white}}{}
\newenvironment{maroon}{\@fontcolor{maroon}}{}
\newenvironment{red}{\@fontcolor{red}}{}
\newenvironment{fuchsia}{\@fontcolor{fuchsia}}{}
\newenvironment{green}{\@fontcolor{green}}{}
\newenvironment{lime}{\@fontcolor{lime}}{}
\newenvironment{olive}{\@fontcolor{olive}}{}
\newenvironment{yellow}{\@fontcolor{yellow}}{}
\newenvironment{navy}{\@fontcolor{navy}}{}
\newenvironment{blue}{\@fontcolor{blue}}{}
\newenvironment{teal}{\@fontcolor{teal}}{}
\newenvironment{aqua}{\@fontcolor{aqua}}{}
\def\cal{\ifmath\ifmathml\@style{font-family: cursive }%
\else\red\fi\else\red\fi}
\def\sf{\ifmath\ifmathml\@style{font-family: sans-serif }%
\else\@span{style="font-family:sans-serif"}\fi\else\@span{style="font-family:sans-serif"}\fi}
\def\sl{\ifmath\ifmathml\@style{font-family: fantasy; font-style: italic }%
\else\@span{style="font-style:oblique"}\fi\else\@span{style="font-style:oblique"}\fi}
\def\sc{\@span{style="font-variant:small-caps"}}%
%%%% LaTeX2e verbose declarations
\newenvironment{mdseries}{\@anti{\bf}}{}
\newenvironment{bfseries}{\bf}{}
\newenvironment{rmfamily}{\rm}{}
\newenvironment{sffamily}{\@anti{\tt}\sf}{}
\newenvironment{ttfamily}{\@anti{\sf}\tt}{}
\newenvironment{upshape}{\@anti{\it,\sl,\sc}}{}
\newenvironment{itshape}{\@anti{\sl,\sc}\it}{}
\newenvironment{slshape}{\@anti{\it,\sc}\sl}{}
\newenvironment{scshape}{\@anti{\it,\sl}\sc}{}
\newenvironment{normalfont}{\rm\mdseries\upshape}{}
%%%%%%%%%%%%%%%%
\def\textrm#1{\mbox{\rmfamily#1}}
\def\textup#1{\mbox{\upshape#1}}
\def\textmd#1{\mbox{\mdseries#1}}
\def\textnormal#1{\mbox{\normalfont#1}}
\def\texttt#1{\mbox{\ttfamily#1}}
\def\textit#1{\mbox{\itshape#1}}
\def\textbf#1{\mbox{\bfseries#1}}
\def\textsf#1{\mbox{\sffamily#1}}
\def\textsl#1{\mbox{\slshape#1}}
\def\textsc#1{\mbox{\scshape#1}}
\newcommand{\emph}[1]{\mbox{\em#1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  New implementation of \sc & \textsc using "small-caps" style. %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
%%%%%%%%%%%%%%% Multicolumns index formating
\newcommand{\setindexpos}[2]
{\providesavebox{\csname indexpos#1\endcsname}%
\sbox{\csname indexpos#1\endcsname}{\@nostyle #2}}
\newcommand{\getindexpos}[1]{\usebox{\csname indexpos#1\endcsname}}
\newcounter{indexcols}\setcounter{indexcols}{2}
\newcounter{indexcount}\newcounter{indexdepth}
\newcounter{indexbox}
\newcommand{\indexitem}
{\stepcounter{indexcount}%
\end{lrbox}%
\setindexpos{\theindexbox}{\theindexcount}%
\stepcounter{indexbox}%
\providesavebox{\csname indexbox\theindexbox\endcsname}%
\begin{lrbox}{\csname indexbox\theindexbox\endcsname}}
\newcommand{\indexspace}{\indexitem}
{\stepcounter{indexcount}}
\setenvclass{indexenv}{indexenv}
\setenvclass{li-indexenv}{li-indexenv}
\newenvironment{indexenv}
  {\setenvclass{itemize}{\getenvclass{indexenv}}%
   \setenvclass{li-itemize}{\getenvclass{li-indexenv}}%
   \stepcounter{indexdepth}%
%IF
   \ifthenelse{\value{indexdepth}>1}
%THEN
     {\begin{itemize}%
      \renewcommand{\indexitem}{\stepcounter{indexcount}\item}%
      \renewcommand{\indexspace}{\stepcounter{indexcount}\vspace*{2ex}}}
%ELSE
     {\setcounter{indexbox}{0}\setcounter{indexcount}{0}%
      \providesavebox{\csname indexbox0\endcsname}%
      \begin{lrbox}{\csname indexbox0\endcsname}}}
{\ifthenelse{\value{indexdepth}>1}
{\end{itemize}\addtocounter{indexdepth}{-1}}
{\end{lrbox}%
\setindexpos{\theindexbox}{\theindexcount}%
\stepcounter{indexbox}%
\addtocounter{indexdepth}{-1}\printindexboxes}}
\newcounter{indexwork}\newcounter{indexlimit}
\newcounter{indexlines}
\newboolean{spaceallowed}
\newcounter{indexclines}\newcounter{indexprev}\newcounter{indexnow}%
\newcommand{\printindexboxes}
{\setcounter{indexwork}{1}%
\setcounter{indexlimit}
  {(\value{indexcount}+\value{indexcols}-1)/\value{indexcols}}%
\setcounter{indexclines}{0}%
\setcounter{indexprev}{0}%
\setcounter{indexnow}{0}%
\begin{tabular}{*{\value{indexcols}}{X}}
\begin{itemize}
\whiledo{\value{indexwork}<\value{indexbox}}
{\setcounter{indexnow}{\pushint{\getindexpos{\theindexwork}}}%
\addtocounter{indexclines}{\value{indexnow}-\value{indexprev}}%
\ifthenelse{\equal{\usebox{\csname indexbox\theindexwork\endcsname}}{}}
{\ifthenelse{\boolean{spaceallowed}}{\vspace*{2ex}}{}}
{\item}%
\setboolean{spaceallowed}{true}%
\usebox{\csname indexbox\theindexwork\endcsname}%
\stepcounter{indexwork}%
\ifthenelse{\value{indexclines}>\value{indexlimit}}
  {\ifthenelse{\value{indexwork}<\value{indexbox}}
     {\end{itemize}&\begin{itemize}\setboolean{spaceallowed}{false}%
      \setcounter{indexclines}{0}}
     {}}%
  {}%
\setcounter{indexprev}{\value{indexnow}}}%
\end{itemize}\end{tabular}}
%%%%%% Default table attribute for array and tabular
\newcommand{\@table@attributes}{style="border-spacing:6px;border-collapse:separate" class="cellpading0"}
\newcommand{\@table@attributes@border}{style="border-spacing:0" class="cellpadding1"}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   Redefining \textoverline of latexcommon.hva			%
%   Here we can use HTML primitives				%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\newcommand{\overlinedbox}[1]%
     {{\@styleattr{span}{style="text-decoration:overline"}#1}}% 
\renewcommand{\textoverline}[1]{\overlinedbox{#1}}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   Redefining \fbox of latexcommon.hva	         		%
%   Here we can use HTML primitives				%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newstyle{.boxed}{border:1px solid black}
\newstyle{.textboxed}{border:1px solid black}
\NewcommandHtml{\@@boxed}[1]
{\@start@text\@open{table}{class="boxed"}\@open{tr}{}\@open{td}{}%
#1%
\@close{td}\@close{tr}\@close{table}\@end@text}
\NewcommandHtml{\@boxed}[1]{{\@styleattr{span}{class="textboxed"}#1}}
\RenewcommandHtml{\fbox}{\DisplayChoose\@@boxed\@boxed}
%%Style of bars
\def\@barsz{2px}
\def\@@barsz{4px}%2 x
\def\@@@barsz{6px}%3 x
\def\@@@@barsz{8px}%3 x
\newstyle{.vbar}
{border:none;width:\@barsz;background-color:black;}
\newstyle{.hbar}
{border:none;height:\@barsz;width:100\%;background-color:black;}
\newstyle{.hfill}
{border:none;height:1px;width:200\%;background-color:black;}
%%%Bars with HR
\newcommand{\@hfill}{{\@nostyle\@print{<hr class="hfill"}}}
\newcommand{\@hbar}[1][]
{{\@clearstyle\def\@tmp{#1}\@print{<hr class="hbar"}%
\@getprint{\ifx\@tmp\@empty\else{} #1\fi}\@print{>}}}
\newcommand{\@vbar}[1][]
{{\@clearstyle\def\@tmp{#1}\@print{<hr class="vbar"}%
\@getprint{\ifx\@tmp\@empty\else{} #1\fi}\@print{>}}}
%%Bars with div
\newcommand{\@@hbar}[1][]
{{\@clearstyle\def\@tmp{#1}%
\@open{div}{class="hbar"\ifx\@tmp\@empty\else{} #1\fi}\@force{div}}}
\newcommand{\@@vbar}[1][]
{{\@clearstyle\def\@tmp{#1}%
\@open{div}{class="vbar"\ifx\@tmp\@empty\else{} #1\fi}\@force{div}}}
%%Style of paragraphs
\ifverbd\newstyle{p}{border:1px solid gray}\fi
\ifverbd\newstyle{div}{border:1px dotted gray}\fi
%%Style of display
\def\@orange{\@print{#}FF8000}
\def\@magenta{fuchsia}
\def\@dtstyle{border-collapse:separate;border-spacing:\@barsz;width:auto;}
\def\@dcstyle{white-space:nowrap;padding:0px;}%;width:auto;}
\newstyle{.vdisplay}{\@dtstyle{} empty-cells:show; border:2px solid red;}
\newstyle{.vdcell}{\@dcstyle{} border:2px solid green;}
\newstyle{.display}{\@dtstyle{} border:none;}
\newstyle{.dcell}{\@dcstyle{} border:none;}
\newstyle{.dcenter}{margin:0ex auto;}
\newstyle{.vdcenter}{border:solid \@orange{} 2px; margin:0ex auto;}
%%% And we can get something similar for extensible arrows accents.
\newcommand{\@vd}{\ifverbd{}v\fi}
\newcommand{\@dclass}{class="\@vd{}display"}
\DeclareSymbolHtml{\hva@righthead}{X25B8}
\DeclareSymbolHtml{\hva@lefthead}{X25C2}
\DeclareSymbolHtml{\hva@uphead}{X25B4}
\DeclareSymbolHtml{\hva@downhead}{X25BE}
\DeclareSymbolHtml{\hva@lrt}{X25E2}
\DeclareSymbolHtml{\hva@llt}{X25E3}
\DeclareSymbolHtml{\hva@ult}{X25E4}
\DeclareSymbolHtml{\hva@urt}{X25E5}
\DeclareSymbolHtml{\hva@utr}{X25B2}
\DeclareSymbolHtml{\hva@dtr}{X25BC}
\newcommand{\@open@dcell}[1]
{\def\@tmp{#1}%
\@open{td}{class="\@vd{}dcell" \ifx\@tmp\@empty\else{} \@addstyle{text-align:center}{#1}\fi}}
\newcommand{\@close@dcell}{\@close{td}}
\newcommand{\d@cell}[2][]{\@open@dcell{#1}#2\@close@dcell}
\newcommand{\@open@display}
{\@open{table}{class="\@vd{}display" style="width:100\%;"}\@open{tr}{}}
\newcommand{\@close@display}{\@close{tr}\@close{table}}
\newcommand{\@open@sizer}{}
\newcommand{\@close@sizer}{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Generic positioning of extensible upper accent
%% Beware need to open display inside itemdisplays.
%% Need also to open two displays so as to avoid 100% to
%% mean all page width, in case command is alone in
%% display!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\@over@arrow}[3][2]
{\@open@sizer\@open@display%
#2%
\@close{tr}\@open{tr}{}%
\d@cell[colspan="#1"]{#3}%
\@close{tr}\@open{tr}{}%
\d@cell[colspan="#1"]{~}%
\@close@display\@close@sizer}
\newcommand{\textoverleftarrow}[1]
{\hva@warn{\overleftarrow outside display mode}#1}
\newcommand{\@overleftarrow}[1]
{\mathop{\@over@arrow
  {\d@cell[style="width:10\%"]{\hva@lefthead}%
   \d@cell[style="width:90\%"]{\@hbar}}
  {#1}}\intlimits}
\newcommand{\overleftarrow}{\DisplayChoose\@overleftarrow\textoverleftarrow}
\newcommand{\textoverrightarrow}[1]
{\hva@warn{\overrightarrow outside display mode}#1}
\newcommand{\@overrightarrow}[1]
{\mathop{\@over@arrow
  {\d@cell[style="width:90\%"]{\@hbar}\d@cell[style="width:10\%"]{\hva@righthead}}
  {#1}}\intlimits}
\newcommand{\overrightarrow}{\DisplayChoose\@overrightarrow\textoverrightarrow}
\newcommand{\textoverbrace}[1]
{\hva@warn{\overbrace in non-display mode}#1}
\newcommand{\@overbrace}[1]
{\mathop{\@over@arrow[5]
  {\d@cell[style="width:5\%"]{\hva@lrt}%
   \d@cell[style="width:40\%;"]{\@hbar}%
   \d@cell[style="width:10\%"]{\hva@utr}%
   \d@cell[style="width:40\%"]{\@hbar}%
   \d@cell[style="width:5\%"]{\hva@llt}}
  {#1}}}
\newcommand{\overbrace}{\DisplayChoose\@overbrace\textoverbrace}
\newcommand{\@under@arrow}[3][2]
{\@open@sizer\@open@display%
\d@cell[colspan="#1"]{~}\@close{tr}%
\@open{tr}{}\d@cell[colspan="#1"]{#3}\@close{tr}%
\@open{tr}{}#2%
\@close@display\@close@sizer}
\newcommand{\textunderbrace}[1]
{\hva@warn{\underbrace in non-display mode}#1}
\newcommand{\@underbrace}[1]
{\mathop{\@under@arrow[5]
  {\d@cell[style="width:5\%"]{\hva@urt}%
   \d@cell[style="width:40\%"]{\@hbar}%
   \d@cell[style="width:10\%"]{\hva@dtr}%
   \d@cell[style="width:40\%"]{\@hbar}%
   \d@cell[style="width:5\%"]{\hva@ult}}
  {#1}}}
\newcommand{\underbrace}{\DisplayChoose\@underbrace\textunderbrace}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%concrete minipage
\newstyle{.minipage}{text-align:left; margin-left:0em; margin-right:auto;}
\setenvclass{minipage}{minipage}
\newenvironment{@minipage}
{\@open{div}{class="\getenvclass{minipage}"}}
{\@close{div}}
%%%%%%%%margin par
\newstyle{.marginpar}
{border:solid thin black; width:20\%; text-align:left;}
\newstyle{.marginparleft}
  {float:left; margin-left:0ex; margin-right:1ex;}
\newstyle{.marginparright}
  {float:right; margin-left:1ex; margin-right:0ex;}
\newif\ifmarginright\marginrighttrue
\setenvclass{marginpar}{marginpar}
\setenvclass{marginparside}{marginparright}
\newcommand{\normalmarginpar}
  {\setenvclass{marginparside}{marginparright}\marginrighttrue}
\newcommand{\reversemarginpar}
  {\setenvclass{marginparside}{marginparleft}\marginrightfalse}
\newcommand{\hva@mtemp}{}
\newcommand{\marginpar}[2][]
{\def\hva@mtemp{#1}%
\@open{div}{class="\getenvclass{marginpar} \getenvclass{marginparside}"}%
\ifx\hva@mtemp\@empty%
#2%
\else\ifmarginright
#2%
\else
#1%
\fi\fi
\@close{div}}
%%%%%%%%Default env class for verbatim
\setenvclass{verbatim}{verbatim}
%%%%%% format theorems
\newcommand{\set@th@font}[1]{\def\th@font{#1}}
\let\th@font\em
\newstyle{.theorem}{text-align:left;margin:1ex auto 1ex 0ex;}
\newcommand{\set@th}[1]
{\global\let\csname#1@font\endcsname\th@font%
\setenvclass[\global]{#1}{theorem}}
\newenvironment{th@env}[3]
{\@open{div}{class="\getenvclass{#1}"}%
\refstepcounter{#2}\textbf{#3~\csname{}the#2\endcsname}%
\def\th@tmp{#1}\th@kont}
{\@close{div}}
\newcommand{\th@kont}[1][]
{\ifoptarg~\textbf{(#1)}\fi\quad\csname\th@tmp{}@font\endcsname}
%%%%%% Do not load hevea.hva again !
\def\csname hevea@loaded\endcsname{}
