# Simple Machines Community Forum

## Customizing SMF => SMF Coding Discussion => Topic started by: Ian Wild on June 16, 2018, 01:58:42 PM

Title: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Ian Wild on June 16, 2018, 01:58:42 PM
Hi all,

It's been a while since I was last on here (over 10 years :o) but I'm back with more work on incorporating math notation editors into SMF - in this case SMF 2.0.15 and fMath.

Just for a bit of background, DragMath (http://www.simplemachines.org/community/index.php?topic=258518.0) has "kind of" been abandoned - Chris Sangwin (http://www.maths.ed.ac.uk/school-of-mathematics/people?person=439), who is responsible for the STACK project (of which DragMath is a part) isn't progressing development of DragMath at the moment so I've been focusing on fMath (http://www.fmath.info/) as an alternative. At the moment this works in conjunction with the MathJax mod (http://custom.simplemachines.org/mods/index.php?mod=4077).

I have put together a new package mod for SMF 2.0.15, which is currently available from http://luminaconsultancy.com/wp-content/uploads/2018/06/SMF-fMath-0.0.1.zip

The project itself is fully available on GitHub at https://github.com/iandavidwild/SMF2.0-fmath-mod

... I now know how to build a new package :D - see my comments from 2007 at http://www.simplemachines.org/community/index.php?topic=192052.0

I would be grateful to know what you all think.

Thanks,

Ian.
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: GigaWatt on June 16, 2018, 02:24:44 PM
I think it's great somebody actually did some development in this field, scientific mods ;).

I run an electronics forum, so I don't really need a whole equation editor (maybe in some rare cases, but this is in 2 or 3 posts a year, when some of the members start discussing some theoretical stuff in the audio section :)... audiophiles, go figure ::) :)), but what I actually needed was a modification of this (https://custom.simplemachines.org/mods/index.php?mod=3054) mod, except I needed it to use Greek letters like Ω, μ, ω, Σ, δ, π, τ, φ, ect. I started doing some of the work, but it's not finished yet. I'll make it public when it is ;).

Although, I have to add that the mod is a little large (unpacked 180MB, or so)... the fonts it uses take up a large portion of that. Can't this be cut down to, one or two fonts?
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: d3vcho(); on June 16, 2018, 02:57:24 PM
I know about a Spanish mathematics SMF forum that is still running 1.1.x because they are using a LaTeX mod for that version, and couldn't find a way to convert to 2.0.x. I think that this will be an interesting choice for them to finally decide to convert to 2.0.x.

Thanks for your work, and welcome back :)
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Ian Wild on June 17, 2018, 04:35:01 AM
Hi GigaWatt and thanks for your message.

I run an electronics forum, so I don't really need a whole equation editor (maybe in some rare cases, but this is in 2 or 3 posts a year, when some of the members start discussing some theoretical stuff in the audio section :)... audiophiles, go figure ::) :)), but what I actually needed was a modification of this (https://custom.simplemachines.org/mods/index.php?mod=3054) mod, except I needed it to use Greek letters like Ω, μ, ω, Σ, δ, π, τ, φ, ect. I started doing some of the work, but it's not finished yet. I'll make it public when it is ;).
Have you taken a look at MathQuill (http://mathquill.com)? I have a semi-working mod that will add this to a forum. This should be with us soon and I'll make this one public too. I'm thinking that MathQuill would be a great way for my students to learn LaTeX.
Although, I have to add that the mod is a little large (unpacked 180MB, or so)... the fonts it uses take up a large portion of that. Can't this be cut down to, one or two fonts?
Sadly yes your're right :( the fMath editor itself is very powerful (coming with different themes and so on). I've been trying to reach out to the author of fMath but so far haven't had a response - I don't want this plugin to be based on a dead project :o

Thanks again,

Ian.
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: GigaWatt on June 17, 2018, 06:02:07 PM
No, actually I only searched the SMF mods site. The mod in the link I provided is really close to what I need... with the exception that I have to rework it ;D.

I took a look at what MathQuill is and no, it doesn't actually suit my needs. You can write equations with it it can solve equations (useful, but not too useful on my forum), but you can't set custom symbols (Greek letters in particular) with it. See, I only need to be able to write "the resistance of the resistor is 2.2KΩ" without having to do a copy/paste of the symbol Ω (as I did now). That's why the mod I pasted the link to is exactly what I need... at least in form, I still have to edit the symbols :S. Basically, all I need is a simple symbol insertion tool ;).

I hope you do reach the fMath author because it does seem like a powerfull editor. As I wrote, I don't need this kind of equation edition power ATM, but if you think I can help in any way (code edits, testing, I'll have a test forum up and running in no time ;)), I'll be glad to help ;). My forum is mostly populated by pro/semi pro users in the field of electronics and nobody is actually that much into math (unfortunately ::)), but once (upon a time :D) I was thinking about opening a local forum about math problems, but this was a long time ago and I kind of gave up on the idea since I had to do a lot of things manually (customizations), but if there's a mod that can automate the process, integrate an equation editor inside the regular text editor, this might be incentive enough for me to go back and resurrect my old math forum idea ;).
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Study Force on June 18, 2018, 01:14:54 PM
Would love to see this in action, any demos?
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Kindred on June 18, 2018, 01:20:47 PM
https://custom.simplemachines.org/mods/index.php?mod=1111
https://custom.simplemachines.org/mods/index.php?mod=4077
https://custom.simplemachines.org/mods/index.php?mod=2867
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Study Force on June 18, 2018, 01:22:10 PM
@ Kindred, the first one doesn't support https. While link 2 and 3 are pretty much identical. I was hoping this mod would include an editor
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Ian Wild on June 18, 2018, 01:56:10 PM
Hi all,

