michal-h21 / make4ht

Build system for tex4ht
132 stars 15 forks source link

'mathml'-option does not color equations #90

Closed yalguzaq closed 1 year ago

yalguzaq commented 1 year ago

Consider the following TeX:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{amsmath,amsthm,amsfonts,amssymb}
\usepackage{hyperref}
\usepackage{xcolor}

\begin{document}
$$\text { minimize } {{\color{blue} x_6} + {\color{blue} x_7} + {\color{blue} x_8}}$$
A basic feasible solution to the auxiliary problem is obtained by letting $({\color{blue} x_6},{\color{blue} x_7},{\color{blue} x_8}) := \mathbf{b} = (2,2,1)$.
\end{document}

I have two issues here:

michal-h21 commented 1 year ago

This issue is quite complicated to solve, because you can quite easily run into XML tag mismatch with switch commands such as \color. It is better to use \textcolor, which has limited scope. Anyway, you can try this configuration file:

\Preamble{xhtml}

\makeatletter
\catcode`\:=11
\let\current:tag\relax
\def\color:tag{\ifmmode mstyle\else span\fi}
\def\:color:after{\HCode{</\color:tag>}\let\current:tag\relax}
\def\:tmp#1{\get:xcolorcss{#1}\:tmpcolor\def\current:tag{\HCode{<\color:tag}\HCode{ style="color:\:tmpcolor" >}}\current:tag\aftergroup\:color:after\o:color:{#1}}
\HLet\color\:tmp
%\Configure{HtmlPar}{\ifx\current:tag\relax\else\color:after\fi\EndP\HCode{<p>}\current:tag}{\EndP\HCode{<p>}}{\HCode{</p>}}{\HCode{</p>}}
\catcode`\:=12
\makeatother
\begin{document}
\EndPreamble

It fails with more complicated examples, where you use \color outside groups, but it seems to work for your test file.

yalguzaq commented 1 year ago

Thank you. The conclusion is that \textcolor should be used instead.