h5p math latex

Hello! I was so glad to see the release of math formulas in h5p. Thank you very much.

I had installed the library for it. I had learned the basics of latex.

But I don't understand where and how should I use latex "code".

When I insert it into the h5p editor in the process of content creation it is not shown right on the page

 1)I create latex code in the editor with all the commands like \documentclass[a4paper,12pt]{article}

or just for the formula 

(like \begin{equation}\label{eq:fourierrow}

f(x) = \frac{A_0}{2} + \sum \limits_{n=1}^{\infty} A_n \cos \left( \frac{2 n \pi x}{\nu} - \alpha_n \right) 

\end{equation})

 2)I create contenet "fill in the blanks" or drag and drop types on my Drupal7 site page on the page with the url

node/add/h5p-content

3)In the task desription page block I insert all the code from the editor or its part

But it is nt working

See screenshoots.

E.g. I had created the code

"

\documentclass[a4paper,12pt]{article}

\usepackage{cmap}

\usepackage[T2A]{fontenc}

\usepackage[utf8]{inputenc}

\usepackage[english]{babel}

\begin{document}

\maketitle

\begin{equation}\label{eq:fourierrow}

f(x) = \frac{A_0}{2} + \sum \limits_{n=1}^{\infty} A_n \cos \left( \frac{2 n \pi x}{\nu} - \alpha_n \right) 

\end{equation}

\end{document}

"

Where should I insert this code?

While waiting for the answer I had the idea how to do it.

I just needed to insert it like in the example on https://h5p.org/mathematical-expressions

after changing "some LaTeX" for my text in the phrase 

"\( some LaTeX \)"

so it became e.g.

\( f(x) = \frac{A_0}{2} + \sum \limits_{n=1}^{\infty} A_n \cos \left( \frac{2 n \pi x}{\nu} - \alpha_n \right) \)

 

BV52's picture

Hi ksen-pol,

If I'm not mistaken this is already working for you. If you have any other questions feel free to post in the forums.

-BV52

Thank you. I can use Latex with h5p now but have problems with some symbols and settings.

I work on the Drupal7 site now.

E.g. after adding  some commands and saving new pages I have messages like "Misplaced &", or Undefined control sequence \cdota

(see screenshoots)

I test commands before using them on writelatex.com online (or overleaf.com). And Commands work well there.

How can I fix this problem on my site with h5p?

Can I add some packages

(like  "\usepackage{amsmath,amsthm,amssymb}" )

by editing some files of the module? In what files can I add packages and make setting for latex?

otacke's picture

Привет ksen-pol!

H5P does not provide a full LaTeX implementation, but uses MathJax to render mathematical formula. In consequence, you cannot add your packages to broaden the functionality.

If you want to check what H5P can render, you should use the live demo of MathJax. For your examples, e.g.

\( S = \frac{1}{2} \cdot a \cdot b \cdot \sin(\alpha) \)

 works just fine.

Thank you very much! It works.

Can you recommend a good tutorial about mathjax syntaxes?

E.g. how can I use images, image references and hierarchy (like section, subsection and etc) commands?

otacke's picture

Hi ksen-pol!

As I mentioned: "H5P does not provide a full LaTeX implementation, but uses MathJax to render mathematical formula." Don't confuse MathJax with a fully fledged LaTeX interpreter. It does solely support mathematical expressions.

Best,

Oliver 

Thank you. I think I understand now. Can you give me a link to the tutorial to the rules of syntaxes for my formula to be displayed on h5p-mathjax site?

And I see here that I can edit some settings. Can I edit it for mathjaх to show not only LateX but also Asciimath?
e.g. with mathjax I can use 

<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/latest.js?config=AM..."></script>

and the formula:

 

`sum_(i=1)^n i^3=((n(n+1))/2)^2`

 

 

otacke's picture

Hi ksen-pol!

I am sure, if you use math latex tutorial in a search engine of your choice, you will find some tutorial. There's none in particular that I can recommend.

You can configure MathJax the way you want. If you need AsciiMath support, you need to add it to the list of input processors (see http://docs.mathjax.org/en/latest/options/input-processors/AsciiMath.html):

The options below control the operation of the AsciiMath input processor that is run when you include "input/AsciiMath" in the jax array of your configuration or load a combined configuration file that includes the AsciiMath input jax.

Best,

Oliver

Sure I had found a lot of math LaTex tutorials. But mathjax does not show all Latex formulas and I could not find in mathjax documentation any information about Latex that particulary suits mathjax. So if you also can not recommend special tutorials may be I should look for this infromation on Mathjax forums. I'll do so.

But how did you know that 

"\( S = \frac{1}{2} \cdot a \cdot b \cdot \sin(\alpha) \) "

will work

instead of  

"S=\frac{1}{2}\cdot&a\cdot&b\cdot&\sin\alpha" 

that did not work with Mathjax but worked in other Latex readers. 

About Ascii: I see that I can include a AsciiMath section in MathJax.Hub.Config()

But can you help me to find the answer,

where should I use the needed code  (ofAsciiMath section in MathJax.Hub.Config) for it to work in h5p interactive content?

otacke's picture

Hi ksen-pol!

I knew that my version would work, because the ampersand inside yours is a reserved symbol for alignment commands - and well again, MathJax is meant for rendering formula, not for supporting layouting, etc. It may simply be very strict when interpreting the input while other LaTeX interpreters are not. You could also ask: Why do browsers render pages differently ...

The documentation page for mathematical expressions within H5P holds configuration examples for Drupal, WordPress and moodle. If you have a look at the property config, you will notice that it's exactly the same as what's called MathJax.Hub.Config in MathJax's documentation. The only transfer that's needed is to define the properties in PHP instead of JavaScript/JSON, e.g.

"jax": ["input/TeX", "output/HTML-CSS"]

would need to become

"jax" => array("input/TeX", "output/HTML-CSS")

 

Best,
Oliver

apienk's picture

Actually, you can add Latex extensions to H5P Mathjax. In order to do so, you need to define them globally in the configuration of your CMS. For example in Wordpress, which I use, you can add extensions by modifying the "extensions" line in wp-config.php. I have loaded the mhchem extension for chemical formulas like this:

"extensions" => array("tex2jax.js", "TeX/mhchem.js"),

Tested. Works. If you use Drupal or Moodle, you get the idea.

Sorry for necroposting but it may still help someone. :)