I've just been putting together a fresh install of SMF for the 'YourMathsTutor' forum at https://forum.yourmathstutor.info. Please do feel free to sign up if you wanted to check out the plugin in action (the fMath button has a 'pi and pencil' graphic on it).

While putting this together I noticed that there were some case sensitivity issues in the package I uploaded previously (the YourMathsTutor forum is deployed on Linux but I built it on Windows - I know: my bad :( ) so I have put together a new package here:

https://luminaconsultancy.com/?attachment_id=178

Thanks :)
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: GigaWatt on June 19, 2018, 12:26:43 AM
I was hoping this mod would include an editor

Exactly the problem I ran into when I had the math forum idea... nobody likes to write codes without seeing what the end result would be. In this particular case, a WYSIWYG editor is really needed.

How do you use it? It tried using it on your forum, but when I click the Pi button, BBCode doesn't appear (a bug ???).

And, as Study Force asked, does the fMath mod include an editor with a realtime preview? Or is the Preview button the only way to get a preview ???.
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Study Force on June 19, 2018, 12:35:52 AM
I was using a Xenforo forum and they had this incredible math editor. I would surely pay for an add-on like that
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Ian Wild on June 19, 2018, 10:25:44 AM
Thanks GigaWatt for checking out my forum :) The way I have it set up is to have the fMath editor generate the LaTeX and use the MathJax filter to typeset it. That's partly because here in the UK that's how students will be expected to generate math notation. I've just tested it again and it seems to work okay, although the site is a bit of a work in progress so it wouldn't surprise me if there was an issue.

Study Force: do you know which math editor they had incorporated in the Xenforo forum you were using?

Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: GigaWatt on June 19, 2018, 05:27:00 PM
Not related to this thread, but I'd advise you to use this (http://www.simplemachines.org/community/index.php?topic=531660.msg3776163#msg3776163) guide on how to set up some of the registration questions. Not everybody knows that Marry had a little lamb :D.

The way I have it set up is to have the fMath editor generate the LaTeX and use the MathJax filter to typeset it.

You should have mentioned that a popup appears :D. I have an outdated popup blocker that's not really detecting popups as it's supposed to, so had to switch to IE, which also didn't work and finally switch to Chrome, which opened the popup ;).

In any case, the editor itself is pretty impressive ;).

