[tex4ht-commits] [SCM] tex4ht updated: r1540 - trunk/lit
Michal Hoftich
INVALID.NOREPLY at gnu.org.ua
Sun Jul 28 19:10:17 CEST 2024
Author: michal_h21
Date: 2024-07-28 17:10:17 +0000 (Sun, 28 Jul 2024)
New Revision: 1540
Modified:
trunk/lit/ChangeLog
trunk/lit/tex4ht-mathjax.tex
Log:
don't add spaces after LaTeX commands in MathJax
Modified: trunk/lit/ChangeLog
===================================================================
--- trunk/lit/ChangeLog 2024-07-26 15:53:24 UTC (rev 1539)
+++ trunk/lit/ChangeLog 2024-07-28 17:10:17 UTC (rev 1540)
@@ -1,3 +1,8 @@
+2024-07-28 Michal Hoftich <michal.h21 at gmail.com>
+
+ * tex4ht-mathjax.tex (mathjax-latex-4ht.4ht): don't add spaces after
+ LaTeX commands.
+
2024-07-26 Michal Hoftich <michal.h21 at gmail.com>
* tex4ht-4ht.tex (tagpdf-hooks.4ht, tagpdf-base-hooks.4ht): removed
Modified: trunk/lit/tex4ht-mathjax.tex
===================================================================
--- trunk/lit/tex4ht-mathjax.tex 2024-07-26 15:53:24 UTC (rev 1539)
+++ trunk/lit/tex4ht-mathjax.tex 2024-07-28 17:10:17 UTC (rev 1540)
@@ -37,12 +37,14 @@
\<required packages\><<<
>>>
-The \verb|\alteqtoks| command saves the used command in HTML. It uses detokenize command
-to insert arguments verbatim. The side effect of this is that detokeize inserts space
+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
after each control sequence. This is completely valid TeX code, but earlier versions of
MathJax didn't like that, rendering resulted in error.
-Fortunatelly, MathJax 3 supports these spaces, so we can remove regular expressions for space handling.
+Fortunatelly, MathJax 3 supports these spaces, so we could remove regular expressions for space handling.
The original code was this:
% % convert \ { to \:{
@@ -52,14 +54,24 @@
% % replace \\:{ back to \\ { -- this can be introduced by the previous regex
% \regex_replace_all:nnN { \x{5C} \x{5C} \x{3A} \x{7B} } { \x{5C} \x{5C} \x{20} \x{7B} } \l_tmpa_tl
+Now (July 2024), when I researched another issue, I've found that it is actually possible to avoid these
+extra spaces using LaTeX 3 commands. The inspiration comes from
+\Link[https://tex.stackexchange.com/a/44444/2891]this Bruno Le Foch\EndLink.
+One ongoing issue is that newlines are not presented. But they weren't preserved with \verb|\detokenize|
+either, so it shouldn't be a problem.
-We still use regula expressions to escape invalid XML characters to entities, so it works only with LaTeX.
+We still use regular expressions to escape invalid XML characters to entities, so it works only with LaTeX.
+
\<defined commands\><<<
\ExplSyntaxOn
\cs_new_protected:Npn \alteqtoks #1
{
- \tl_set:Ne \l_tmpa_tl {\detokenize{#1}}
+ % save tokens, but preserve spaces
+ % https://tex.stackexchange.com/a/44444/2891
+ \tl_set:Nn \l_tmpa_tl {#1}
+ \regex_replace_all:nnN { . } { \c{string} \0 } \l_tmpa_tl
+ \tl_set:Nx \l_tmpa_tl { \l_tmpa_tl }
% % replace < > and & with xml entities
\regex_replace_all:nnN { \x{26} } { & } \l_tmpa_tl
\regex_replace_all:nnN { \x{3C} } { < } \l_tmpa_tl
More information about the tex4ht-commits
mailing list.