LaTeX images not showing - can't find latex.fmt

LaTeX images not showing - can't find latex.fmt

by Jeff P -
Number of replies: 16

I've been setting up my Moodle installation the past few days and have just one more hurdle until everything is working smoothly. My LaTeX files aren't displaying right. My server has latex, dvips and convert installed and on the configuration section, all appear with a check mark beside them. So, that doesn't seem to be the problem. I ran the debug mode and it told me:

Checking executables

latex executable (/usr/bin/latex) is readable
dvips executable (/usr/bin/dvips) is readable
convert executable (/usr/bin/convert) is readable

base filename for expression is '9608176195573c30c6beb3cf078fdf66'

Processing TeX expression:

f(x)=\int_{-\infty}^x~e^{-t^2}dt
$ /usr/bin/latex --interaction=nonstopmode /home/londonma/moodledata/temp/latex/9608176195573c30c6beb3cf078fdf66.tex
OUTPUT: This is pdfeTeX, Version 3.141592-1.21a-2.2 (Web2C 7.5.4)
I can't find the format file `latex.fmt'!
RETURN CODE: 1
$ /usr/bin/dvips -E /home/londonma/moodledata/temp/latex/9608176195573c30c6beb3cf078fdf66.dvi -o /home/londonma/moodledata/temp/latex/9608176195573c30c6beb3cf078fdf66.ps
OUTPUT: 
RETURN CODE: 1
$ /usr/bin/convert -density 240 -trim /home/londonma/moodledata/temp/latex/9608176195573c30c6beb3cf078fdf66.ps /home/londonma/moodledata/temp/latex/9608176195573c30c6beb3cf078fdf66.gif 
OUTPUT: 
RETURN CODE: 1

I'm guessing that the "I can't find the format file 'latex.fmt'" is the problem. But is there any way I can fix this? For what it's worth, I've been searching Google and the Moodle forums for a while. And I can only find two other posts on Moodle about latex.fmt and none seems relevant. And nothing helpful turned up in Google.

Average of ratings: -
In reply to Jeff P

Re: LaTeX images not showing - can't find latex.fmt

by Marc Grober -

This is a latex issue. See, e.g., http://www-mobile.ecs.soton.ac.uk/bjc97r/tips/latex-install.html

Is this your server or someone else's? If the latter, talk to our ISP.

In reply to Marc Grober

Re: LaTeX images not showing - can't find latex.fmt

by Jeff P -

Ok, thanks. I had a suspicion that was the case. It's not my own server - I've opened a support ticket with them. So, hopefully that will fix things. Thanks for answering my post so fast! smile

In reply to Jeff P

Re: LaTeX images not showing - can't find latex.fmt

by Jeff P -

For anyone else having this issue...my server was A2hosting and apparently others on the same server have encountered the issue, too. This post helped a lot: https://rniwa.com/2010-09-07/wordpressand-latex-on-a2-hosting/. Basically, I SSH'd into the server and ran latex. It created a latex.fmt file which I copied to the folder where I was trying to render the images and it seemed to work. The server wasn't able to "see" the latex.fmt file otherwise.

In reply to Jeff P

Re: LaTeX images not showing - can't find latex.fmt

by Jeff P -

I'm still having some problems with my latex installation after all. I'm using Moodle 2.0.2. In the latex settings, latex, dvips, convert all have checkmarks next to them and they have the correct paths. However, latex images only display on my main landing page. When I create a quiz, the images do not show up. I use a2hosting and it is a shared hosting service. I found this post about someone experiencing trouble using latex on a2:

https://rniwa.com/2010-09-07/wordpressand-latex-on-a2-hosting/

So, I tried accessing the server from a shell and ran latex. A file called latex.fmt was created and I uploaded it to the /moodledata/temp directory. And when I did that, the images started loading perfectly. However, it seems that this was just a shortterm solution because the temp directory is apparently purged every so often.

When I view texdebug.php, and try to choose option 4 (Show a graphic image of the algebraic expression rendered with Tex/Ghostscript), I get:


Warning: filemtime() [function.filemtime]: stat failed for /home/londonma/moodledata/temp/latex/9608176195573c30c6beb3cf078fdf66.png in /home/londonma/public_html/lib/filelib.php on line 1639

Warning: filesize() [function.filesize]: stat failed for /home/londonma/moodledata/temp/latex/9608176195573c30c6beb3cf078fdf66.png in /home/londonma/public_html/lib/filelib.php on line 1640

Warning: Cannot modify header information - headers already sent by (output started at /home/londonma/public_html/lib/filelib.php:1639) in /home/londonma/public_html/lib/filelib.php on line 1665

