延伸问题这里那么,还有什么办法可以在tabularx
环境中获取彩色文本吗?
以下是 MWE:
\documentclass[12pt]{book}
\usepackage{tabularx}
\usepackage{xcolor}
\newenvironment{colorenv}[1]{\color{#1}}{}
\begin{document}
\begin{colorenv}{blue}
This text is blue.
\begin{tabularx}{\linewidth}{| X | X |}
\hline
This text is black & although I would like to have it blue.\\
\hline
\end{tabularx}
\end{colorenv}
\end{document}
这是配置文件:
\Preamble{xhtml}
\ExplSyntaxOn
\renewenvironment{colorenv}[1]{
\get:xcolorcss{#1}\:colorenv
\ifvmode\IgnorePar\fi\EndP\HCode{<div~style="color:\:colorenv">}\par\ShowPar
}{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}
\ExplSyntaxOff
\begin{document}
\EndPreamble
答案1
有两个问题。一个是 Calibre 无法以正确的颜色显示文本,另一个与表格规则颜色有关,TeX4ht 将其设置为黑色。
第一个问题可以通过以下 CSS 声明来解决:
\Css{table{color: inherit;}}
它只是告诉 Calibre 使用父元素的颜色作为表格。它似乎默认将其设置为黑色。
规则的修复更加复杂。我不得不复制一些设置规则颜色的配置,并更改显式颜色以使用该\:colorenv
颜色。这是完整的配置文件:
\Preamble{xhtml}
\catcode`\:=11
\def\:colorenv{black}
\renewenvironment{colorenv}[1]{
\get:xcolorcss{#1}\:colorenv
\ifvmode\IgnorePar\fi\EndP\HCode{<div style="color:\:colorenv" class="colorenv">}\par\ShowPar
}{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}
\Configure{VBorder}
{\let\VBorder\empty \let\AllColMargins\empty
\global\let\GROUPS\empty \HAssign\NewGroup = 0
\gHAdvance\Next:TableNo by 1 \global\let\TableNo=\Next:TableNo }
{\xdef\VBorder{\VBorder\ifnum \NewGroup> 0 </colgroup>\fi}
\HAssign\NewGroup = 0 % \gdef\GROUPS{rules="groups"}}
% put vertical border for a column
\ifnum\ar:cnt > 0%
% in all other cases, we should put right border
\Css{\#TBL-\TableNo-\ar:cnt {border-right:1px solid \:colorenv;}}%
\else%
% columns are numbered from 1. if \ar:cnt == 0 then it is the left border
\Css{\#TBL-\TableNo-1{border-left: 1px solid \:colorenv;}}%
\fi%
}
{\Advance:\NewGroup by 1
\ifnum \NewGroup=1 \xdef\VBorder{\VBorder<colgroup
id="TBL-\TableNo-\ar:cnt g">}\fi
\xdef\VBorder{\VBorder<col\Hnewline id="TBL-\TableNo
-\ar:cnt"\xml:empty>}\xdef\AllColMargins{\AllColMargins1}}
{\xdef\AllColMargins{\AllColMargins 0}}
\AddToHook{env/tabularx/after}{
\Css{.colorenv \#TBL-\TableNo\space .hline{border-top: 1px solid \:colorenv;}}
}
\catcode`\:=12
\Css{table{color: inherit;}}
\begin{document}
\EndPreamble
结果如下: