Moodle and LaTeX

Moodle and LaTeX

by Colin Fraser -
Number of replies: 14
Picture of Documentation writers Picture of Testers
I am trying to work out how to use LaTeX inside Moodle, but I am having an issue with the comments. I can create a formula, no problems, and it renders fine, but if I write something like

If $f(x) = 3x + 7$ and $g(x) = x + 4$ then \[ f(x) + g(x) = 4x + 11 \] and \[ f(x)g(x) = 3x^2 + 19x +28. \]

I get the result in the image below. I need the good result, but I also need the example to show in ordinary text in the Google page. So how can I comment out things or prevent the LATeX plug-in from converting it? <pre> and <code> do not work...



Attachment LateXresponse01.gif
Average of ratings: -
In reply to Colin Fraser

Re: Moodle and LaTeX

by Colin Fraser -
Picture of Documentation writers Picture of Testers
And if I had looked I would have seen it doing the same thing here... so what is the issue?
In reply to Colin Fraser

Re: Moodle and LaTeX

by Marc Grober -
Sorry Colin but I am not quite sure what you want to accomplish, however, you CSM use the google chart API which will produce same result in moodle and google pages.

If you are asking about latex escape function that is available. There are lots of functions in latex though that are not implemented in moodle's filter

I would consider going with asciimath and setting fallback to googlechartapi - and it is possible that eventually an asciimath derivative may be integrated in google as I hope it will be in moodle. Among other features asciimath does make text inside tokens very simple.
In reply to Colin Fraser

Re: Moodle and LaTeX

by Mauno Korpelainen -

Colin,

can you add the lines or things you want to do to an attachment (some tex file or doc) - Tex filter is just sending the tags between delimiters (usually double dollars) to renderer (Mimetex or some local distribution of Latex) and you should have only latex or pure text inside delimiters.

If you have in editor for example html inside delimiters renderer tries to render it as text - not html. Latex does not understand html formatting.

And different distributions of (La)TeX use also different commands and symbols...

And if you want to show only syntax you can use backslash before dollar to render plain dollar $ as $$ \$ $$ (I have here spaces around \$ in ' \$ ' )

In reply to Mauno Korpelainen

Re: Moodle and LaTeX

by Colin Fraser -
Picture of Documentation writers Picture of Testers
Hi Marc, the story is a friend of mine, a principal, asked me to develop some Latex tutorials inside Moodle, for the Maths and Science staff at his school, him knowing I know a little about Moodle, and not knowing I knew nothing about Latex hahaha!!!!. So I downloaded MikTex installed it and realized it is actually quite easy to use to generate formula.

So rather than use MikTex, then generate PDFs and importing screen grabs to Moodle, which is time consuming, I thought I would just use Moodle. Activated the Latex filter and it works well, only a little too well. Testing it out I have run into this problem of it rendering the code used, then what should be html examples. Painful...

Hi Mauno, all I am using is the Moodle Latex Filter which is pointing at miktex latex and dvips exe files and ImageMagick. I kind of figured that it wasn't going to be so straightforward - and the fact it that it seems to render some elements I want as HTML in Latex and others it leaves alone - just really intriguing.

And of course, the intro in MikTex is that MikTex does not vary too much from Latex, so go to this latex site and do that tute. I did, and now want to move on with it.

Oh, I started out with the idea that I would use MediaWiki, to justify a school offering a Moodle/MediaWiki resource to sudents. As I am more familiar with Moodle, that seemed the better option.
In reply to Colin Fraser

Re: Moodle and LaTeX

by Mauno Korpelainen -

My local Vista is using MikTex ( and my plugindemo site is using TexLive ) so I think I can test any problems you have with MikTex but I just did not figure out the actual problem meaning what do you expect to happen with some tags - or latex images - or syntax ...

If you check file filter/tex/filter.php and functions string_file_picture_tex and tex_filter you notice that double dollars are not the only possible delimiters - in Wiki square parenthesis can cause some odd results etc.

More examples please - and for example a MS Word attachment where it might be possible for us to see what you hope to see...framed with red color wink

In reply to Colin Fraser

Re: Moodle and LaTeX

by Marc Grober -
Colin,
looks like there are a few issues involved and that the discussion on latex and asciimath in moodle docs ( mediawiki ) would help you along.

On the simplistic side, the statement below was done with the \text{} function:
$$\text{why is }\frac{x}{0}\text{ undefined?}$$

what drove me to asciimath was in fact the need to have a totally portable way to display math, where a typical latex installation was not available. Using the latexmathml that is included and the appropriate fallback you can produce results that display well without having to have latex.

With google, in addition to chartapi, invocation may available through the new script functionality (I don't have access to that so can't say for certain) and could possibly be implemented via etherpad code now that google has purchased and release it.

If you go to a site like artofproblemsolving you will find excellent tutorials but will end up banging your head against the wall because of limitations of moodle implementations, but there are free standing open public latex hosts and using them you could do "real" Tex and then embed same in other resources, as long as web access available. Here again asciimath makes a good deal of Tex available even where no web access by including js in dpc.
In reply to Colin Fraser

Re: Moodle and LaTeX

by Zbigniew Fiedorowicz -
To escape the TeX filter, enclose your input with triple dollar signs instead of double dollar signs. This will then display like this:

$$$\frac{x}{y}$$$ produces $$\frac{x}{y}$$

