# Request: Plugin for mathematical expressions

#### 1marianSep 07, 2018 17:04

Hi there,
I am new to b2evo and have not yet found a solution as how to write mathematical formulars into a web page. Is there a plugin, e.g. MathJax (www.mathjax.org), or a similar tool available?
Thanks,
Marian

#### 2amounSep 08, 2018 11:17

Hi Marian

Althought this forum doesn't allow HTML code my b2evo site does so I can type expressions via the character codes, but sure it would be good to have a plugin that would allow a simple click like a virtual keyboard.

How many expressions to you anticipate would suffice, lets say for a simple version?

#### 3amounSep 08, 2018 11:59

The reason I ask how many expressions as it is relatively easy to modify an existing plugin to add a few terms

As examples
I modified a plugin to add a target attribute to the links tab and added various extra buttons for styling for example http://rogerlovejoy.net/blog/b2evo.php/my-tags-plugin.
So it is possible to add buttons for any character to be inserted and if you want a big set then yes a new plugin would be convenient.
Apart from being busy and not in urgent need for such it sounds like a nice little script to make, but hey! maybe there is one or you or someone would like to make it sooner than later.

Can you hack an exisitng plugin as I've shown, as if so it's worth a try on your own :)

You could try and modify one of the existing plugins as I have shown and just add a &plusmn, &micro; to get the process working then you can add whatever you like :}

#### 4amounSep 08, 2018 13:54

As a further example I have modified a plugin as explained above.
I added a line to [plugins/mytags_plugin/_mytags.plugin.php]

Go to my site http://rogerlovejoy.net/blog/b2evo.php/math-terms to see efforts so far

The image below shows how it looks in the post creation/editing mode. You can see the button just above the [Teaserbreak][/s]
See #8 below

MoreButtons[MoreButtons.length] = new AnotherButton( 'math_1','&plusmn;','maths','<span class="math1">&plusmn;</span>'
);

I'm not saying this is a definitive way of doing it, but it works until a more sophisticated way in made, as can add exactly the terms you want to use as your own specific plugin.
EDIT
If you are really not up to doing it yourself, maybe let me know exactly what terms you want and I will find time to do it for a laugh.

#### 5amounSep 08, 2018 14:26

Ok you've got me going. I'm going to make a new plugin for my own limited use.
The questions arising now are

1. Whether to have a class for each term so that the font can be formatted or leave that to just default adjustments by html tags (big,small, bold, em) etc.
2. If to have it functional so that calculations can be made live, a bit dodgey maybe as someone may find a way of entering a malicious function.

#### 6amounSep 08, 2018 15:23

Just to confirm I have modified a plugin just for math expressions/terms call [_mymathterms] so will make it available to you soon.
It will be simple but you will be able to add any expression you want. Initially this will mean adding code which is very simple, maybe later a user will be able to add via the back-office.
Out on the town tonight as it's Sat eve soon in the UK so won't get much done in the next few hours or days maybe.

This won't be an 'official' plugin for now as I'm adapting an existing one given I'm not sure of the process from start. However once you and I are happy with it we can make it public proper.

#### 7marianSep 08, 2018 17:51

amoun,

This is awesome. I am out of town, too, but will read through your posts once again over the weekend. I am not a developer, so I am not sure whether I have understood everything, let alone whether I can do it, but I thank you very much for your support.
I will come back to this forum next week.

Thanks again a nice weekend to all,
Marian

#### 8amounSep 08, 2018 20:47

No problem
The Unicodes are at
https://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode and
https://www.compart.com/en/unicode/category/Sm
Typical use is [&#x2211;] for the Capital Sigma

With a dozen or so it's easy to hard code as I have done, but if you want (any and all - hundreds) then an input box could be used and you could type in the Unicode from one of the lists above. But note that you can just type in the code in any post that doesn't block Unicode inserts.

As mentioned &#x2211; resolves as the Big Sigma on my sites

If you want to format each symbol it would need another box to enter css properties. So not knowing the details I'm going to stop adding symbols to my first effort as shown on my site

My working example is now at http://rogerlovejoy.net/blog/b2evo.php/math-terms

#### 10amounOct 12, 2018 00:28

Hi again
Just looking at https://www.mathjax.org/#demo and https://www.mathjax.org/#gettingstarted
I put the script
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-MML-AM_CHTML' async></script>

Had to double the string character $$to get it working When$$a \ne 0$$, there are two solutions to (ax^2 + bx + c = 0) and they are$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.

#### 11amounOct 12, 2018 01:33

Hi @marian
I've made a plugin to add the code to the header, so there's no need to hack the script etc. Let me know if you would like a copy

#### 12amounOct 12, 2018 01:47

Of course I have just realised that the single line of code can be added to the html >head section via [settings > advanced]