summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/generic/tex4ht/tex4ht-mathjax.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/generic/tex4ht/tex4ht-mathjax.tex')
-rw-r--r--Master/texmf-dist/source/generic/tex4ht/tex4ht-mathjax.tex49
1 files changed, 44 insertions, 5 deletions
diff --git a/Master/texmf-dist/source/generic/tex4ht/tex4ht-mathjax.tex b/Master/texmf-dist/source/generic/tex4ht/tex4ht-mathjax.tex
index e93531455a2..0e62cc872e2 100644
--- a/Master/texmf-dist/source/generic/tex4ht/tex4ht-mathjax.tex
+++ b/Master/texmf-dist/source/generic/tex4ht/tex4ht-mathjax.tex
@@ -1,4 +1,4 @@
-% $Id: tex4ht-mathjax.tex 1215 2022-10-17 13:58:09Z michal_h21 $
+% $Id: tex4ht-mathjax.tex 1256 2022-11-28 15:50:18Z michal_h21 $
% compile: latex tex4ht-mathjax
%
% Copyright 2018-2022 TeX Users Group
@@ -26,6 +26,7 @@
\AtBeginDocument{%
|<configurations|>
|<mhchem configurations|>
+|<restore environments|>
}
\endinput
>>>
@@ -114,6 +115,32 @@ environments. They will then keep the LaTeX code unchanged.
}
>>>
+In pictures, we want to use the original version of the math environments. Because we use
+an agressive verbatim method for the environments, we cannot use the usual \verb'\HLet' method.
+Instead, we save the original meaning, and user needs to restore it manually, using
+the \verb'\RestoreMathJaxEnvironments' command.
+
+\<defined commands\><<<
+\ExplSyntaxOn
+\seq_new:N\:savedmathjaxenvs
+
+\newcommand\:savemathjaxenv[1]{%
+ \seq_gput_right:Nn\:savedmathjaxenvs{#1}
+ \expandafter\let\csname mathjax-#1\expandafter\endcsname\csname #1\endcsname%
+ \expandafter\let\csname mathjax-end#1\expandafter\endcsname\csname end#1\endcsname%
+}
+
+\newcommand\RestoreMathJaxEnvironment[1]{%
+ \expandafter\let\csname #1\expandafter\endcsname\csname mathjax-#1\endcsname%
+ \expandafter\let\csname end#1\expandafter\endcsname\csname mathjax-end#1\endcsname%
+}
+
+\newcommand\RestoreMathJaxEnvironments{%
+ \seq_map_function:NN\:savedmathjaxenvs\RestoreMathJaxEnvironment%
+}
+\ExplSyntaxOff
+>>>
+
The \verb|\VerbMath| command redefines environments to pass their content
verbatim to the HTML output.
@@ -129,6 +156,7 @@ numbers them consecutively. In these cases, other mechanisms may be necessary.
\cs_generate_variant:Nn \regex_extract_once:nnNTF {nV}
\newcommand\VerbMath[2][]{%
\cs_if_exist:cTF{#2}{
+ \:savemathjaxenv{#2}%
\RenewDocumentEnvironment{#2}{+!b}{%
\NoFonts\expandafter\VerbMathToks\expandafter{\detokenize{##1}}{#2}\EndNoFonts%
\ifx\relax#1\relax\else%
@@ -148,10 +176,13 @@ keep their verbatim appearance in the TOC
\def\fixmathjaxtoc#1{\Configure{writetoc}{\def#1{\detokenize{#1}}}}
>>>
-Some math commands cause issues when used in sections, so we will deactivate them.
+This was meant to fix some commands in sectioning commands, but it is not
+a good solution. Better is to define the problematic commands as robust.
-\<defined commands\><<<
+\<not defined commands\><<<
\def\fixmathjaxsec#1{\def#1{\detokenize{#1}}}
+\fixmathjaxsec\right
+\fixmathjaxsec\left
>>>
Require verbatim math environments.
@@ -207,8 +238,6 @@ them into pictures.
Fixes for tables of contents.
\<configurations\><<<
-\fixmathjaxsec\left
-\fixmathjaxsec\right
\fixmathjaxtoc\int
\fixmathjaxtoc\,
\fixmathjaxtoc\sin
@@ -241,4 +270,14 @@ Fixes for tables of contents.
}{}
>>>
+Restore environments redefined to produce verbatim output to their
+original meaning in the picture mode. Otherwise math cannot work
+inside TikZ etc.
+
+\<restore environments\><<<
+\@ifpackageloaded{tikz}{%
+\tikzset{every picture/.append code={\RestoreMathJaxEnvironments}}
+}{}
+>>>
+
\endinput