Mathjax in jsxgraph

277 views
Skip to first unread message

epmbaba

unread,
Oct 13, 2020, 5:07:33 AM10/13/20
to JSXGraph

Hi

I tried getting `bar(x)` in jsxgraph, but didn't work. Here's my latest attempt:

brd.create('text',[-4,15,
  function() {
    return `\\[bar{x}\\]`;
  }]);

How can I get it?

Thanks!!


Murray

unread,
Oct 13, 2020, 8:16:06 PM10/13/20
to JSXGraph
When the page first loads, if MathJax finds any math then it processes it.

But JSXGraph loads separately, and so if you have math in your JSXGraph it needs to be processed my MathJax in a separate and later process to the main page. 

This page tells you how to invoke MathJax to process the math in your JSXGraph:

epmbaba

unread,
Oct 14, 2020, 3:40:18 AM10/14/20
to JSXGraph
Hi Murray

Thanks, but Mathjax has been loaded. I'm getting "x square", but not "x bar"

This works:

brd.create('text',[-4,15,
  function() {
    return `\\[{x}^2\\]`;
  }]);

But not
brd.create('text',[-4,15,
  function() {
    return `\\[bar{x}\\]`;
  }]);

Alfred Wassermann

unread,
Oct 14, 2020, 3:55:06 AM10/14/20
to JSXGraph
The following two issues may cause this poblem: 
1) Are you using the attribute `useMathJax:true`?
    brd.create('text',[-4,15,  function() {  return `\\[bar{x}\\]`;  }], {useMathJax:true});
2) Do you use the attribute "async" for loading MathJax? If yes, you may have to wait until MathJax is loaded before you can use it in JSXgraph.

Best wishes,
Alfred


epmbaba

unread,
Oct 14, 2020, 10:24:51 AM10/14/20
to JSXGraph
Hi Alfred

a) No, I'm not using `useMathJax:true`

b) Yes, I'm using the attribute "async". But, then, how does x^2 load, and not bar(x). Doesn't make sense.

Nevertheless, in this context, how can I avoid using "async":

Alfred Wassermann

unread,
Oct 14, 2020, 10:47:38 AM10/14/20
to JSXGraph
The super script x^2 is set by JSXGraph in HTML, for this MathJax is not needed. Does your code work if you set the attribute useMathJax:true?
What happens, if you take the async out? Of course, the page will need more time until it is ready.

Best wishes,
Alfred




Javier Puértolas

unread,
Oct 14, 2020, 11:04:25 AM10/14/20
to jsxg...@googlegroups.com
Hi,

bar{x} doesn’t work in latex. It is \bar{x}. In jsxgraph text latex commands needs two backslash: \\bar{x}, or three, \\\bar{x} if you d’int use the parse:false option.

I’ll try

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>

brd.create('text',[-4,15, ‘$ \\bar{x} $`], {useMathjax:true, parse:false});

Javier

Javier Puértolas

unread,
Oct 14, 2020, 11:06:01 AM10/14/20
to jsxg...@googlegroups.com
Sorry, the correct option is:    useMathJax:true

El 14 oct 2020, a las 17:02, Javier Puértolas <jouer...@gmail.com> escribió:

seMathjax:true

epmbaba

unread,
Oct 15, 2020, 5:44:41 AM10/15/20
to JSXGraph
Hi Alfred

Negative here - set the attribute to true, and/or removed "async". No luck.

(I'm using asciimath - so I write `x^2` for x square).

epmbaba

unread,
Oct 15, 2020, 5:49:43 AM10/15/20
to JSXGraph
Thanks, Javier, but didn't work

set the attribute useMathjax:true - no luck
tried 2, 3 backslahes - \\bar(x), \\\bar(x) - ... no luck :(

(FYI - I'm using asciimath - so I write `bar(x)` for x bar).

Michael Morelli

unread,
Nov 21, 2020, 8:09:36 PM11/21/20
to JSXGraph
Here is a working example: https://code.sololearn.com/WoNMn3DXxeGN

The two important points are:
     1. You must include the 'window.MathJax' script in your document.
     2. You have to use the double backslash \\ before you can type TeX.

Those MathJax window configurations were taken from the 'options.js' JSXGraph documentation (lines 4630-4642): https://jsxgraph.uni-bayreuth.de/docs/symbols/src/src_options.js.html

Cheers
Reply all
Reply to author
Forward
0 new messages