% $Id: tex4ht-html5.tex 1716 2025-07-06 20:00:56Z michal_h21 $
% compile 3 times: latex tex4ht-moz
% or xhlatex tex4ht-moz "html,3,sections+"
%
% Copyright 2009-2025 TeX Users Group
% Copyright 2000-2009 Eitan M. Gurari
% Released under LPPL 1.3c+.
% See tex4ht-cpright.tex for license text.
%%%%%%%%%%%%%%%%%% load style files %%%%%%%%%%%%%%%%%%%%%%%%%%
\ifx \HTML\UnDef
\def\HTML{html5}
\def\CONFIG{\jobname}
\def\MAKETITLE{\author{Eitan M. Gurari}}
\def\next{\input mktex4ht.4ht \endinput}
\expandafter\next
\fi
\input{common.tex}
\input{tex4ht-cpright.tex}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Preamble}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\<<<
% html5.4ht (|version), generated from |jobname.tex
% Copyright 2016-2025 TeX Users Group
|
>>>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Basic configurations}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{HTML5 structure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\<<<
|
\Configure{VERSION}{}
\Configure{DOCTYPE}{\HCode{\Hnewline}}
\Configure{HTML}{\HCode{\Hnewline}}{\HCode{\Hnewline}}
\Configure{@HEAD}{}
\Configure{@HEAD}{\HCode{\Hnewline}}
\Configure{@HEAD}{\HCode{\Hnewline}}
\Configure{@HEAD}{\HCode{\Hnewline}}
\Configure{@HEAD}{\HCode{\Hnewline}}
\Configure{@HEAD}
{\HCode{\Hnewline}}
\:CheckOption{timestamp}\if:Option
\Configure{@HEAD}
{\HCode{\Hnewline}}
\else
\Log:Note{To print a timestamp, use the command line option timestamp}
\fi
>>>
\section{Default CSS style}
This style fixes some common issues regarding size of sectioning commands,
background of generated images in the dark mode, or line lenght.
\<<<
\:CheckOption{nostyle}\if:Option
\else
\Log:Note{We use a default CSS style. Use the `nostyle' option if you want to use custom a CSS design}
\Css{body{
margin:1em auto;
max-width:80ch;
padding:0 .62em;
}}
\Css{h1,h2,h3,h4,h5 {
line-height:1.2;
}}
\Css{@media print{
body{
max-width:none
}
}}
\Css{.partHead, .likepartHead { font-size: 2em; }}
\Css{.chapterHead, .likechapterHead { font-size: 1.7411em; }}
\Css{.sectionHead, .likesectionHead { font-size: 1.5157em; }}
\Css{.subsectionHead, .likesubsectionHead { font-size: 1.3195em; }}
\Css{.subsubsectionHead, .likesubsubsectionHead { font-size: 1.1487em; }}
\Css{
@media (prefers-color-scheme: dark) {
img[src^="\jobname"]{filter: invert(1); }
}
}
\Css{
body {
background-color: Canvas;
color: CanvasText;
color-scheme: light dark;
}
}
\fi
>>>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Language and charset setting}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Charset can be set using charset=charsetcode option for tex4ht.sty. It is saved in \verb|\a:charset| macro.
If charset oprion isn't used, \verb|\A:charset| is used instead. Bot of these macros store the charset information
in charset=name form. We need to add quotes around name in html5, thus the following macro.
\<<<
\def\:charset:quotes#1=#2.{
#1="#2"%
}
\def\use:charset{%
\expandafter\ifx\csname a:charset\endcsname\relax%
\expandafter\expandafter\expandafter\:charset:quotes\csname A:charset\endcsname.
\else%
\expandafter\expandafter\expandafter\:charset:quotes\csname a:charset\endcsname.
\fi
}
>>>
We can interfere the document language from \verb|\bbl@main@language| macro. It
is supported by both Babel and Polyglossia.
\<<<
\def\Declare:Language#1#2{%
\expandafter\gdef\csname rfclang#1\endcsname{#2}%
}
\def\Get:Language{%
\ifx\bbl@main@language\@undefined en-US%
\else%
\expandafter\ifdefined\csname rfclang\bbl@main@language\endcsname \csname rfclang\bbl@main@language\endcsname\fi%
\fi%
}
\Declare:Language{nil}{en}
\Declare:Language{UKenglish}{en}
\Declare:Language{USenglish}{en}
\Declare:Language{latex}{en}
\Declare:Language{acadian}{fr}
\Declare:Language{albanian}{sq}
\Declare:Language{american}{en}
\Declare:Language{amharic}{am}
\Declare:Language{arabic}{ar}
\Declare:Language{armenian}{hy}
\Declare:Language{australian}{en}
\Declare:Language{austrian}{de}
\Declare:Language{basque}{eu}
\Declare:Language{bengali}{bn}
\Declare:Language{brazilian}{pt}
\Declare:Language{brazil}{pt}
\Declare:Language{breton}{br}
\Declare:Language{british}{en}
\Declare:Language{bulgarian}{bg}
\Declare:Language{canadian}{en}
\Declare:Language{canadien}{fr}
\Declare:Language{catalan}{ca}
\Declare:Language{croatian}{hr}
\Declare:Language{czech}{cs}
\Declare:Language{danish}{da}
\Declare:Language{divehi}{dv}
\Declare:Language{dutch}{nl}
\Declare:Language{english}{en}
\Declare:Language{esperanto}{eo}
\Declare:Language{estonian}{et}
\Declare:Language{finnish}{f\/i}
\Declare:Language{francais}{fr}
\Declare:Language{french}{fr}
\Declare:Language{galician}{gl}
\Declare:Language{germanb}{de}
\Declare:Language{german}{de}
\Declare:Language{greek}{el}
\Declare:Language{hebrew}{he}
\Declare:Language{hindi}{hi}
\Declare:Language{hungarian}{hu}
\Declare:Language{icelandic}{is}
\Declare:Language{interlingua}{ia}
\Declare:Language{irish}{ga}
\Declare:Language{italian}{it}
\Declare:Language{kannada}{kn}
\Declare:Language{khmer}{km}
\Declare:Language{korean}{ko}
\Declare:Language{lao}{lo}
\Declare:Language{latin}{la}
\Declare:Language{latvian}{lv}
\Declare:Language{lithuanian}{lt}
\Declare:Language{lowersorbian}{dsb}
\Declare:Language{magyar}{hu}
\Declare:Language{malayalam}{ml}
\Declare:Language{marathi}{mr}
\Declare:Language{naustrian}{de}
\Declare:Language{newzealand}{en}
\Declare:Language{ngerman}{de}
\Declare:Language{norsk}{no}
\Declare:Language{norwegiannynorsk}{nn}
\Declare:Language{nynorsk}{no}
\Declare:Language{occitan}{oc}
\Declare:Language{oldchurchslavonic}{cu}
\Declare:Language{persian}{fa}
\Declare:Language{polish}{pl}
\Declare:Language{polutonikogreek}{el}
\Declare:Language{portuges}{pt}
\Declare:Language{portuguese}{pt}
\Declare:Language{romanian}{ro}
\Declare:Language{romansh}{rm}
\Declare:Language{russian}{ru}
\Declare:Language{samin}{se}
\Declare:Language{sanskrit}{sa}
\Declare:Language{scottish}{gd}
\Declare:Language{serbian}{sr}
\Declare:Language{serbo-croatian}{sh}
\Declare:Language{slovak}{sk}
\Declare:Language{slovene}{sl}
\Declare:Language{slovenian}{sl}
\Declare:Language{spanish}{es}
\Declare:Language{swedish}{sv}
\Declare:Language{tamil}{ta}
\Declare:Language{telugu}{te}
\Declare:Language{thai}{th}
\Declare:Language{tibetan}{bo}
\Declare:Language{turkish}{tr}
\Declare:Language{turkmen}{tk}
\Declare:Language{ukrainian}{uk}
\Declare:Language{uppersorbian}{hsb}
\Declare:Language{urdu}{ur}
\Declare:Language{vietnamese}{vi}
\Declare:Language{welsh}{cy}
>>>
Support for xml name spaces. It must be configured after
\verb|\begin{document}| in the configuration file.
\<<<
\edef\html:xmlns{}
\NewConfigure{xmlns}[2]{%
\ifx\relax#2\relax%
\edef\html:xmlns{}%
\else%
\edef\html:xmlns{\html:xmlns xmlns\ifx\relax#1\relax\else :#1\fi="#2"}%
\fi%
}
>>>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{LaTeX and classes configurations}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{LaTeX}
\<<<
|
>>>
\section{Article, book and report classes}
\<<<
|
|
>>>
\<<<
|
>>>
\<<<
|
|
>>>
Shared configurations for base LaTeX classes.
\<<<
|
|
>>>
Configurations that are shared only for article and report
\<<<
|
>>>
\section{Configurations for Koma Script}
\<<<
|
>>>
\<<<
|
>>>
\<<<
|
>>>
\<<<
|
|
>>>
\section{Configurations for AMS classes}
\<<<
|
>>>
\<<<
|
>>>
\<<<
|
>>>
\<<<
|
|
>>>
\section{Configurations for Memoir}
\<<<
|
|
|
>>>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Packages configuration}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Logical structure configurations}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Tables}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cellspacing and cellpading attributes are prohibited in html5
\<<<
\Configure{halignTB<>}{tabular}{\HCode{id="TBL-\TableNo" class="tabular"\Hnewline \GROUPS\Hnewline
}<>\HAlign}
>>>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Figures}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Configure HTML5 figures. Floats are converted as captions too.
\<<<
\Configure{float}
{\ifOption{refcaption}{}{\csname par\endcsname\ShowPar \leavevmode}}
{\:xhtml{\IgnorePar\EndP}\HCode{}}
{\ifvmode \IgnorePar \fi\EndP
\HCode{}\csname par\endcsname\ShowPar}
\ConfigureEnv{figure}
{\:xhtml{\IgnorePar\EndP}\HCode{\Hnewline}%
\bgroup \Configure{float}{\ShowPar}{}{}%
}
{\egroup
\:xhtml{\IgnorePar\EndP}\HCode{}|\par}
{}{}
\ConfigureEnv{figure*}
{\:xhtml{\IgnorePar\EndP}\HCode{\Hnewline}%
\bgroup \Configure{float}{\ShowPar}{}{}%
}
{\egroup
\:xhtml{\IgnorePar\EndP}\HCode{}|\par}
{}{}
\Css{figure.float, div.figure {margin-left: auto; margin-right: auto;}}
\Css{figure.figure {text-align:center;}}
\Configure{caption}{\:xhtml{\IgnorePar\EndP}\HCode{}}
{: } {\HCode{}}
{\HCode{}\HCode{}%
}
\Css{figcaption.caption {text-indent:-2em; margin-left:3em; margin-right:1em;
text-align:center;}}
\Css{figcaption.caption span.id{font-weight: bold; white-space: nowrap; }}
\Css{p + figcaption, img + figcaption{margin-top: 1em;}}
>>>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Abstracts}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\<<<
\ConfigureEnv{abstract}
{\ifvmode\IgnorePar\fi\EndP\HCode{\Hnewline}}
{\ifvmode\IgnorePar\fi\EndP\HCode{}\par}{}{}
\Css{.abstract{margin:1em;}}
>>>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Bibliography}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
This configuration implements bibliographies according to recommendation
\Link[https://kb.daisy.org/publishing/docs/html/bibliographies.html]{}{}Accessible
Publishing Knowledge Base\EndLink. Thanks to Jeffrey Kuan for the suggestion.
Unfortunately, we cannot put the bibliography title inside the section,
because it would result in mismatched tags when we put chapters on separate pages.
See \Link[https://tex.stackexchange.com/q/747278/2891]{}{}this bug report\EndLink.
\<<<
% now configure thebibliography to produce a description list
% \en:bib insertes delimiters for particular bibitems. at the beginning, it is empty, as there is no need to insert the delimiter
% it is then defined to insert the delimiter after the first bibitem
\ConfigureList{thebibliography}%
{\ifvmode\IgnorePar\fi\EndP\HCode{- }\let\en:bib=\empty}% opening tags
{\ifvmode\IgnorePar\fi\EndP\HCode{
}} % closing tags
{\en:bib\def\en:bib{\ifvmode\IgnorePar\fi\HCode{}}}% at the bibitem
{\HCode{}}% after biblabel
\Css{.thebibliography dl {
display: grid;
grid-auto-columns: min-content 1fr;
grid-auto-flow: column;
}}
\Css{.thebibliography dt {
grid-column: 1;
margin-bottom: 0.5em;
}}
>>>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Utilities}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\<<<
\ShowPar
>>>
\endinput