Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

added asciimath.js and asciimath.html#818

Open
tom-berend wants to merge 3 commits into
jsxgraph:developjsxgraph/jsxgraph:developfrom
tom-berend:developtom-berend/jsxgraph:developCopy head branch name to clipboard
Open

added asciimath.js and asciimath.html#818
tom-berend wants to merge 3 commits into
jsxgraph:developjsxgraph/jsxgraph:developfrom
tom-berend:developtom-berend/jsxgraph:developCopy head branch name to clipboard

Conversation

@tom-berend

Copy link
Copy Markdown
Contributor

Dear Alfred (and team),

This PR adds native AsciiMath processing to JSXGraph. There are no flags or attributes to set; simply start a string with a backtick ( ` ) and the text is rendered as AsciiMath.

board.create('text', [1, 4, '`d/dxf(x)=lim_(h->0)(f(x+h)-f(x))/h']);

Of course, you can use AsciiMath in dynamic labels. See examples/asciimath.html (image below).

AsciiMath is a simple and elegant alternative to LaTeX. Making it 'native' will encourage math notation in JSXGraph, and resolve issues related to hosts running different versions of MathJax. here

This PR includes recent improvements in fonts and matrix handling contributed by Dr Peter Lippman, who maintains the AsciiMathML project.

MathML is supported by all major browsers, but Chrome sometimes requires specifying a math font. This can be done by adding the following line to the HTML header:

    <link href="https://fonts.googleapis.com/css2?family=STIX Two Math" rel="stylesheet">
image

@alfredwassermann

Copy link
Copy Markdown
Member

Dear Tom,
many thanks for this PR to include ASCIIMathML!
Please, allow a few questions:

  • As far as I could see, you took the latest version ASCIIMathML.js from https://github.com/asciimath/asciimathml and extended it for JSXGraph. Would it be possible to encapsulate the JSXGraph-specific extensions (and deliver these with JSXGraph) and let the applications load the original ASCIIMathML.js? In that way, we are nearly independent from new versions of ASCIIMathML. I.e. my dream is that we include in JSXGraph only your changes and the user has to load some version of ASCIIMathML as external resource from wherever.
  • We already had/have ASCIIMathML support in JSXGraph, but I did not test it for at least 10 years. The previous approach was that the attribute useASCIIMathML:true has to be set. Then JSXGraph encloses the text string with backticks and let's ASCIIMathML do its work. I guess that did never work for dynamic texts. But I would prefer that the attribute useASCIIMathML:true still has to be supplied, to distinguish the renderings with MathJax, KaTeX, or ASCIIMathML. Would you agree? If yes, we have to decide if the leading backtick has to be supplied by the user or is added by JSXGraph.

What do you think?

All the best, Alfred

@tom-berend

Copy link
Copy Markdown
Contributor Author

Dear Alfred,

I can understand if you don't want to include AsciiiMathML in core JSXGraph. And it is definitely your call. But here's some background.

ASCIIMathML.js is intended to work like MathJAX - it is an event-driven task that scans the DOM for text with backticks and converts them directly in the DOM. This has multiple problems, such as slow response and a lack of control over the environment.

This forum discussion referenced universities running Moodle with old versions of MathJAX, but anyone running in sandboxes has similar limitations.

To embed AsciiMath in JSXGraph in a natural way, the library should output HTML and use it in text, instead of modifying the DOM after the page is rendered. That way I only needed to modify 3-4 lines in text.js.

So I developed a modified version of ASCIIMathML.js that generates plain HTML. I built versions for TS and PHP for my own projects. I converted the TS version to look like JSXGraph code (object syntax instead of class syntax), and that's the version that I submitted.


I plugged the PR version of JSXGraphCore into my TSXGraph playground, and it is addictive to use. No flipping `useMathJax' between true/false, no extra setup. If I want a point's name in greek, it is simply `alpha.

I think math notation is so basic to JSXGraph that it should always be installed in every environment. No extra setup of the web page, consistent version, etc. If JSXGraph works, then AsciiMath works. But again, it is your call.

I did not test the old ASCIIMath flags, happy to do that if you like. But MathJax is a better solution because of Chrome fonts.

@tom-berend

Copy link
Copy Markdown
Contributor Author

Dear Alfred,

I suspect you don’t want to accept this PR, but are too nice to reject it. So you are waiting.

No worries, I won’t be upset. Well, actually, I WILL be upset. Because I believe that JSXGraph is a compelling educational tool that every first-year STEM student should learn and use, and math notation goes hand-in-hand with graphics for that educational purpose. But to get there, the tools must have a smaller learning curve.

For equations, AsciiMath has 90% of the expressive power of LaTeX, with about 10% of the learning curve. The engine is a few hundred lines of JavaScript and is generously licensed. The full manual is a single HTML page.


My first use of JSXGraph wasn’t interactive. I needed illustrations for a presentation, and JSXGraph generated high-quality images. I set up an HTML page on my laptop with your 'getting started' instructions, and coded the JS. I pasted screenshots of my constructions into PowerPoint.

I suspect that is a common use of JSXGraph. It is a tiny fraction of what JSXGraph is capable of, but still unique and wonderful.

Now my interest is in building tools for education. Here is the kind of presentation I want first-year students to be able to pull together: Walking with Coffee. This illustration captures the whole idea.

image

The labels in this image are simple, but still need LaTeX for proper fonts. For my presentation, I would have had to install MathJAX and learn LaTeX. If I had wanted equations for my image, I would have prepared them in a LaTeX composing tool, changed the backgrounds to transparent (in GIMP), and positioned them using PowerPoint.

Ha, ha. I'm joking. Too many layers and tools. It might make sense for a PhD candidate to spend the time learning the stack. Or someone writing a STEM textbook. But not a first-year student, certainly not a high-school student.

And that's not even where we want to go. I want the students to ANIMATE the image with JSXGraph, perhaps using the wonderful tools in your Math libraries.


I am continuing to work on making JSXGraph more accessible for students. I think TSXGraph and the playground are a good first step. Seamlessly integrating AsciiMath and JSXGraph would be another big step, and I have put considerable time into it.

I hope to show yet another step forward in October.

So please consider moving forward on this. My fallback is to integrate AsciiMath into TSXGraph, I will continue to work on simplifying the toolchain. But I also think it is the right direction for JSXGraph as an educational tool and a community.

@tom-berend

Copy link
Copy Markdown
Contributor Author

Dear Alfred,

I can't achieve the simplicity I want with AsciiMath loaded externally. But I understand and respect your concerns. Let me suggest a different way to move forward.

I will modify JSXGraph to expose 'poorMansTex()' from the JXG object so it can be found even after Webpack scrambles the code. Minimal logic changes (make sure that convertGeonextAndSketchometry2CSS still gets called, although I'm not sure how to test that).

Then when I set up a JSXGraph environment, I will inject AsciiMath (replacing poorMansTex) instead of relying on DOM events to find the tags. I can build this injection seamlessly into 'Simplified JSXGraph' as a demonstration.

But to proceed, I need you to delete this pull request. I can't 'sync' my fork to start again (my develop branch is ahead of yours, so github just tells me to have a nice day), and I'm afraid that deleting my repository with an open PR will mangle your repository in some awful way.

Hoping this is acceptable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.