Here the first instance of \frac{x}{y} was enclosed by triple dollar signs and the second instance by double dollar signs.
In reply to Zbigniew Fiedorowicz

Re: Moodle and LaTeX

by Colin Fraser -
Picture of Documentation writers Picture of Testers
Muano, please find attached a word 2003 document, I don't know what version of Word you have but... as you running Vista, probably 2007... but seriously, I just cannot be bothered. (I want to dump Windows altogether, but to make the changeover to Linux is just too large a leap at this stage. or perhaps I am too lazy to make it.big grin)

I understand Marc about the asciimath, but my accomplice in crime wants to use MikTex. His argument is that more academic content and documentation needs to go onto the school server, Moodle is one way of doing this, and MikTex works in the Windows environment. So he is trapped by Windows too. And, as he is paying the bills, I am inclined to just give him what he wants, besides, I know less about ascimath than I do now about MikTex.

And Zbigniew, no sorry, looked good but didn't work - thanks for the suggestion, have filed it for use in MikTex.


In reply to Colin Fraser

Re: Moodle and LaTeX

by Mauno Korpelainen -

Ah - this Word document explains a lot.

When you take examples from tex files they usually have more commands for complete latex documents but tex filter is very simplyfied version of rendering Latex using some packages defined in settings of tex filter (administration menu).

If you want to use tex filter change single dollars to double dollars or use those square bracket delimiters (they don't work in wiki anyway).

But some tags like those equation tags don't look correctly aligned - not with MikTex or Tex Live - if they are used with Tex filter (first equation is left aligned and second goes to the right...). Still you could use other latex to produce same kind of content -

http://docs.moodle.org/en/Development:MediaWiki_TeX_test

has some examples that should work almost the same way in MikTex, Tex Live and TeTex - Mimetex is using many custom tags that other distributions can't use and on the other hand mimetex can't use all the packages, symbols and commands that other distributions can use. A little test:

HTML (italics):

If f(x) = 3x + 7 and g(x) = x + 4 then f(x) + g(x) = 4x + 11 and f(x)g(x) = 3x2 + 19x + 28.

Your one line example with double dollars and begin equation...end equation tags (note the first equation):

If $$ f(x)=3x+7 $$ and $$ g(x) = x+4 $$ then $$ f(x) + g(x) = 4x + 11 $$ and $$ f(x)g(x) = 3x^2 + 19x + 28 $$.

If $$ f(x)=3x+7 $$ and $$ g(x) = x+4 $$ then
\[ \begin{equation} f(x) + g(x) = 4x + 11 \end{equation} $$$
and $$$
\begin{equation} f(x)g(x) = 3x^2 + 19x + 28 \end{equation} \]


Centered example with begin array and end array:

$$ If \; f(x)=3x+7 \;and \; g(x) = x+4 \; then $$

$$ \begin{array}{lrr} & f(x) + g(x) = 4x + 11 & (1) \\ and & & \\ & f(x)g(x) = 3x^2 + 19x + 28 & (2) \end{array} $$
In reply to Mauno Korpelainen

Re: Moodle and LaTeX

by Mauno Korpelainen -

And like you can see here font size is not very similar in theme as font of Latex tags with 120dpi density so you might try to use smaller density in settings of tex filter or bigger fonts (Times new roman etc) on pages where you use maths and change tex filter to render pngs instead of gifs (other posts on maths forum)

Writing maths has always been a pain in moodle but it is slow and painful even with Word equation editor ... wink

In reply to Mauno Korpelainen

Re: Moodle and LaTeX

by Colin Fraser -
Picture of Documentation writers Picture of Testers
I deliberately went to a larger font in the TeXworks document, to produce a larger graphic, makes some rather myopic people look at what is there sometimes..smile

I know the people who are going to be reading it, and using MikTex, believe me, they will need me right in their face from time to time. Teachers.. all of them.

Anyway, you tips about proper alignment and such are good, and it is possible that in the end, I am going to have to use an image, in a table format, one side with the inserted tex and the other with the end result, and each line commented. Using pngs instead of gifs never thought about, but will try it now..

Thanks Muano, appreciate the time you have given me. Cheers.
In reply to Colin Fraser

Re: Moodle and LaTeX

by Mauno Korpelainen -

And note that you can't automatically use all packages of latex but you can add them to your tex filter settings. For example if you want to use colors you need to use LaTeX preamble like

\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage[usenames]{color}
\RequirePackage{amsmath,amssymb,latexsym}

to be able to render tags like

\displaystyle x_{1,2}=\frac{-b\pm\sqrt{\color{Red}b^2-4ac}}{2a}

or

\displaystyle \colorbox{red}{testing dollars}\sum_{i=1}^{p}\sum_{j=1}^{q}\sum_{k=1}^{r}\textcolor{blue}{a_{ij}} \frac{\textcolor{green}{b_{jk}}c_{kl}}{\colorbox{Orange}{ text}}

(double dollars or square bracket tags around them)

MikTex like Tex Live has a lot of such packages that people never use...

In reply to Colin Fraser

Re: Moodle and LaTeX

by Mauno Korpelainen -
It's a nice solution to use tex images in tables - so basicly you just add single images (like any other images - where ever they come from) to different places on page (tables, divs, spans) and with relative positioning you could even "stack notations"... wink
In reply to Mauno Korpelainen

Re: Moodle and LaTeX

by Colin Fraser -
Picture of Documentation writers Picture of Testers
Yep, that is about it, neat and tidy, gives everyone what they want and what they need.