| 1 |
% \subsubsection{MathJax support} |
| 2 |
% When using mathjax, dump all the |\newcommand|s to a |.jax| file. |
| 3 |
% |
| 4 |
% First, create the |.jax| file. |
| 5 |
% \begin{macrocode} |
| 6 |
%<*classXimera> |
| 7 |
\ifdefined\HCode |
| 8 |
\else |
| 9 |
\newwrite\myfile |
| 10 |
\immediate\openout\myfile=\jobname.jax |
| 11 |
\fi |
| 12 |
%</classXimera> |
| 13 |
% \end{macrocode} |
| 14 |
% From |only.dtx| we must also create |prompt| on the MathJax side. |
| 15 |
% \begin{macrocode} |
| 16 |
%<*classXimera> |
| 17 |
\ifdefined\HCode |
| 18 |
\else |
| 19 |
\immediate\write\myfile{\unexpanded{\newenvironment}{prompt}{}{}} |
| 20 |
\fi |
| 21 |
%</classXimera> |
| 22 |
% \end{macrocode} |
| 23 |
% Redefine newcommand appropriately. |
| 24 |
% \begin{macrocode} |
| 25 |
%<*classXimera> |
| 26 |
\ifdefined\HCode |
| 27 |
\else |
| 28 |
\let\@oldargdef\@argdef |
| 29 |
\long\def\@argdef#1[#2]#3{% |
| 30 |
\immediate\write\myfile{\unexpanded{\newcommand}{\unexpanded{#1}}[\unexpanded{#2}]{\unexpanded{#3}}}% |
| 31 |
\@oldargdef#1[#2]{#3}% |
| 32 |
} |
| 33 |
|
| 34 |
\let\@OldDeclareMathOperator\DeclareMathOperator |
| 35 |
\renewcommand{\DeclareMathOperator}[2]{\@OldDeclareMathOperator{#1}{#2}\immediate\write\myfile{\unexpanded{\DeclareMathOperator}{\unexpanded{#1}}{\unexpanded{#2}}}} |
| 36 |
|
| 37 |
\fi |
| 38 |
%</classXimera> |
| 39 |
% \end{macrocode} |
| 40 |
% Include the jax'ed newcommands |
| 41 |
% \begin{macrocode} |
| 42 |
%<*cfgXimera> |
| 43 |
% Remove commands that use @ |
| 44 |
\immediate\write18{sed -i "/@/d" \jobname.jax} |
| 45 |
% Replace ##1 with #1 and so forth |
| 46 |
\immediate\write18{sed -i "s/\string#\string#\string\\([0-9]\string\\)/\string#\string\\1/g" \jobname.jax} |
| 47 |
|
| 48 |
\Configure{BVerbatimInput}{}{}{}{} |
| 49 |
|
| 50 |
\Configure{verbatiminput}{}{}{}{} |
| 51 |
|
| 52 |
% Instead of a nonbreaking space, use a standard space |
| 53 |
\makeatletter |
| 54 |
\def\FV@Space{\space} |
| 55 |
\makeatother |
| 56 |
|
| 57 |
% Include the mathjax newcommands in a math/tex script right at the beginning of the body |
| 58 |
\Configure{BODY}{% |
| 59 |
\HCode{<body>\Hnewline}% |
| 60 |
\Tg<div class="preamble">% |
| 61 |
\Tg<script type="math/tex">% |
| 62 |
\BVerbatimInput{\jobname.jax}% |
| 63 |
\Tg</script>% |
| 64 |
\IfFileExists{\jobname.ids}{\HCode{<script type="text/javascript">\Hnewline}% |
| 65 |
\BVerbatimInput{\jobname.ids}% |
| 66 |
\HCode{</script>\Hnewline}% |
| 67 |
\Tg</div>% |
| 68 |
}{} |
| 69 |
}{% |
| 70 |
\HCode{</body>\Hnewline}% |
| 71 |
} |
| 72 |
% \end{macrocode} |
| 73 |
% Now I just need to add a newcommand command which outputs the |
| 74 |
% appropriate newcommands to MathJax; then this should be "good |
| 75 |
% enough" for our purposes. |
| 76 |
% \begin{macrocode} |
| 77 |
\newtoks\eqtoks |
| 78 |
\def\AltMath#1${\eqtoks{#1}% |
| 79 |
\HCode{<script type="math/tex">\the\eqtoks</script>}$} |
| 80 |
\Configure{$}{}{}{\expandafter\AltMath} |
| 81 |
|
| 82 |
\def\AltlMathI#1\){\eqtoks{#1}% |
| 83 |
\HCode{<script type="math/tex">\the\eqtoks</script>}\)} |
| 84 |
\Configure{()}{\AltlMathI}{} |
| 85 |
|
| 86 |
\def\AltlDisplay#1\]{\eqtoks{#1}% |
| 87 |
\HCode{<script type="math/tex; mode=display">\the\eqtoks</script>}\]} |
| 88 |
\Configure{[]}{\AltlDisplay}{} |
| 89 |
|
| 90 |
\def\AltlDisplayI#1$${\eqtoks{#1}% |
| 91 |
\HCode{<script type="math/tex; mode=display">\the\eqtoks</script>}$$} |
| 92 |
\Configure{$$}{}{}{\expandafter\AltlDisplayI} |
| 93 |
% \end{macrocode} |
| 94 |
% Need to turn off htmlpar too, as expained in http://tex.stackexchange.com/questions/204930/vertical-spaces-in-htlatex-scriptenv |
| 95 |
% \begin{macrocode} |
| 96 |
\newcommand\VerbMath[1]{% |
| 97 |
\renewenvironment{#1}{\NoFonts}{\EndNoFonts} |
| 98 |
\ScriptEnv{#1}{\ifvmode \IgnorePar\fi \EndP\HCode{<script type="math/tex; mode=display"> \string\begin{#1}\Hnewline}\HtmlParOff}{\HtmlParOn\HCode{\string\end{#1}</script>}} |
| 99 |
} |
| 100 |
% \end{macrocode} |
| 101 |
% This is a fix for the LAODE book, which uses matlabEquation as if it were an equation |
| 102 |
% \begin{macrocode} |
| 103 |
\ScriptEnv{matlabEquation}{\ifvmode \IgnorePar\fi \EndP\HCode{<script type="math/tex; mode=display"> \string\begin{equation}\Hnewline}\HtmlParOff}{\HtmlParOn\HCode{\string\end{equation}</script>}} |
| 104 |
|
| 105 |
\VerbMath{equation} |
| 106 |
\VerbMath{equation*} |
| 107 |
\VerbMath{align} |
| 108 |
\VerbMath{align*} |
| 109 |
\VerbMath{alignat} |
| 110 |
\VerbMath{alignat*} |
| 111 |
\VerbMath{eqnarray} |
| 112 |
\VerbMath{eqnarray*} |
| 113 |
|
| 114 |
%</cfgXimera> |
| 115 |
% \end{macrocode} |