Warning: Cannot modify header information - headers already sent by (output started at /home/londonma/public_html/lib/filelib.php:1639) in /home/londonma/public_html/lib/filelib.php on line 1675

Warning: Cannot modify header information - headers already sent by (output started at /home/londonma/public_html/lib/filelib.php:1639) in /home/londonma/public_html/lib/filelib.php on line 1679

Warning: Cannot modify header information - headers already sent by (output started at /home/londonma/public_html/lib/filelib.php:1639) in /home/londonma/public_html/lib/filelib.php on line 1680

Warning: Cannot modify header information - headers already sent by (output started at /home/londonma/public_html/lib/filelib.php:1639) in /home/londonma/public_html/lib/filelib.php on line 1681

Warning: Cannot modify header information - headers already sent by (output started at /home/londonma/public_html/lib/filelib.php:1639) in /home/londonma/public_html/lib/filelib.php on line 1685

Warning: Cannot modify header information - headers already sent by (output started at /home/londonma/public_html/lib/filelib.php:1639) in /home/londonma/public_html/lib/filelib.php on line 1747

Warning: Cannot modify header information - headers already sent by (output started at /home/londonma/public_html/lib/filelib.php:1639) in /home/londonma/public_html/lib/filelib.php on line 1749

When I choose option 5 (Show command execution output from the algebraic expression rendered with Tex/Ghostscript), I get:

Checking executables
latex executable (/home/londonma/bin/latex) is readable
dvips executable (/home/londonma/bin/dvips) is readable
convert executable (/usr/bin/convert) is readable

base filename for expression is '9608176195573c30c6beb3cf078fdf66'

Processing TeX expression:

f(x)=\int_{-\infty}^x~e^{-t^2}dt

$ /home/londonma/bin/latex --interaction=nonstopmode /home/londonma/moodledata/temp/latex/9608176195573c30c6beb3cf078fdf66.tex
OUTPUT: This is pdfeTeX, Version 3.141592-1.21a-2.2 (Web2C 7.5.4)
I can't find the format file `latex.fmt'!
RETURN CODE: 1

$ /home/londonma/bin/dvips -E /home/londonma/moodledata/temp/latex/9608176195573c30c6beb3cf078fdf66.dvi -o /home/londonma/moodledata/temp/latex/9608176195573c30c6beb3cf078fdf66.ps
OUTPUT:
RETURN CODE: 1

$ /usr/bin/convert -density 240 -trim /home/londonma/moodledata/temp/latex/9608176195573c30c6beb3cf078fdf66.ps /home/londonma/moodledata/temp/latex/9608176195573c30c6beb3cf078fdf66.png
OUTPUT:
RETURN CODE: 1

When talking to support on a2hosting, they said:

Have you been checking the error logs in cPanel? I found some errors in the logs such as:

[Mon Mar 28 17:34:36 2011] [error] [client 216.240.14.115] sh: /home/londonma/public_html/filter/tex/mimetex.linux: Permission denied, referer: http://study.londonmathtutor.com/mod/quiz/attempt.php?attempt=13&page=4

I changed permission on these (and other files in the tex directory) to make them executable, and when I went back to your exam page on the site, this error no longer appears but I get a different one in the logs:

[Mon Mar 28 20:54:40 2011] [error] [client 64.112.207.184] fmtutil: format directory `/.texmf-var/web2c' does not exist., referer: http://study.londonmathtutor.com/mod/quiz/review.php?attempt=8
[Mon Mar 28 20:54:40 2011] [error] [client 64.112.207.184] fmtutil: format directory `/.texmf-var/web2c' does not exist., referer: http://study.londonmathtutor.com/mod/quiz/review.php?attempt=8

That directory path is located under /usr/share on the server, and LaTex is installed and appears to be working for at least a part of your site. You may want to check on the Moodle forums and see if anyone has run into similar problems when using LaTex with Moodle on a shared server.

So, I'm wondering...does anyone have any idea what I can do? Does the problem possibly stem from being on a shared host? Ideally I'd like to get the latex working and not have to use mimetex.

In reply to Jeff P

Re: LaTeX images not showing - can't find latex.fmt

by Marc Grober -

One thing you can do is simply install TexLive.  It is designed so that it can be run on a shared host and then you have total control over your own Latex distribution.  You can then also hack Moodle to bypass using convert.

You coold also use MathJax, though it is not as comprehensive as TexLive

In reply to Jeff P

Re: LaTeX images not showing - can't find latex.fmt

by khaled baloul -

Hello Jeff, hello everyone,

I am having exactly the sames problems as yours.

Did u found the clue? 

Please let me know if the problem stems from the shared hosting or from the latex binaries installed by the hosting provider?

