[tex4ht-commits] [SCM] tex4ht updated: r1598 - trunk/lit

Michal Hoftich INVALID.NOREPLY at gnu.org.ua
Wed Nov 20 12:40:35 CET 2024


Author: michal_h21
Date: 2024-11-20 11:40:35 +0000 (Wed, 20 Nov 2024)
New Revision: 1598

Modified:
   trunk/lit/ChangeLog
   trunk/lit/tex4ht-mathjax.tex
Log:
added the fastmathjax option

Modified: trunk/lit/ChangeLog
===================================================================
--- trunk/lit/ChangeLog	2024-11-17 22:03:56 UTC (rev 1597)
+++ trunk/lit/ChangeLog	2024-11-20 11:40:35 UTC (rev 1598)
@@ -1,3 +1,9 @@
+2024-11-20  Michal Hoftich  <michal.h21 at gmail.com>
+
+	* tex4ht-mathjax.tex (mathjax-latex-4ht.4ht): added the
+	"fastmathjax" option.
+	https://tug.org/pipermail/tex4ht/2024q4/003625.html
+
 2024-11-17  Michal Hoftich  <michal.h21 at gmail.com>
 
 	* tex4ht-4ht.tex (manyfoot-hooks.4ht): fixed normal footnote numbers

Modified: trunk/lit/tex4ht-mathjax.tex
===================================================================
--- trunk/lit/tex4ht-mathjax.tex	2024-11-17 22:03:56 UTC (rev 1597)
+++ trunk/lit/tex4ht-mathjax.tex	2024-11-20 11:40:35 UTC (rev 1598)
@@ -40,7 +40,8 @@
 The \verb|\alteqtoks| command prints the used LaTeX math code to the output document in 
 verbatim. 
 
-In the past, we used \verb|\detokenize|. The side effect of this is that detokeize inserts space
+We use \verb|\detokenize| to output verbatim LaTeX code to the HTML document. 
+The side effect of this is that detokenize inserts space
 after each control sequence. This is completely valid TeX code, but earlier versions of
 MathJax didn't like that, rendering resulted in error.
 
@@ -77,9 +78,41 @@
 
 
 We still use regular expressions to escape invalid XML characters to entities, so it works only with LaTeX.
+But regular expressions may be slow if there is a huge number of math, and they may fail if contents 
+of any math environment is larger than 64 KB.  
 
+So we provide a "fastmathjax" option, that doesn't do any post-processing of the math contents. It should 
+result in 60-70\% speed-up. The downside is that if math contains characters that are invalid in the 
+XML mode, such as ampersand, less-than and greater-than, make4ht XML DOM filters will fail. Fortunatelly, 
+make4ht will then switch to the HTML parser mode, so DOM filters will be still executed.
+
+
 \<defined commands\><<<
 \ExplSyntaxOn
+\:CheckOption{fastmathjax}\if:Option
+|<fastmathjax|>
+\else
+|<normalmathjax|>
+\fi
+\ExplSyntaxOff
+>>>
+
+Output verbatim math to HTML without any post-processing. 
+We still need to set the token list to prevent some issues. 
+
+For example, if the processed math contain paragraphs, we would
+get an error because \''\HCode' doesn't like that.
+
+\<fastmathjax\><<<
+\DeclareRobustCommand\alteqtoks[1]{%
+  \tl_set:Ne \l_tmpa_tl {\detokenize{#1}}
+  \HCode{\l_tmpa_tl}
+}
+>>>
+
+Escape illegal XML characters.
+
+\<normalmathjax\><<<
 \cs_new_protected:Npn \alteqtoks #1
 {
   \tl_set:Ne \l_tmpa_tl {\detokenize{#1}}
@@ -92,10 +125,9 @@
   \tl_set:Ne \l_tmpb_tl{ \l_tmpa_tl }
   \HCode{\l_tmpb_tl}
 }
-\ExplSyntaxOff
-
 >>>
 
+
 Provide configuration for MathJax
 
 \<defined commands\><<<



More information about the tex4ht-commits mailing list.