MathJax and miserver

MiServer is Dyalog's APL-based web development framework

Re: MathJax and miserver

Postby bwyork67 on Wed Nov 08, 2017 11:45 pm

Brian

Wow!!! This is great. A template solves a lot of my problems. I will pull down
your MathJax website and follow the example.

For RESTful I am envisioning the student client who fills in an input box in Latex and data is returned to miserver, where I do some processing (my own apl code) before causing the Latex to be displayed in a field on the
the client's browser, as well as some additional content based on my apl code.

I am assuming that RESTfull will be more efficient that sending an entire page.

Bryant
bwyork67
 
Posts: 13
Joined: Tue Nov 12, 2013 7:01 pm

Re: MathJax and miserver

Postby bwyork67 on Fri Nov 10, 2017 1:39 am

Hi Brian

I did all the modifications you suggested and they work fine. I am having
trouble with the following:

getting input from an editField as a Latex string; triggering the callback function,
and then having the callback function render the Latex in a div or another editField.

I probably do not understand fully how "replace" works.

If you have some ideas, I welcome them.

Thx

Bryant
bwyork67
 
Posts: 13
Joined: Tue Nov 12, 2013 7:01 pm

Re: MathJax and miserver

Postby bwyork67 on Fri Nov 10, 2017 11:18 pm

Hi Brian
I am having difficulty replacing a div dynamically and forcing MathJax to typeset
the new math. I tried following the description for dynamic pages but cannot
get the implementation of dynamic MathJax to work.

Here is a link to the documentation:
https://docs.mathjax.org/en/v1.0/typeset.html

Any help would be greatly appreciated.

Thx

Bryant
bwyork67
 
Posts: 13
Joined: Tue Nov 12, 2013 7:01 pm

Re: MathJax and miserver

Postby Brian|Dyalog on Mon Nov 13, 2017 8:28 pm

Hi Bryant,

Sorry for the delay in my reply - I've been travelling the last couple of days and finally had a chance to sit down and take a look at dynamically generating MathJax output based on form input. Here's what I came up with...

I created a new page based on the TeXPage class we used in my last example...
Code: Select all
:Class texform : TeXPage

    ∇ Compose
      :Access Public
      :With Add _.Form
          ('#inp'Add _.Input'text' '' 'TeX/LaTeX input:  ').style←'width:400px;'
          Add _.br
          (Add _.Button'Go!').On'click' 'myCallback'
      :EndWith
      '#output'Add _.div
    ∇

    ∇ r←myCallback
      :Access public
      r←'#output'Replace(New #.TeX(Get'inp')).Render
      r,←Execute'MathJax.Hub.Reprocess()'
    ∇

:EndClass

So, I...
  • add a _.Form (Dyalog-enhanced <form> element - remember that Dyalog controls begin with uppercase letters - _.form would be the raw HTML <form> element).
  • to the form I add a _.Input (Dyalog-enhanced <input> element) that has an id and name of "inp". I also make the input field 400px wide.
  • and a _.Button (Dyalog-enhanced <button> element), I also define a callback to call the function "myCallback" when the button is clicked
  • outside the form, I add a _.div with an id of "#output"
  • I defined the myCallback function to
    • grab the value "inp" (the value of the input element we defined above)
    • create a new instance of the TeX widget with an argument of the "inp" value
    • render the instance (this creates HTML)
    • tell the client to replace the content of the "#output" division with the rendered HTML
    • tell the client to execute the MathJax.Hub.Reprocess method which will re-render any MathJax on the page (which now happens to include the equation we just created above)
I've uploaded the code to the MathJax MiSite in GitHub.

I hope this helps!
/Brian
User avatar
Brian|Dyalog
 
Posts: 71
Joined: Thu Nov 26, 2009 4:02 pm
Location: West Henrietta, NY

Re: MathJax and miserver

Postby bwyork67 on Mon Nov 13, 2017 11:50 pm

Brian

Thanks, You solved my problem (again!). I was trying to get MathJax to reprocess the page
with the MathJax.Hub.Typeset() command.

I have been pasting things together and trying
to understand how miserver works by reading the examples.
Is it possible for me to get a copy of your workshop slides from Dyalog 2015.

Thanks

Bryant
bwyork67
 
Posts: 13
Joined: Tue Nov 12, 2013 7:01 pm

Previous

Return to MiServer

Who is online

Users browsing this forum: No registered users and 1 guest