|
| 1 | +% tufte.cfg - TeX4ht configuration for Tufte-LaTeX to Tufte-CSS HTML conversion |
| 2 | +% Based on: https://tex.stackexchange.com/questions/570630/can-a-tufte-latex-file-output-tufte-css-html |
| 3 | +% Reference: https://edwardtufte.github.io/tufte-css/ |
| 4 | + |
| 5 | +\Preamble{xhtml} |
| 6 | +\Configure{AddCss}{tufte.css} |
| 7 | + |
| 8 | +% Helper macro to close current paragraph |
| 9 | +\def\endparagraph{\ifvmode\IgnorePar\fi\EndP} |
| 10 | + |
| 11 | +% Configure body to use article wrapper (tufte-css convention) |
| 12 | +\Configure{@BODY}{\endparagraph\HCode{<article>}} |
| 13 | +\Configure{@/BODY}{\endparagraph\HCode{</article>}} |
| 14 | + |
| 15 | +% Configure sections (Tufte LaTeX makes \section and \subsection behave like starred versions) |
| 16 | +\Configure{likesection} |
| 17 | +{\endparagraph\HCode{<section>}}{\endparagraph\HCode{</section>}} |
| 18 | +{\HCode{<h2 class="chapterHead">}}{\HCode{</h2>}\par\ShowPar} |
| 19 | + |
| 20 | +\Configure{likesubsection} |
| 21 | +{\endparagraph\HCode{<section>}}{\endparagraph\HCode{</section>}} |
| 22 | +{\HCode{<h3 class="subsectionHead">}}{\HCode{</h3>}\par\ShowPar} |
| 23 | + |
| 24 | +% Simple table of contents - will be populated by JavaScript |
| 25 | +\renewcommand\tableofcontents{% |
| 26 | + \endparagraph% |
| 27 | + \HCode{<nav id="toc" class="toc"><h2>Contents</h2><ul id="toc-list"></ul></nav>}% |
| 28 | + \HCode{<script src="toc.js"></script>}% |
| 29 | +} |
| 30 | + |
| 31 | +\makeatletter |
| 32 | + |
| 33 | +% Configure title page |
| 34 | +\renewcommand{\maketitle}{% |
| 35 | + \begingroup% |
| 36 | + \endparagraph\HCode{<h1>}\@title\HCode{</h1>}% |
| 37 | + \HCode{<p class="subtitle">}\@author\HCode{</p>}% |
| 38 | + \HCode{<p class="subtitle">}\@date\HCode{</p>}% |
| 39 | + \endgroup |
| 40 | +} |
| 41 | + |
| 42 | +% Configure image dimensions |
| 43 | +\Configure{Gin-dim}{} |
| 44 | +\Css{img { |
| 45 | + max-width: 100\%; |
| 46 | + height: auto; |
| 47 | +}} |
| 48 | + |
| 49 | +% Fix soul package compatibility (for \allcaps, \smallcaps) |
| 50 | +\@ifpackageloaded{soul}{% |
| 51 | +\renewcommand{\allcaps}[1]{\MakeTextUppercase{#1}}% |
| 52 | +\renewcommand{\smallcaps}[1]{{\scshape\MakeTextLowercase{#1}}}% |
| 53 | +\renewcommand{\textsc}[1]{\textcaps{#1}}% |
| 54 | +}{} |
| 55 | + |
| 56 | +% Configure sidenotes with tufte-css checkbox toggle pattern |
| 57 | +\long\def\@tufte@sidenote[#1][#2]#3{% |
| 58 | + \stepcounter\@mpfn% |
| 59 | +\bgroup% |
| 60 | + \HCode{<label for="sidenote-\thempfn" class="margin-toggle sidenote-number"></label><input type="checkbox" id="sidenote-\thempfn" class="margin-toggle" />}% |
| 61 | + \HCode{<span class="sidenote">}#3\HCode{</span>}% |
| 62 | +\egroup% |
| 63 | +} |
| 64 | + |
| 65 | +% Configure margin notes (unnumbered) |
| 66 | +% Use Unicode character directly for the circle-plus symbol |
| 67 | +\renewcommand\marginnote[2][0pt]{% |
| 68 | + \stepcounter\@mpfn% |
| 69 | +\bgroup% |
| 70 | + \HCode{<label for="marginnote-\thempfn" class="margin-toggle">⊕</label><input type="checkbox" id="marginnote-\thempfn" class="margin-toggle" />}% |
| 71 | + \HCode{<span class="marginnote">}#2\HCode{</span>}% |
| 72 | +\egroup% |
| 73 | +} |
| 74 | + |
| 75 | +% Configure verbatim environments |
| 76 | +\ConfigureEnv{verbatim}{\endparagraph\HCode{<pre><code>}\NoFonts}{\EndNoFonts\endparagraph\HCode{</code></pre>}}{}{} |
| 77 | + |
| 78 | +% Configure fullwidth environment |
| 79 | +\ConfigureEnv{fullwidth}{\endparagraph\HCode{<div class="fullwidth">}% |
| 80 | +\ConfigureList{list}{}{}{}{}% |
| 81 | +\par\ShowPar\indent% |
| 82 | +} |
| 83 | +{\endparagraph\HCode{</div>}}{}{} |
| 84 | + |
| 85 | +% Configure margin floats (marginfigure) |
| 86 | +\NewConfigure{marginfloat}{2} |
| 87 | + |
| 88 | +\renewenvironment{@tufte@margin@float}[2][-1.2ex]% |
| 89 | +{\FloatBarrier% |
| 90 | +\begingroup% |
| 91 | +\let\textwidth\marginparwidth% |
| 92 | +\def\@captype{#2}% |
| 93 | +\par% |
| 94 | +\Configure{HtmlPar}{\EndP\csname a:marginfloat\endcsname}{\EndP\csname a:marginfloat\endcsname}{\csname b:marginfloat\endcsname}{\csname b:marginfloat\endcsname}% |
| 95 | +} |
| 96 | +{\endgroup} |
| 97 | + |
| 98 | +\Configure{marginfloat}{\HCode{<p><span class="marginnote">}% |
| 99 | +\Configure{caption}{\HCode{<span class="figure">}}{:\space}{}{\HCode{</span>}}% |
| 100 | +}{\HCode{</span></p>}}{}{} |
| 101 | + |
| 102 | +\Css{.marginnote .figure{display:block;}} |
| 103 | + |
| 104 | +% Configure regular floats |
| 105 | +\renewenvironment{@tufte@float}[3][htbp]% |
| 106 | +{\@float{#2}[#1]}{\end@float} |
| 107 | + |
| 108 | +% Configure captions |
| 109 | +\Configure{caption}{\HCode{<span class="marginnote">}}{:\space}{}{\HCode{</span>}} |
| 110 | + |
| 111 | +% Configure fullwidth figures (figure*) |
| 112 | +\ConfigureEnv{figure*}{ |
| 113 | +\Configure{float}{}{\endparagraph\HCode{<figure class="fullwidth">}}{\endparagraph\HCode{</figure>}\csname par\endcsname\ShowPar} |
| 114 | +\Configure{caption}{\endparagraph\HCode{<span class="figure">}}{:\space}{}{\HCode{</span>}} |
| 115 | +}{}{}{} |
| 116 | + |
| 117 | +% Configure margin tables |
| 118 | +\ConfigureEnv{margintable}{\endparagraph\HCode{<div class="margintable">}\Configure{caption}{}{:\space}{}{}}{\endparagraph\HCode{</div>}}{}{} |
| 119 | + |
| 120 | +% Configure math display width to match tufte-css article width |
| 121 | +\Css{div.math-display, div.par-math-display {width: 55\%}} |
| 122 | + |
| 123 | +% Add custom stylesheet (loaded after tufte.css) |
| 124 | +\Configure{AddCss}{lab-manual.css} |
| 125 | + |
| 126 | +\makeatother |
| 127 | + |
| 128 | +\begin{document} |
| 129 | +\EndPreamble |
0 commit comments