Debian Codegraph @

texmf-dist/source/generic/tex4ht/tex4ht-html5.tex

raw
1 % $Id: tex4ht-html5.tex 1788 2026-01-18 15:06:30Z karl $
2 % compile 3 times: latex tex4ht-moz
3 % or xhlatex tex4ht-moz "html,3,sections+"
4 %
5 % Copyright 2009-2026 TeX Users Group
6 % Copyright 2000-2009 Eitan M. Gurari
7 % Released under LPPL 1.3c+.
8 % See tex4ht-cpright.tex for license text.
9
10 %%%%%%%%%%%%%%%%%% load style files %%%%%%%%%%%%%%%%%%%%%%%%%%
11
12 \ifx \HTML\UnDef
13 \def\HTML{html5}
14 \def\CONFIG{\jobname}
15 \def\MAKETITLE{\author{Eitan M. Gurari}}
16 \def\next{\input mktex4ht.4ht \endinput}
17 \expandafter\next
18 \fi
19
20 \input{common.tex}
21 \input{tex4ht-cpright.tex}
22
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24 \chapter{Preamble}
25 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26
27 \<html5\><<<
28 % html5.4ht (|version), generated from |jobname.tex
29 % Copyright 2016-2026 TeX Users Group
30 |<TeX4ht copywrite|>
31 >>>
32
33
34
35
36
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 \chapter{Basic configurations}
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40
41
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 \section{HTML5 structure}
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45
46
47 \<configure html5 tex4ht\><<<
48 |<patch charset|>
49 \Configure{VERSION}{}
50 \Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
51 \Configure{HTML}{\HCode{<html lang="\Get:Language" xml:lang="\Get:Language" \html:xmlns>\Hnewline}}{\HCode{\Hnewline</html>}}
52 \Configure{@HEAD}{}
53 \Configure{@HEAD}{\HCode{<meta \use:charset />\Hnewline}}
54 \Configure{@HEAD}{\HCode{<meta name="generator" content="TeX4ht
55 (https://tug.org/tex4ht/)" />\Hnewline}}
56 \Configure{@HEAD}{\HCode{<meta name="viewport" content="width=device-width,initial-scale=1" />\Hnewline}}
57 \Configure{@HEAD}{\HCode{<link
58 rel="stylesheet" type="text/css"
59 href="\expandafter\csname aa:CssFile\endcsname" />\Hnewline}}
60 \Configure{@HEAD}
61 {\HCode{<meta name="src"
62 content="\jobname.tex"\xml:empty>\Hnewline}}
63 \:CheckOption{timestamp}\if:Option
64 \Configure{@HEAD}
65 {\HCode{<meta name="date"
66 content="\:today"\xml:empty>\Hnewline}}
67 \else
68 \Log:Note{To print a timestamp, use the command line option timestamp}
69 \fi
70 >>>
71
72 \section{Default CSS style}
73
74 This style fixes some common issues regarding size of sectioning commands,
75 background of generated images in the dark mode, or line lenght.
76
77
78 \<configure html5 tex4ht\><<<
79 \:CheckOption{nostyle}\if:Option
80 \else
81 \Log:Note{We use a default CSS style. Use the `nostyle' option if you want to use custom a CSS design}
82 \Css{body{
83 margin:1em auto;
84 max-width:80ch;
85 padding:0 .62em;
86 }}
87
88 \Css{h1,h2,h3,h4,h5 {
89 line-height:1.2;
90 }}
91 \Css{@media print{
92 body{
93 max-width:none
94 }
95 }}
96 \Css{.partHead, .likepartHead { font-size: 2em; }}
97 \Css{.chapterHead, .likechapterHead { font-size: 1.7411em; }}
98 \Css{.sectionHead, .likesectionHead { font-size: 1.5157em; }}
99 \Css{.subsectionHead, .likesubsectionHead { font-size: 1.3195em; }}
100 \Css{.subsubsectionHead, .likesubsubsectionHead { font-size: 1.1487em; }}
101
102 \Css{
103 @media (prefers-color-scheme: dark) {
104 img[src^="\jobname"]{filter: invert(1); }
105 }
106 }
107
108 \Css{
109 body {
110 background-color: Canvas;
111 color: CanvasText;
112 color-scheme: light dark;
113 }
114 }
115 \fi
116 >>>
117
118
119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 \section{Language and charset setting}
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122
123 Charset can be set using charset=charsetcode option for tex4ht.sty. It is saved in \verb|\a:charset| macro.
124 If charset oprion isn't used, \verb|\A:charset| is used instead. Bot of these macros store the charset information
125 in charset=name form. We need to add quotes around name in html5, thus the following macro.
126
127 \<patch charset\><<<
128
129 \def\:charset:quotes#1=#2.{
130 #1="#2"%
131 }
132 \def\use:charset{%
133 \expandafter\ifx\csname a:charset\endcsname\relax%
134 \expandafter\expandafter\expandafter\:charset:quotes\csname A:charset\endcsname.
135 \else%
136 \expandafter\expandafter\expandafter\:charset:quotes\csname a:charset\endcsname.
137 \fi
138 }
139 >>>
140
141
142 We can interfere the document language from \verb|\bbl@main@language| macro. It
143 is supported by both Babel and Polyglossia.
144
145 \<configure html5 tex4ht\><<<
146 \def\Declare:Language#1#2{%
147 \expandafter\gdef\csname rfclang#1\endcsname{#2}%
148 }
149 \def\Get:Language{%
150 \ifx\bbl@main@language\@undefined en-US%
151 \else%
152 \expandafter\ifdefined\csname rfclang\bbl@main@language\endcsname \csname rfclang\bbl@main@language\endcsname\fi%
153 \fi%
154 }
155
156 \Declare:Language{nil}{en}
157 \Declare:Language{UKenglish}{en}
158 \Declare:Language{USenglish}{en}
159 \Declare:Language{latex}{en}
160 \Declare:Language{acadian}{fr}
161 \Declare:Language{albanian}{sq}
162 \Declare:Language{american}{en}
163 \Declare:Language{amharic}{am}
164 \Declare:Language{arabic}{ar}
165 \Declare:Language{armenian}{hy}
166 \Declare:Language{australian}{en}
167 \Declare:Language{austrian}{de}
168 \Declare:Language{basque}{eu}
169 \Declare:Language{bengali}{bn}
170 \Declare:Language{brazilian}{pt}
171 \Declare:Language{brazil}{pt}
172 \Declare:Language{breton}{br}
173 \Declare:Language{british}{en}
174 \Declare:Language{bulgarian}{bg}
175 \Declare:Language{canadian}{en}
176 \Declare:Language{canadien}{fr}
177 \Declare:Language{catalan}{ca}
178 \Declare:Language{croatian}{hr}
179 \Declare:Language{czech}{cs}
180 \Declare:Language{danish}{da}
181 \Declare:Language{divehi}{dv}
182 \Declare:Language{dutch}{nl}
183 \Declare:Language{english}{en}
184 \Declare:Language{esperanto}{eo}
185 \Declare:Language{estonian}{et}
186 \Declare:Language{finnish}{f\/i}
187 \Declare:Language{francais}{fr}
188 \Declare:Language{french}{fr}
189 \Declare:Language{galician}{gl}
190 \Declare:Language{germanb}{de}
191 \Declare:Language{german}{de}
192 \Declare:Language{greek}{el}
193 \Declare:Language{hebrew}{he}
194 \Declare:Language{hindi}{hi}
195 \Declare:Language{hungarian}{hu}
196 \Declare:Language{icelandic}{is}
197 \Declare:Language{interlingua}{ia}
198 \Declare:Language{irish}{ga}
199 \Declare:Language{italian}{it}
200 \Declare:Language{kannada}{kn}
201 \Declare:Language{khmer}{km}
202 \Declare:Language{korean}{ko}
203 \Declare:Language{lao}{lo}
204 \Declare:Language{latin}{la}
205 \Declare:Language{latvian}{lv}
206 \Declare:Language{lithuanian}{lt}
207 \Declare:Language{lowersorbian}{dsb}
208 \Declare:Language{magyar}{hu}
209 \Declare:Language{malayalam}{ml}
210 \Declare:Language{marathi}{mr}
211 \Declare:Language{naustrian}{de}
212 \Declare:Language{newzealand}{en}
213 \Declare:Language{ngerman}{de}
214 \Declare:Language{norsk}{no}
215 \Declare:Language{norwegiannynorsk}{nn}
216 \Declare:Language{nynorsk}{no}
217 \Declare:Language{occitan}{oc}
218 \Declare:Language{oldchurchslavonic}{cu}
219 \Declare:Language{persian}{fa}
220 \Declare:Language{polish}{pl}
221 \Declare:Language{polutonikogreek}{el}
222 \Declare:Language{portuges}{pt}
223 \Declare:Language{portuguese}{pt}
224 \Declare:Language{romanian}{ro}
225 \Declare:Language{romansh}{rm}
226 \Declare:Language{russian}{ru}
227 \Declare:Language{samin}{se}
228 \Declare:Language{sanskrit}{sa}
229 \Declare:Language{scottish}{gd}
230 \Declare:Language{serbian}{sr}
231 \Declare:Language{serbo-croatian}{sh}
232 \Declare:Language{slovak}{sk}
233 \Declare:Language{slovene}{sl}
234 \Declare:Language{slovenian}{sl}
235 \Declare:Language{spanish}{es}
236 \Declare:Language{swedish}{sv}
237 \Declare:Language{tamil}{ta}
238 \Declare:Language{telugu}{te}
239 \Declare:Language{thai}{th}
240 \Declare:Language{tibetan}{bo}
241 \Declare:Language{turkish}{tr}
242 \Declare:Language{turkmen}{tk}
243 \Declare:Language{ukrainian}{uk}
244 \Declare:Language{uppersorbian}{hsb}
245 \Declare:Language{urdu}{ur}
246 \Declare:Language{vietnamese}{vi}
247 \Declare:Language{welsh}{cy}
248 >>>
249
250 Support for xml name spaces. It must be configured after
251 \verb|\begin{document}| in the configuration file.
252
253 \<configure html5 tex4ht\><<<
254 \edef\html:xmlns{}
255 \NewConfigure{xmlns}[2]{%
256 \ifx\relax#2\relax%
257 \edef\html:xmlns{}%
258 \else%
259 \edef\html:xmlns{\html:xmlns xmlns\ifx\relax#1\relax\else :#1\fi="#2"}%
260 \fi%
261 }
262 >>>
263
264 XMLNS for MathML is not necessary in HTML5, so we will disable it unhless the
265 mathmlxmlns option is used.
266
267 \<configure html5 tex4ht\><<<
268 \:CheckOption{mathmlxmlns}\if:Option\else
269 \:CheckOption{mathml}\if:Option%
270 \else\:CheckOption{mathml-}\fi%
271 \if:Option%
272 \Configure{math-xmlns}{}
273 \fi
274 \fi
275 >>>
276
277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278 \chapter{LaTeX and classes configurations}
279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280
281
282 \section{LaTeX}
283
284 \<configure html5 latex\><<<
285 |<tabular fixes|>
286 >>>
287
288 \section{Article, book and report classes}
289 \<configure html5 article\><<<
290 |<article,report,book|>
291 |<article,report|>
292 >>>
293
294 \<configure html5 book\><<<
295 |<article,report,book|>
296 >>>
297
298 \<configure html5 report\><<<
299 |<article,report,book|>
300 |<article,report|>
301 >>>
302
303 Shared configurations for base LaTeX classes.
304
305 \<article,report,book\><<<
306 |<figcaption|>
307 |<default thebibliography|>
308 >>>
309
310 Configurations that are shared only for article and report
311
312 \<article,report\><<<
313 |<abstract|>
314 >>>
315
316
317 \section{Configurations for Koma Script}
318
319 \<configure html5 scrartcl\><<<
320 |<scr article,report,book|>
321 >>>
322
323 \<configure html5 scrbook\><<<
324 |<scr article,report,book|>
325 >>>
326
327 \<configure html5 scrreprt\><<<
328 |<scr article,report,book|>
329 >>>
330
331 \<scr article,report,book\><<<
332 |<figcaption|>
333 |<default thebibliography|>
334 >>>
335
336 \section{Configurations for AMS classes}
337
338 \<configure html5 amsart\><<<
339 |<ams art,proc,book|>
340 >>>
341
342 \<configure html5 amsproc\><<<
343 |<ams art,proc,book|>
344 >>>
345
346 \<configure html5 amsbook\><<<
347 |<ams art,proc,book|>
348 >>>
349
350
351 \<ams art,proc,book\><<<
352 |<figcaption|>
353 |<default thebibliography|>
354 >>>
355
356 \section{Configurations for Memoir}
357
358 \<configure html5 memoir\><<<
359 |<figcaption|>
360 |<abstract|>
361 |<default thebibliography|>
362 >>>
363
364 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
365 \chapter{Packages configuration}
366 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
367
368 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
369 \chapter{Logical structure configurations}
370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
371
372 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
373 \section{Tables}
374 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
375
376 cellspacing and cellpading attributes are prohibited in html5
377
378 \<tabular fixes\><<<
379 \Configure{halignTB<>}{tabular}{\HCode{id="TBL-\TableNo" class="tabular"\Hnewline \GROUPS\Hnewline
380 }<>\HAlign}
381 >>>
382
383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
384 \section{Figures}
385 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
386
387 Configure HTML5 figures. Floats are converted as captions too.
388
389 \<figcaption\><<<
390 \Configure{float}
391 {\ifOption{refcaption}{}{\csname par\endcsname\ShowPar \leavevmode}}
392 {\:xhtml{\IgnorePar\EndP}\HCode{<figure class="float"\Hnewline>}}
393 {\ifvmode \IgnorePar \fi\EndP
394 \HCode{</figure>}\csname par\endcsname\ShowPar}
395
396 \ConfigureEnv{figure}
397 {\:xhtml{\IgnorePar\EndP}\HCode{<figure class="figure">\Hnewline}%
398 \bgroup \Configure{float}{\ShowPar}{}{}%
399 }
400 {\egroup
401 \:xhtml{\IgnorePar\EndP}\HCode{</figure>}|<try env inline par|>\par}
402 {}{}
403
404 \ConfigureEnv{figure*}
405 {\:xhtml{\IgnorePar\EndP}\HCode{<figure class="figure">\Hnewline}%
406 \bgroup \Configure{float}{\ShowPar}{}{}%
407 }
408 {\egroup
409 \:xhtml{\IgnorePar\EndP}\HCode{</figure>}|<try env inline par|>\par}
410 {}{}
411
412 \Css{figure.float, div.figure {margin-left: auto; margin-right: auto;}}
413 \Css{figure.figure {text-align:center;}}
414
415 \Configure{caption}{\:xhtml{\IgnorePar\EndP}\HCode{<figcaption class="caption" ><span class="id">}}
416 {: } {\HCode{</span><span \Hnewline class="content">}}
417 {\HCode{</span></figcaption>}\HCode{<!--tex4ht:label?:
418 \cur:th\:currentlabel\space-->}%
419 }
420 \Css{figcaption.caption {text-indent:-2em; margin-left:3em; margin-right:1em;
421 text-align:center;}}
422 \Css{figcaption.caption span.id{font-weight: bold; white-space: nowrap; }}
423 \Css{p + figcaption, img + figcaption{margin-top: 1em;}}
424 >>>
425
426 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
427 \section{Abstracts}
428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
429
430
431
432 \<abstract\><<<
433 \ConfigureEnv{abstract}
434 {\ifvmode\IgnorePar\fi\EndP\HCode{<section role="doc-abstract" class="abstract">\Hnewline}}
435 {\ifvmode\IgnorePar\fi\EndP\HCode{</section>}\par}{}{}
436
437 \Css{.abstract{margin:1em;}}
438 >>>
439
440 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
441 \section{Bibliography}
442 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
443
444
445 This configuration implements bibliographies according to recommendation
446 \Link[https://kb.daisy.org/publishing/docs/html/bibliographies.html]{}{}Accessible
447 Publishing Knowledge Base\EndLink. Thanks to Jeffrey Kuan for the suggestion.
448
449 Unfortunately, we cannot put the bibliography title inside the section,
450 because it would result in mismatched tags when we put chapters on separate pages.
451 See \Link[https://tex.stackexchange.com/q/747278/2891]{}{}this bug report\EndLink.
452
453
454 \<default thebibliography\><<<
455 % now configure thebibliography to produce a description list
456 % \en:bib insertes delimiters for particular bibitems. at the beginning, it is empty, as there is no need to insert the delimiter
457 % it is then defined to insert the delimiter after the first bibitem
458 \ConfigureList{thebibliography}%
459 {\ifvmode\IgnorePar\fi\EndP\HCode{<section role="doc-bibliography" class="thebibliography"><dl><dt>}\let\en:bib=\empty}% opening tags
460 {\ifvmode\IgnorePar\fi\EndP\HCode{</dd></dl></section>}} % closing tags
461 {\en:bib\def\en:bib{\ifvmode\IgnorePar\fi\HCode{</dd><dt>}}}% at the bibitem
462 {\HCode{</dt><dd>}}% after biblabel
463
464 \Css{.thebibliography dl {
465 display: grid;
466 grid-auto-columns: min-content 1fr;
467 grid-auto-flow: column;
468 }}
469
470 \Css{.thebibliography dt {
471 grid-column: 1;
472 margin-bottom: 0.5em;
473 }}
474 >>>
475
476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
477 \section{Utilities}
478 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
479
480 \<try env inline par\><<<
481 \ShowPar
482 >>>
483
484 \endinput