MathJax icon indicating copy to clipboard operation
MathJax copied to clipboard

Feature Request: Script r

Open paulnakroshis opened this issue 3 years ago • 4 comments

I would love to have the ability in Jupyter Notebooks to use a script r in the style used by David Griffiths' Introduction to Electrodynamics. I have modified his preamble definition to the following:

\usepackage{graphicx}

\def\rcurs{{\mbox{$\resizebox{.16in}{.08in}{\includegraphics{ScriptR}}$}}\hspace*{-1.3mm}}
\def\brcurs{{\mbox{$\resizebox{.16in}{.08in}{\includegraphics{BoldR}}$}}\hspace*{-1.3mm}}
\def\hrcurs{{\mbox{$\hat \brcurs$}}}

If this is easy to add to MathJax, there would be literally thousands of physicists and physics students that would extremely happy. :-) Griffiths_R.pdf

paulnakroshis avatar Jun 10 '21 13:06 paulnakroshis

I'm moving this issue to the main MathJax issue tracker, since it is a feature request for MathJax, not an issue with the documentation.

dpvc avatar Jun 10 '21 14:06 dpvc

Davide, Thanks for moving this to the appropriate place. Do you think this is an easy thing to include? (it's literally a cut and paste for a straight .tex document preamble, but I have no idea about the structure of MathJax). -p

paulnakroshis avatar Jun 10 '21 15:06 paulnakroshis

Although MathJax does have the ability to specify a script "r", the MathJax fonts don't include this character, so the result will depend on the fonts installed on the computer of the reader.

On the other hand, MathJax can insert images, so you could use a similar trick to what you are doing now, but using MathJax's features. I give an example below. Note that I have converted the pdf versions into png versions, which are only about 3K rather than the 150K of the original BoldR.pdf, in order to make them useable in all browser (not all browsers will handle the PDF version). These are linked below so you can download them for your own use.

To add this in MathJax, we use the MathML <mglyph> element, and create it using the \mmlToken macro. You can define the \rcurs, \brcurs, and \hrcurs macros in the tex.macros block of your MathJax configuration:

MathJax = {
  tex: {
    macros: {
      rcurs: '\\mmlToken{mglyph}[src="ScriptR.png" width="1.4ex" height="1.4ex" valign="-.1ex" alt="cursive r"]{}',
      brcurs: '\\mmlToken{mglyph}[src="BoldR.png" width="1.4ex" height="1.4ex" valign="-.1ex" alt="bold cursive r"]{}',
      hrcurs: '\\hat\\brcurs'
    }
  }
};

and then use them in your TeX code as normal. The result of \(\brcurs \equiv (\mathbf{r} - \mathbf{r'})\) is

mj-r

which seems to compare favorably with

intro

which is taken directly from Grifiths' introduction.

The two images that you need are:

ScriptR.png

ScriptR

BoldR.png

BoldR

You should be able to use your browser's "Save linked file as..." contextual menu item (or a similar one) to save these images to use in your own website. Note that the clipping at the top is part of the original PDF file, and I couldn't prevent that, though at the low resolutions at which it will be used, you probably won't notice it.

dpvc avatar Jun 10 '21 15:06 dpvc

PS, we are working on the ability to add your own font information into MathJax, so that you would be able to replace the script font with your own (and it appears that there are some web versions of the Kaufmann font available). That will make things easier in the long run. But that won't be out until the end of the summer.

dpvc avatar Jun 10 '21 15:06 dpvc