## Mathematics tools

### cleaner latex rendering.

This discussion has been locked because a year has elapsed since the last post. Please start a new discussion topic.
cleaner latex rendering.

latex rendering on thornhawk and on my moodle site is noticeable different. When I render an equation on thornhawk, it renders very neat and clean. By when i copy that code and render it on my moodle site between double dollar signs, it displays it very choppy and messy. Is there a way to have my moodle site render latex clean just like how thornhawk does?

http://thornahawk.unitedti.org/equationeditor/equationeditor.php

Any input would be appreciate it, thanks

Average of ratings: -
Re: cleaner latex rendering.
Hi Frank,

Thornahawk is probably using LatexRender and your Moodle is likely using mimeTeX (where, to be fair, the image quality isn't that great). There are some instructions on how to integrate LatexRender and Moodle here...

http://nte.unifr.ch/blog/2005/04/18/integrating_latexrender_in_moodle/

The article is a bit out of date but it should give you an idea of what you need to do.

Hope this makes sense.

Ian.

Average of ratings: -
Re: cleaner latex rendering.
I have posted an issue on moodle's tracker with a patch that does what Mauno Korpelainen said.

Average of ratings: -
Re: cleaner latex rendering.

Yes, the main reason for poor output is usually Mimetex - almost any other distribution of latex could produce better quality images but I suppose you did not have the option to install or use other Latex.

It is possible to set latex to use png images instead of gif images, change dpi{dots-per-inch}, gammacorrection, fonts etc but in built-in Mimetex you can only set dpi from your tex filter settings or files of tex filter.

$f(x)=\int_{-\infty}^x e^{-t^2}dt$ in Codecogs and the same with TeX filter here in moodle.org $$f(x)=\int_{-\infty}^x e^{-t^2}dt$$

Average of ratings: -
Re: cleaner latex rendering.
Hi All,

I'm just playing around with LaTeX rendering on one of our (Ubuntu) servers. I've got the TeX filter configured so that the paths to the latex, dvips and convert binaries are set up correctly. I think it should be using these binaries instead of mimeTeX but how do I tell?

Also, I've tried editing latex.php, filter.php and pix.php so that it creates PNGs instead of GIFs (following the instructions given here). The file extension is now PNG but the file itself is still a GIF . Any idea how I can force it to definitely create a PNG?

Ian.

Average of ratings: -
Re: cleaner latex rendering.

I checked my files and I have actually modified four files:

1) In file texed.php change:

$image = md5($texexp) . ".gif";
$filetype = 'image/gif'; to$image = md5($texexp) . ".png";$filetype = 'image/png';

2) In file pix.php change:

$md5 = str_replace('.gif','',$image);

to

$md5 = str_replace('.png','',$image);

3) in file latex.php two changes:

$gif = "{$this->temp_dir}/$filename.gif"; to$gif = "{$this->temp_dir}/$filename.png";

and

unlink( "{$this->temp_dir}/$filename.gif" );

to

unlink( "{$this->temp_dir}/$filename.png" );

4) In file filter.php

$filename =$md5 . ".gif";

to

$filename =$md5 . ".png";

Note also that in 3) name of variable is $gif - not$png... but I think you may need 1) to get the correct file type.

You could test if your site if using Mimetex or the other distribution of LaTeX with some commands that do work in that other distribution but do not (both) work in Mimetex, try for example \diamondsuit\diamond\Diamond - Mimetex should not recognize the first one but for example TexLive gives 3 diamonds
$\300dpi \diamondsuit\diamond\Diamond$ (attached the same file as 300 dpi png file)

Average of ratings: -
Re: cleaner latex rendering.
I didn't realise that you had to change texed.php as well. Thanks for that.

I've still got problems, though

Moodle is still insisting on using mimeTeX to render the notation. Strangely, if I try the "Show command execution..." option in texdebug.php then everything seems to work fine and the image is created properly (as a png) using ghostscript, &c.. But if I try to include math in the course then it is definitely using mimeTeX. If I move the mimeTeX binary then nothing gets rendered at all. I've tried playing around with permissions but to no avail.

Any idea what's going wrong? I've been trying to get this to work for hours and I'm beginning to get a bit depressed...

Ian.

Average of ratings: -
Re: cleaner latex rendering.
Hi again,

After much fiddling around in the tex filter code I found the problem: for some reason the line that runs the command to convert the .ps file to a .png (in my case) had become wrapped - i.e. had a carriage return in the middle of it. We've no idea how that happened.

Thanks for all your help Mauno . Everything is now behaving as it should.

Cheers,

Ian.

Average of ratings: -
Re: cleaner latex rendering.

LOL, well I am glad you found it....

