problem with paths of TeX binaries

problem with paths of TeX binaries

by Jean-Michel Védrine -
Number of replies: 8

Hello,

On a new system (windows 8.1 Apache , PHP 5.4.12, latest Moodle 2.6.2+ weekly release) I am trying to setup the Vienna University Offlinequiz activity module (see http://www.academic-moodle-cooperation.org/en/modules/offline-quiz/) because that would allow me to switch from the University proprietary OCR system to a free and open alternative for paper and pencil tests (yes we still do a lot of these !) and also (even more important) that would allow my student to review their answers and questions feedback after the test.

But obviously as this module is creating pdf documents with multichoice questions included in the offline test, I can't use MathJax. Fortunately the offlinequiz code allow the use of the TeX filter and in that case math formulas are included in pdf documents.

I discovered I have a problem I never encountered before with paths to dvips, latex and convert binaries:

  • If I put them inside double quotes, creation of tex, dvi and png files works fine (easy to verify), but as is_file and is_executable PHP functions return false for paths included in double quotes I must comment the line
    set_config('filter_tex_convertformat', 'gif');
    in the filter_tex_updatedcallback function in filter/tex/lib.php because if I don't do it GIF images will be created instead of PNG ones
  • If I remove the double quotes I get all the green checks in the filter settings page and filter_tex_convertformat is not turned to GIF, but obviously nothing is working as my paths include spaces so in filterdebug I can see that as expected all return codes are now equal to 1.

With the number of people using the teX filter this problem is surely well known but I never read about it.

Of course this is not a big problem for me as I can get the system to work.

Average of ratings: -
In reply to Jean-Michel Védrine

Re: problem with paths of TeX binaries

by Daniel Thies -
Picture of Core developers Picture of Plugin developers Picture of Testers

Jean-Michel,I think this has probably not come up because it is a windows specific problem. Unix systems by convention normally do not have spaces in paths for system commands, and it might  be able escape them with backslashes if they did.  I did find some comments on this in the PHP manual.  I believe it is a  legitimate bug.  It could be partially fixed by striping the quotes in lib.php (with str_replace or other method), but that does not fix the problem of the little x's on the admin page.  This uses a core function admin_settings_configexecutable. It may affect some other components although not many use executables in the core.

Incidently, I think Mauno mentioned he has a method for printing with MathJax in book module. 

In reply to Daniel Thies

Re: problem with paths of TeX binaries

by Jean-Michel Védrine -

Yes I think it's a bug and the fact it didn't come up before is a sure proof that not so many people have full TeX install under recent Windows versions (in older versions MiKTeX installed itself under c:\texmf so you could in theory avoid spaces but the default location is now c:\program files (x86)\miktex 2.9)

Also it's rather comical that the default paths written in Moodle code have double quotes even if they contain no spaces so they will not work smile

I think the good solution would be to say that these paths shouldn't have quotes (so no change to admin_settings_configexecutable, and quotes are added later in commands if OS is Windows but of course that would complicate upgrade (need to remote the quotes if they exist).

Unfortunately due to the way conversion to pdf is done in offlinequiz, I don't think MathJax is an option, I need local images (so Mathtran isn't an option either !)

In reply to Jean-Michel Védrine

Re: problem with paths of TeX binaries

by Colin Fraser -
Picture of Documentation writers Picture of Testers

I use TeXLive for my binary on my private Moodle, with Windows7 at home.  That sets up the \texlive\2013 folder, while Image Magik runs in the ImageMagik folder, so no spaces there either I am afraid. (My volunteer site is hosted but they do not use TeX, no need. My work Moodle is hosted by NetSpot, so I don't know what they are using.)

One thing, I was using TeXLive to create a number of PDF worksheets for an Algebra class then thought about it after they were done, then decided to rewrite them and put them into my work Moodle. To test them I was going to write them into my new installation after a rebuild of my PC. The first time I went to use TeX Notation I went and checked the paths and found I had not actually re-installed ImageMagic, yet the TexLive install produced PDFs. So, does TeXLive use a converter to create its coding as images? does the TeXLive not need an external converter? and if so, Does a TeXLive binary require an external converter in Moodle? I never thought to test this, or to find the converter in the TeXLive installation until now and aim Moodle at that. (I have no time to check this out, but someone more knowledgable than I might be able to figure it out.) Is it possible then that using TeXLive might avoid the added complication of using a converter? 

In reply to Colin Fraser

Re: problem with paths of TeX binaries

by Marc Grober -

Convert is not necessary with current versions of TexLive - tweaking the tex filter to bypass convert was the mdl I was working on when I gave up on Moodle 

In reply to Daniel Thies

Re: problem with paths of TeX binaries

by Jean-Michel Védrine -

Daniel, for me the problems are exactly the same with Moodle 2.6.2+ and 2.7dev despite the differences in code :

  • If I put the double quotes around paths they are reported wrong on the settings page but commands are working in texdebug and the filter create image using TeX . Apart from the crosses on the settings page the main problem is I can't switch to PNG because as paths are considered wrong filter_tex_updatedcallback function revert back to GIF. I can correct the problem by commenting a line in that function.
  • If I don't put double quotes around paths They are reported correct on the settings page but commands are failing in texdebug and the filter is broken. I can correct the problem by patching the code adding double quotes around paths before they are used in commands.

So for windows there is no way to get it working without patching core code.

In reply to Jean-Michel Védrine

Re: problem with paths of TeX binaries

by Colin Fraser -
Picture of Documentation writers Picture of Testers

Well... no, the reason why it has never been mentioned is that it has never come up before, to my knowledge anyway. Is it possible that the converter is returning blank images, that is the image canvas and frame but no image? Not converting to png properly? You will get a positive return code, 1, but no image... 

In reply to Colin Fraser

Re: problem with paths of TeX binaries

by Daniel Thies -
Picture of Core developers Picture of Plugin developers Picture of Testers

Yes, Colin, ignorance of and prejudice against Windows got the better of me. I should probably have assumed that the TeX distribution is the same as has been used before. If spaces have worked in the past in paths, something else must have changed.  You and Jean-Michel are right, this is a new problem.  I found that I have this problem also in 2.6.2+ if I rename the binary to include a space, but not in the dev master for 2.7.  In the TeX filter, they have changed path reference for $CFG->filter_tex_dvips in 2.6 to get_config('dvips','filter_tex') in 2.7.  Apparently the old method utilized magic quotes in PHP to escape the space in the admin settings code, and get_config does not.  Magic quotes were deprecated in PHP 5.3 and removed from PHP 5.4. Upgrading to 2.7 should fix the problem, but 2.6 should also have a bug fix.