One approach would be to set up a style like the following as part of
your configuration:
MathJax.Hub.Config({
...
"HTML-CSS": {
styles: {
".MathJax .code": {
"font-family": "Courier ! important"
}
}
}
});
and then use
\class{code}{\text{...}}
to typeset the material that should be in the courier font. You could
make a macro that does this, as in:
MathJax.Hub.Config({
TeX: {
Macros: {
CODE: ["\\class{code}{\\text{#1}}",1]
}
}
});
so that \CODE{...} would typeset its contents in the courier font.
Note that you can use $...$ or \(...\) within the \CODE{...} to switch
back to mathematics:
$ t = (\CODE{fn x => \(t'\)}) $
so I think this covers the situations you need. The only issue is
that you need to know the font used by default for <code> blocks.
That may mean you need to use CSS to set this explicitly for the code
blocks so that you are sure to match it within the mathematics.
Because MathJax scales the mathematics to match the surrounding text,
you may also find that the size of the \CODE{...} text is not quite
the same as the surrounding text. In that case, you may need to add a
font-size style as well to compensate.
It would also be possible to use
\style{font-family:Courier!important}{\text{...}}
rather than setting a style, but styling may give you more flexibility
in the long run.
Hope that does what you need.
Davide
> I had a related problem working on mathics.net, where I wanted to
> insert SVG images (i.e. DOM nodes) into mathematical formulas. My
> workaround (for the MathML renderer, though) is as follows:
>
> * insert <mspace>s with the appropriate dimensions (trivial for
> images, but you could easily figure it out for text as well using some
> JavaScript), and
> * after rendering by MathJax, inject the desired code into the <span>
> elements generated from the <mspace>s.
That is clever, and I wouldn't have thought of it.
I suppose the proper hook for this sort of thing is the <semantics>
element, but it has always been somewhat mysterious to me, and I
haven't taken time to really look into what the proper action should
be for non-MathML children. Certainly support for it could be
improved in the HTML-CSS output jax. One thing I worry about, though,
is compatibility with the NativeMML output. I don't like to extend
the HTML-CSS output too far beyond what is available in native MathML,
since many people are using that for speed purposes. If HTML-CSS
handles extra content in <semantics> that native MathML doesn't then
that will break sites for those using browsers with native MathML
support.
> There are two main restrictions so far: It only works with MathML
> input (but there might be an equivalent to <mspace> in TeX as well)
One could use \hskip to produce <mspace> in the output.
> and it needs the HTML renderer of Mathics (to be able to "tweak" the
> result).
Right.
> Of course, native support for HTML/DOM element injection would be much
> better...
Indeed.
Davide