This happens way too frequently, more often than not through the use of windows based editors (tell me you weren't editing the linux server files with an MS Windows editor - LOL) and unfortunately it is usually a matter of self-abuse.... If it makes you feel any better I often use a text editor on a system which opens files in insert overwrite mode and as a result I was blowing a way the first few characters of a file when I opening it and tried to page down. Of course this is disastrous for files used with a scripting language that requires initial characters.... and since I had no reason to inspect the first few characters, this drove me nuts until I figured out what I was doing to myself......

Average of ratings: -
Re: cleaner latex rendering.
Thanks Marc. I'm glad it's not just me . Don't worry: I was using nano on an Ubuntu box ssh'd onto an Ubuntu server. All I can think is that I accidentally hit CR as I was cursoring through the file. Not sure how I managed that, though .

Obviously I'm glad that a problem that is likely due to my own incompetence hasn't been recorded in detail on a public, immensely popular, international forum...

Doh

Average of ratings: -
Re: cleaner latex rendering.

I attempted to install TexLive on my Linux Red Hat box, but it is not rendering the image onto the screen. When I go into the temp folder and view the .ps file, the image appears to be rendered correctly. Any ideas as to how I would correct this?

Just a note - I was able to configure Latex correctly on my Ubuntu server.

Average of ratings: -
Re: cleaner latex rendering.

Red Hat might have some security module (SeLinux?) on or you may need to change some permissions for executable binaries - my Debian Lenny had no problems with TeX Live but I have not been able to install it to Windows Vista so far - or basicly everything seems to be ok but "something" just does not work with Vista like in Debian.

Average of ratings: -
Re: cleaner latex rendering.

I have a feeling that the amsmath, amssymb, latexsym, amsmath, and amsfonts packages were not part of the TeX Live installation, as they were when I installed Tetex on my Ubuntu server. All of these packages are underlined in red in the Latex Preamble box. The only package not underlined is latin1. Any ideas as to where I would go to inorder to download these packages?

Average of ratings: -
Re: cleaner latex rendering.

I still do not understand how this works. I tried changing the various php files given on moodle.org and the latex/mimetext still renders poorly. How am I do chnage the tex notaion on my moodle site?

Average of ratings: -
Re: cleaner latex rendering.

Frank,

Can I take it that you have reviewed the docs regarding the tex filter, including this URL, http://docs.moodle.org/en/TeX_filter, and having done so you used the debugging feature found here: http://docs.moodle.org/en/TeX_filter#Debugging_TeX_filter? Because had you done so I would have expected you to have provided the results of those efforts so that we could have some idea of what you have done and what you have not done.

I really have no idea what, "I tried changing the various php files given on moodle.org and the latex/mimetext still renders poorly." means, and of course I haven't a clue as to what you read or did. Moreover, if you place x^2 between doubledollars and it does not render as $$x^2$$ then it is not a matter of your text expressions, but a matter of your Tex configuration, which can be addressed via the materials identified above.....

Average of ratings: -
Re: cleaner latex rendering.

Hey Marc, thank you for getting back to my post. I did a debug and this is what I got. This is from doing text 4. (Show a graphic image of the algebraic expression rendered with Tex/Ghostscript.)

Warning: is_file() [function.is-file]: open_basedir restriction in effect. File(/usr/bin/latex) is not within the allowed path(s): ('.:/proc/uptime:/tmp:/home:/usr/local/lib/php:/usr/home:/usr/local:/usr/local/bin') in /home/satma1/public_html/filter/tex/texdebug.php on line 189

Warning: is_file() [function.is-file]: open_basedir restriction in effect. File(/usr/bin/dvips) is not within the allowed path(s): ('.:/proc/uptime:/tmp:/home:/usr/local/lib/php:/usr/home:/usr/local:/usr/local/bin') in /home/satma1/public_html/filter/tex/texdebug.php on line 196

Warning: is_file() [function.is-file]: open_basedir restriction in effect. File(/usr/bin/convert) is not within the allowed path(s): ('.:/proc/uptime:/tmp:/home:/usr/local/lib/php:/usr/home:/usr/local:/usr/local/bin') in /home/satma1/public_html/filter/tex/texdebug.php on line 203

Fatal error: Call to undefined function tex_sanitize_formula() in /home/satma1/public_html/filter/tex/latex.php on line 49

Also, note that in my settings for tex notation, the paths all have red Xs, which the debug warning states.

Average of ratings: -
Re: cleaner latex rendering.

As I expected your problem is that your display is being handled by mimetex, not by tex,

open-basedir restrictions used to be much more common with some php apps in shared environments, but hopefully won't prevent you from resolving your problem. If you do a web search on "php.ini open_basedir" you will find lots of resources explaining how open_basedir can be turned off or adjusted via php.ini Check your php.ini and see if open_basedir is set. If it is then you can change it to add the full paths to your three binaries (and take the time to make sure that the binaries are in fact there!). If its not set and you are in a hosted situation then you may need to talk to your webhost about whether you can override it through a custom php.ini

You can also address the issue via apache. Here is a discussion that addresses changing open_basedir settings via your apache conf file:
http://www.mydigitallife.info/2007/03/15/php-scripts-open_basedir-restriction-in-effect-error/

Average of ratings: -
Re: cleaner latex rendering.

Oddly, I do not have a php.ini file in my moodle site.  But I do have it for our dummy site.  Both sites were set up the same way.  We never added a php.ini in our old (dummy) site, but our new one does not have this.  The php.ini file is the file inside the public_html folder correct?

I also noticed that inside the php.ini, there is no mention of a open_basedir or paths.  We tried talking to our webhost and they were of little help.

How can I override it through a custom php.ini?

In order to render latex not mimetex, do I need to download and install something onto my moodle or is it just a matter of changning the paths?  If so, why doesn't moodle just allow the paths to render latex out of the box?

If I wanted to use apache or something, can I just go into cPanel?  I saw something for apache in cPanel, but did not see anything about paths or open_basedir.

Sorry for my lack of knowledge.  I appreciate your help so much.

Average of ratings: -
Re: cleaner latex rendering.

alright, So I talked to my host service providers. They states that because we are on a shared server environment, and because LaTeX is not installed on the server, we cannot display latex. They told us that we should either get a VPS or dedicated server, and then install LaTeX onto it, and from there, have latex to show up. Is this true? I did not know that LaTeX was something that had to be installed onto the server. I assumed it was like mimetex, where it was already built in. At any rate, is LaTeX only able to be displayed on VPS or dedicated servers? or are they trying to sell me a VPS?

Average of ratings: -
Re: cleaner latex rendering.

1. If your webhost does not have latex installed and you can't install yourself, move to a different webhost.

2. In the interim, either install asciimathml or mathjax

3. If you install ascimathml, consider fallback to google chart API so as to avoid any other issues you may be having with mimetex

Average of ratings: -
Re: cleaner latex rendering.

You can as well go for example to http://www.codecogs.com/components/equationeditor/equationeditor.php

- write your TeX - and click the rendered image to save it and upload to your moodledata.

Quality is much better that with TeX filter... this image is saved as 300 dpi png

Average of ratings: Useful (1)
Re: cleaner latex rendering.

Is it possible to configure this so that the equation is centered rather than aligned with the bottom of a fraction? Right now an expression floats in the air when embedded in a line of text if there is a fraction or any symbol that is taller than a single line.

Also, there is a blue box around the expression -- how do I get rid of it?

Average of ratings: -
Re: cleaner latex rendering.

If you have some blue boxes around equations they are most likely image borders that might come from your editor or theme css - check if source come has some code like border: blue solid 1px near your equations.

Because those equation are normal images you can use for example vertical alignment in css (or latex itself) - but here in moodle.org the vertical-align style attribute is cut away...

Try Integral with style vertical-align:baseline(default) <img alt="test" height="46" src="http://latex.codecogs.com/png.latex?\120dpi f(x)=\displaystyle\int_{-\infty}^x e^{-t^2}dt" style="vertical-align: baseline;" width="153" /> and Integral with style vertical-align:middle <img alt="test" height="46" src="http://latex.codecogs.com/png.latex?\120dpi f(x)=\displaystyle\int_{-\infty}^x e^{-t^2}dt" style="vertical-align: middle;" width="153" />

Integral with tex filter in moodle.org is vertically aligned to middle: $$f(x)=\displaystyle\int_{-\infty}^x e^{-t^2}dt$$

Average of ratings: -
Re: cleaner latex rendering.

I don't see any code that would generate the boxes, so it must be a theme problem -- I am using a standard logo theme that was modified by the people here, so maybe they did something

Average of ratings: -
Re: cleaner latex rendering.

If all your images have blue box around them the problem might be in config.php (empty rows or white spaces after last ?> or some of the paths is not correct ) etc - some other reason why theme/css is not properly rendered and images have 1px solid blue border although they should have 0px border in moodle.

Try the normal standard theme - does it show blue boxes too?

Average of ratings: -
Re: cleaner latex rendering.

I have tried numerous themes and get the same result.  It must be somewhere in the configuration, but since I don't have administrator rights, I can't try to fix it.

Do you have any suggestions about where to look for a problem in the setting so I can pass it on to the moodle administrators?  I know they won't take the time to search, but maybe if I can point them in the right direction they would be willing to try.

Average of ratings: -
Re: cleaner latex rendering.

If you don't have administrator rights you can't do much for this. Most likely those blue borders around images are caused by broken css that can be caused for example by wrong dirroot or wwwroot in config.php, some misconfiguration of server, whitespaces in config.php, some custom code that breaks css (typical for hacked sites) or probably your standard theme is some modified version and not the original standard theme from the original package.

I should see your site to be able to say anything for sure.

Average of ratings: -