As i am waiting for an SSH access to my account to run latex and get the latex.fmt files, does it help to just pick one around in the internet and put it in the /moodledata/temp directory.

Thanks for the help.

Regards.

 

Kal

In reply to khaled baloul

Re: LaTeX images not showing - can't find latex.fmt

by Colin Fraser -
Picture of Documentation writers Picture of Testers

AFAIK, there may be an issue with the "shared hosting" that will cause some difficulties with rendering images. I am pretty certain that I have run into this before, but not 100% positive. If I recall the creation of the gif over ran the space restrictions on the shared server. It can't create the format file so cannot create the image. I could very well be wrong, but that may be a place to start...

In reply to Colin Fraser

Re: LaTeX images not showing - can't find latex.fmt

by Marc Grober -
Tex issue, Colin. The OP can spend some moments searching on this and a number of solutions will present themselves assuming he has adequate access to server.....
In reply to Marc Grober

Re: LaTeX images not showing - can't find latex.fmt

by Colin Fraser -
Picture of Documentation writers Picture of Testers

Hi Marc, but I am sure we had a similar discussion ages ago on this and that was the cause.. but as I said, I am not 100% certain may have been in relation to something else. But I would certainly bow to your experience here..smile

In reply to Colin Fraser

Re: LaTeX images not showing - can't find latex.fmt

by khaled baloul -
Thanks Collin Thanks Marc for your advices. finally the clue seems to reside in the latex.fmt file. just copied it in moodledata/temp/latex directory and it work now. Regards
In reply to Jeff P

This forum post has been removed

The content of this forum post has been removed and can no longer be accessed.
In reply to Deleted user

Re: LaTeX images not showing

by Colin Fraser -
Picture of Documentation writers Picture of Testers

Those error messages appear to me to be a little generic. I don't see where shell_exec() would need to be disabled, but then I am no developer. 

Start with the basics, is the rendering program set up, or are you relying on mimetex's fallback to render the image? If so, then you might want to install Ghostscript and you should have a TeX program available, something like LiveTeX. If you already have these thing in place, then you might want to ensure the paths are there. I would also recommend that you actually go to this page and have a read. To follow that up, forther discussion can be found here.  That might help you reformulate your site's policies with regard to TeX and what you want to do with it... 

In reply to Colin Fraser

Re: LaTeX images not showing

by Andreas Gounaris -

Hi ,

a more generic question: what if we can't change site policies? Moodle is installed in a shared hosting environment, thus the provider mey deny the use of functions like shell_exec().

Is therer anything we can tell him so that he can be sure server's security won't be compromised by enabling shell_exec() function and related executables on the file system?

Ideally, I'd like to have a list of things required for a Plesk shared hosting environment so that TeX will be enabled in moodle.

Thanks

In reply to Andreas Gounaris

Re: LaTeX images not showing

by Mauno Korpelainen -

They are simply afraid that you might be able to compromise the security of all free hosting accounts on your server. Php settings like disable_functions are server wide, not on an individual account basis.

But you can change the account/server type (may not be free anymore) to be able to configure your server as you like - mimetex inside folder filter/tex can render basic notations and if you need a heavy tool (full latex distribution) you can for example install texlive together with imagemagick or ghostscript (explained in moodle docs). Note that executable files (mimetex and binaries of latex distribution and convert library) need a permission to execute commands and paths for local binaries need to be set in settings of tex filter. If local latex/tex is impossible to use you can for example add mathjax script tags to themes (the method depends on your version of moodle) or for example in moodle 2 try adding the attached script tags (examples.txt) to additional HTML to header (from administration menu...in that case scripts are loaded on every page of moodle)

See more details from http://www.mathjax.org/docs/1.1/tex.html

In reply to Deleted user

Re: LaTeX images not showing

by Mauno Korpelainen -

Those warnings are caused by disabled functions of php. Most likely your site php.ini has a line with

disable_functions = ...

If you can't remove shell_exec and system from that list in php.ini there are not many workarounds available to use local mimetex or latex with Tex filter. Still like Colin suggests you can use other math renderers like MathJax, asciimathml, mathtran etc.

In reply to Mauno Korpelainen

Re: LaTeX images not showing

by Johnson Pau -

After hours of reading the code, I found that Tex are using system() to call run the shell command. 

After remove "system" from the disable_functions= from php.ini, my lex notation now working.

FYI:

I am using Debian 6.0

These are extra packages that I have installed and steps to make tex filter worked.

apt-get install texlive-full

apt-get install imagemagick

vi /etc/php5/fpm/php.ini

Change this 

#disable_functions = exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show_source

disable_functions = exec,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show_source

Hope this help.