michal-h21 / make4ht

Build system for tex4ht
132 stars 15 forks source link

Explicit style/css for all rows/cells #63

Closed damageboy closed 9 months ago

damageboy commented 2 years ago

Hi, When generating tables with make4ht I'm left with great looking tables when displayed as is (in html/browser).

However, since my intention is to further process this HTML into a separate publishing system, I've encountered a weirdness where many of the table/rows, while having IDs, don't have explicit styling settings, neither inline on the HTML element level, nor in the CSS.

Is there a way to cause make4ht generate a more explicit/verbose CSS or HTML table elements?

michal-h21 commented 2 years ago

Hi,

do you have example of code that generates such table? In general, TeX4ht generates inline CSS with alignment info for each table cell. This is configured using \Configure{halignTD} configuration. The following example changes inline CSS for l and r tabular specifiers to CSS code inserted into the CSS file:

\Preamble{xhtml}
\Configure{halignTD} {}{}
   {<}{\Protect\leftalignedcolumn}
   {-}{\HCode{ style="white-space:nowrap; text-align:center;"}}
   {>}{\Protect\rightalignedcolumn}
   {^}{\HCode{ style="vertical-align:top; white-space:nowrap;"}}
   {=}{\HCode{ style="vertical-align:baseline; white-space:nowrap;"}}
   {|}{\HCode{ style="vertical-align:middle; white-space:nowrap;"}}
   {_}{\HCode{ style="vertical-align:bottom; white-space:nowrap;"}}
   {p}{\HCode{ style="white-space:normal; text-align:left;"}\Protect\a:HColWidth}
   {m}{\HCode{ style="white-space:nowrap; text-align:left; vertical-align:middle;"}}
   {b}{\HCode{ style="white-space:nowrap; text-align:left; vertical-align:baseline;"}}
   {}

\def\leftalignedcolumn{\ifnum\HRow=1\Css{\#TBL-\TableNo\space td:nth-child(\HCol){text-align:left;}}\fi}
\def\rightalignedcolumn{\ifnum\HRow=1\Css{\#TBL-\TableNo\space td:nth-child(\HCol){text-align:right;}}\fi}
\begin{document}
\EndPreamble

\TableNo is number of the table, \HCol is number of the column. As this code is executed for every cell, we need \ifnum\HRow=1 to execute it only in the first row, to prevent multiple insertions to the CSS file.