(https://s20.postimg.cc/hqqof3ict/SHOT0031.png)

(https://s20.postimg.cc/5c3wetoal/SHOT0032.png)

(https://s20.postimg.cc/8671sfb31/SHOT0033.png)

Although, it would be even nicer if a new editor popped up under the regular text editor, in the same window (I guess I'm asking for too much :D). Now that would be really cool ;).

And it's not working for derivatives (differentials), since I tried to input the code for the equation in the pics above and it just kept returning this error.

Code: [Select]
Undefined control sequence \DifferentialDx
This is the LaTeX code.

Code: [Select]
$y = \int_{- 1}^1 e^x \DifferentialDx$
But, seems to work with this code.

Code: [Select]
$y = \int_{- 1}^1 e^x\;\mathrm{d}x$
(https://s20.postimg.cc/lqxtrf8ul/SHOT0048.png)

Seems that the generated LaTeX code is not correct ???.
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Study Force on June 19, 2018, 11:20:07 PM
Mary had a little lamb isn't a good question...

I've downloaded the math editor, it's good but not great. For example, it isn't intuitive, like when you write '^', it doesn't understand that it's a superscript.

Regardless, it's a lot better than what I'm using at the moment.

Thank you
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: GigaWatt on June 19, 2018, 11:30:45 PM
Mary had a little lamb isn't a good question...

It's not that it's not a good question... well, now that I think about it, you're probably right, it's not a really good question :D.

I was thinking more in the terms of... well, most of native English speakers will probably be able to answer that question, but not non-native English speakers. Not everybody went to sleep with "Marry had a little lamb" while they were kids.

All of the questions are sort of like that. Native English speakers will know the answers, but most non-native English speakers probably won't... or would have to Google the answer.

I've downloaded the math editor, it's good but not great. For example, it isn't intuitive, like when you write '^', it doesn't understand that it's a superscript.

Yeah, I also noticed this. It looks like it doesn't respond well to direct input in the LaTeX translation. The trick is to reload the page... at least that's what worked for me.
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Study Force on June 19, 2018, 11:39:21 PM

In terms of the mod, I feel like it's dated and not fluid. That's my main issue with it, though it is highly functional. Given our options, it's the best one out there. Mine's a lot more basic but way more fluid.
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: GigaWatt on June 20, 2018, 12:37:40 AM
In terms of the mod, I feel like it's dated and not fluid.

Agreed.

That's my main issue with it, though it is highly functional.

=||=

Given our options, it's the best one out there.

Yes, it's the best I've seen too... though I've seen only two other, which were better, not as functional, but as you said, more fluid. They were on proprietary scripts though.
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Study Force on June 20, 2018, 12:41:44 AM
Do you still recall the websites that used them?
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: GigaWatt on June 20, 2018, 01:00:35 AM
One was on on the department for electronics at the university I attended. It was supposed to be sort of a forum for professor/student relations, questions, etc. You couldn't get in the site without a username and a password thought. If you're a student, the username was your student index ID, the pass was a random string sent to your university email address and you couldn't change it. I think they had some sort of an arrangement with the computer department and they managed it, since I asked once or twice about changing my password and all of the professors and staff kind of looked at me like I was asking for a passing grade for a course I still haven't attended :D... which kind of led me to believe that they didn't know a damn thing about the site :D.

The other one was an IEEE site or a subdomain... can't really remember... I was doing some research on 3G networks, once again, in my student days :), and I ran into this site that I THINK was either a redirect from an IEEE site or a subdomain... can't really recall. In any case, there were some equations on probability theory and statistics and you could edit them, but the changes had to be approved by an admin, so... I just kind of messed around with the editor :D. Really powerful... not as this one, but really responsive and, like you said, fluid.

The one we had on the university site was a bit more powerful than yours. It had more options, like differentials and integrals, but nothing as complex as the one in this thread... I mean, come on, three dimensional curve integrals :D... I've only seen that in magnetism and math theory books, nowhere else :D.
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Study Force on June 20, 2018, 01:12:52 AM
I got the impression you found them on an SMF forum, that's why I requested the link. I've used Desire 2 Learn before, which is a platform used by most colleges, and their editor is great. I dug into the code and found that they lease a software. Like you said, a paid proprietary solution. I'll install this one on a test website, and I'll try to cut out as much as I can, like the double and triple integrals lol I'm certain it's possible
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: GigaWatt on June 20, 2018, 01:20:49 AM
Maybe one of the two sites I mentioned used this proprietary solution ???... who knows :). Well, for what it's worth, I hope it was the IEEE redirect :D... that editor was so cool, before it's time... this was back in 2007, 2008... I think... and it was fluid and responsive and the cursor was not just jumping from item to item, it had arrow keys integration and it did exactly what you wanted it to. Very similar to a regular text editor :).

EDIT: I don't think you can cut out anything :S... I think they're vectorized... part of a font :S... that's why the mod is so big :S. You could probably cut down on font solutions (different types of appearance of the same equation), I think that would be doable ;).
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Ian Wild on June 21, 2018, 10:25:39 AM
Thanks again for checking this out. I'll have a look at the issue with the \DifferentialDx tag not rendering properly. I'm suspecting that this is to do with the MathJax plugin (which would render the LaTeX) rather than the LaTeX that's being generated. But, again, I'll check this out.
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: GigaWatt on June 21, 2018, 12:58:46 PM
I found the mathrm{d}x notation while searching online for "derivative LaTeX code" trying to fix the "Undefined control sequence" error. That is supposed to be the default LaTeX notation tor form a differential at the end of the equation. Has the default notation for a derivative/differential changed in LaTeX? Since that (\DifferentialDx) is the LaTeX code that the equation editor generated.
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Ian Wild on June 23, 2018, 05:20:50 PM
Hi GigaWatt,

As mentioned previously, I'm using the MathJax plugin to render LaTeX but, just looking quickly through the list of supported commands (http://docs.mathjax.org/en/latest/tex.html#supported-latex-commands), I can't see \DifferentialDx. How you typeset the dx is a bit of a minefield anyway (for example see this tex.stackexchange.com thread (https://tex.stackexchange.com/questions/14821/whats-the-proper-way-to-typeset-a-differential-operator))

I still haven't heard from the author of the fMath plugin so I think I'm going to put together another mod based on MathQuill (I should be able to refactor the most of the code).

EDIT: I've changed the verification questions on the YourMathsTutor forum. Thanks for that advice!
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: GigaWatt on June 23, 2018, 05:39:53 PM
Yeah, I can't find the command on the MathJax list either, but that's what the editor wrote when I automatically (through the buttons of the editor) chose an integral with an exponent.

Code: [Select]
operatorname{d}
Which is exactly what I did manually.

Code: [Select]
mathrm{d}x
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Ian Wild on July 03, 2018, 10:06:59 AM
Hi again,

I've just had a response back from the developer of the fMath editor (Ionel Alexandru) to say that he's happy with the way I'm using it (along with the well-deserved attribution to his work, of course) so I'll have a go at submitting the mod back to the community at the mod site now...

Thanks all :D
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: GigaWatt on July 03, 2018, 10:10:43 AM
Did you check the problem with the differential at the end of an integral?
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Ian Wild on July 03, 2018, 10:28:24 AM
Hi GigaWatt,

Oh yes you're right: I'd forgotten about that. Also, I need to make sure there are no redundant files in there and that the JS is minimised.

I'll let you know when I get those issues sorted.

Thanks again,

Ian.

Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: GigaWatt on July 03, 2018, 10:31:28 AM
OK ;).
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Ian Wild on July 03, 2018, 01:01:04 PM
So I've been taking a deeper look into the issue with '\DifferentialD' and I think the issue is that the MathML specification says we should be using the &DifferentialD; entity but the rest of the world (it seems  ::) ) says that really we should be using 'upright d'. I'm using the MathJax mod to render the math notation and the issue with 'DifferentialD' has been discussed there too (see https://github.com/mathjax/MathJax/issues/1237)

For example, in LaTeX an anti-derivative would, usually, be something like:

Code: [Select]
\int x^4 \mathrm{dx}
... although there doesn't seem to be an agreement on this.

Internally the fMath editor is using MathML so the move away from the DifferentialD entity to '\mathrm' markup was looking tricky :o so I replaced it with the letter 'd' ;D

I'll send an email to Ionel (the fMath editor's author) later to see what he thinks about all of this. I guess the other alternative is to filter the LaTeX returned by the editor but that just seemed a little bit clunky.

Anyway, I've updated the plugin on the Your Maths Tutor website. There are a couple more configuration improvements I'd like to make and then I'll try submitting it to the mod site.

Thanks again guys for your help :)
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: GigaWatt on July 03, 2018, 06:20:54 PM
No problem, happy to help ;).
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Ian Wild on July 04, 2018, 04:27:35 AM
Hi all,

I now have a new version of the fMath plugin, available from https://luminaconsultancy.com/?attachment_id=184 (https://luminaconsultancy.com/?attachment_id=184), that not only uses 'Latin d' instead of the &DifferentialD entity for derivatives but also includes the following changes:

1) New configuration options to allow an administrator to specify 'open', 'inline open' and 'close' tags - what these are will depend on the LaTeX filter you have installed.
2) A checkbox on the editor to allow you to specify if you want inline notation.

(https://s8.postimg.cc/x32bppoyd/smf_f_Math_editor_config.png)

(https://s8.postimg.cc/3nwngps4l/smf_f_Math_editor_example.png)

I've also minified the main fMath script which will obviously speed things up for end users but didn't make a lot of difference to the overall size of this mod  :o

I'll have a go later at submitting it to the mod site :)

Cheers,

Ian.
Title: Re: Incorporating maths expressions (LaTeX notation) to SMF 2.x
Post by: Ian Wild on July 04, 2018, 05:03:11 PM
After a discussion here (https://www.simplemachines.org/community/index.php?topic=561063.0) about how stupidly big this mod was originally (due to fMath editor's 50Mb footprint) I've split the package into a wrapper mod (which is a standard SMF package) and a separate editor repository, available on GitHub, which will need to be installed separately.

I've submitted it to the mod folks so hopefully everything will be okay with it!

Thanks again guys for your help :)