% \subsubsection{MathJax support} % When using mathjax, dump all the |\newcommand|s to a |.jax| file. % % First, create the |.jax| file. % \begin{macrocode} %<*classXimera> \ifdefined\HCode \else \newwrite\myfile \immediate\openout\myfile=\jobname.jax \fi % % \end{macrocode} % From |only.dtx| we must also create |prompt| on the MathJax side. % \begin{macrocode} %<*classXimera> \ifdefined\HCode \else \immediate\write\myfile{\unexpanded{\newenvironment}{prompt}{}{}} \fi % % \end{macrocode} % Redefine newcommand appropriately. % \begin{macrocode} %<*classXimera> \ifdefined\HCode \else \let\@oldargdef\@argdef \long\def\@argdef#1[#2]#3{% \immediate\write\myfile{\unexpanded{\newcommand}{\unexpanded{#1}}[\unexpanded{#2}]{\unexpanded{#3}}}% \@oldargdef#1[#2]{#3}% } \let\@OldDeclareMathOperator\DeclareMathOperator \renewcommand{\DeclareMathOperator}[2]{\@OldDeclareMathOperator{#1}{#2}\immediate\write\myfile{\unexpanded{\DeclareMathOperator}{\unexpanded{#1}}{\unexpanded{#2}}}} \fi % % \end{macrocode} % Include the jax'ed newcommands % \begin{macrocode} %<*cfgXimera> % Remove commands that use @ \immediate\write18{sed -i "/@/d" \jobname.jax} % Replace ##1 with #1 and so forth \immediate\write18{sed -i "s/\string#\string#\string\\([0-9]\string\\)/\string#\string\\1/g" \jobname.jax} \Configure{BVerbatimInput}{}{}{}{} \Configure{verbatiminput}{}{}{}{} % Instead of a nonbreaking space, use a standard space \makeatletter \def\FV@Space{\space} \makeatother % Include the mathjax newcommands in a math/tex script right at the beginning of the body \Configure{BODY}{% \HCode{\Hnewline}% \Tg
% \Tg% \IfFileExists{\jobname.ids}{\HCode{\Hnewline}% \Tg
% }{} }{% \HCode{\Hnewline}% } % \end{macrocode} % Now I just need to add a newcommand command which outputs the % appropriate newcommands to MathJax; then this should be "good % enough" for our purposes. % \begin{macrocode} \newtoks\eqtoks \def\AltMath#1${\eqtoks{#1}% \HCode{}$} \Configure{$}{}{}{\expandafter\AltMath} \def\AltlMathI#1\){\eqtoks{#1}% \HCode{}\)} \Configure{()}{\AltlMathI}{} \def\AltlDisplay#1\]{\eqtoks{#1}% \HCode{}\]} \Configure{[]}{\AltlDisplay}{} \def\AltlDisplayI#1$${\eqtoks{#1}% \HCode{}$$} \Configure{$$}{}{}{\expandafter\AltlDisplayI} % \end{macrocode} % Need to turn off htmlpar too, as expained in http://tex.stackexchange.com/questions/204930/vertical-spaces-in-htlatex-scriptenv % \begin{macrocode} \newcommand\VerbMath[1]{% \renewenvironment{#1}{\NoFonts}{\EndNoFonts} \ScriptEnv{#1}{\ifvmode \IgnorePar\fi \EndP\HCode{}} } % \end{macrocode} % This is a fix for the LAODE book, which uses matlabEquation as if it were an equation % \begin{macrocode} \ScriptEnv{matlabEquation}{\ifvmode \IgnorePar\fi \EndP\HCode{}} \VerbMath{equation} \VerbMath{equation*} \VerbMath{align} \VerbMath{align*} \VerbMath{alignat} \VerbMath{alignat*} \VerbMath{eqnarray} \VerbMath{eqnarray*} % % \end{macrocode}