I'm student for Computer science. I prefer to write my home work assignments in LaTeX. I'm utilizing tikZ pretty heavily in my specialized science courses. My goal now is to convert my TeX files to HTML+CSS+MathJax. I want everything that is supported by MathJax to be converted to MathJax and everything else (complex diagrams and drawings) to be simple converted to images (SVG/PGF).
I have tried to use Pandoc and Make4ht to achieve this goal with no success.
Pandoc makes a pretty good job of converting my common LaTeX to HTML+MathJax, but fell short when it comes to TikZ diagrams.
With Make4ht I have a great success with TikZ diagrams but I have several problems with the TeX itself.
Currently I have 2 problems:
- make4ht doesn't convert my
\newcommand
macros. - make4ht can't use HTML color codes for cell filling in tables.
- make4ht gnerates SVG images of TikZ diagrams but without text.
Here I'm providing a sample code and its result as it appears on my computer after invoking: make4ht -ux file.tex "mathjax"
\documentclass [11pt, a4paper]{article}
\usepackage[margin=2 cm]{geometry} %
\usepackage{polyglossia}
\usepackage{listings}
\usepackage{fontspec}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{parskip}
\usepackage{graphicx}
\usepackage[table,xcdraw]{xcolor}
\usepackage[american]{circuitikz}
\newcommand{\n}[1]{\overline{#1}}
\begin{document}
\begin{table}[h!]
\begin{tabular}{|c|c|c|c|c|}
\hline
\rowcolor[HTML]{C0C0C0}
\( \mathbf{x} \) & \( \mathbf{y} \) & \( \mathbf{(\n{x + y})} \) & \( \mathbf{\left( \n{\n{x} + \n{y}}\right)} \) & \( \mathbf{F} \)\\ \hline
0 & 0 & 1 & 0 & \cellcolor[HTML]{67FD9A}0 \\ \hline
0 & 1 & 0 & 0 & \cellcolor[HTML]{67FD9A}0 \\ \hline
1 & 0 & 0 & 0 & \cellcolor[HTML]{67FD9A}0 \\ \hline
1 & 1 & 0 & 1 & \cellcolor[HTML]{67FD9A}0 \\ \hline
\end{tabular}%
\end{table}
\( (\n{A} + B) \cdot \n{B} + \n{A}\n{C} + A \)
\begin{circuitikz} \draw
(0,0) node[] (A) {A}
(0,-0.5) node[] (B) {B}
(0,-1.5) node[] (C) {C}
(4,-0.5) node[or port] (myor) {}
(2,-1) node[nand port] (mynand) {}
(A) -| (myor.in 1)
(B) -| (mynand.in 1)
(C) -| (mynand.in 2)
(mynand.out) -| (myor.in 2)
(myor.out) node[anchor=west] {F}
;\end{circuitikz}
\end{document}
As you can see make4ht did'nt interpreted \n
macro. Also while running the command I did get this warning message:
Argument of \c:HColor: has an extra }.
<inserted text>
\par
l.27 ... \rowcolor[HTML]{C0C0C0}
?
Best Answer
Update:
It is possible to use the direct colors now. Try this version of
colortbl.4ht
:Original answer:
I can compile your file with
tex4ht
with small changes.There are three issues that need to be fixed: missing definition of the
\n
command in MathJax, color issues and issues with the TikZ graphics.For TikZ, I would use the alternative driver. It uses Dvisvgm for the conversion and produces much better result than the default driver. Especially for the text nodes.
The issue with
\n
command is caused by the fact thattex4ht
cannot process the math content in the MathJax mode. It can be fixed with a simple configuration for MathJax.The color issues can be fixed using named colours instead of use of the direct values. It is also necessary to provide an alternative definition for the
\cellcolor
command, because it is not supported bytex4ht
by default.Here is the modified TeX file:
The main changes are the use of the alternative driver:
and use of the named colours:
Here is the configuration file:
It defines the
lightgreen
color, because all colors must be configured fortex4ht
.lightgray
is defined by default:the next lines redefine a macro used by
\cellcolor
internally to use thetex4ht
configurations for cell colors:And finally, using the following configuration we define the
\n
macro for MathJax:Compile your file using
This is the result: