Moodle
  1. Moodle
  2. MDL-10197

Quality improvement of Tex-images

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.7.1, 1.8.12, 1.9.8, 2.0
    • Fix Version/s: 1.9.9, 2.0
    • Component/s: Maths filters
    • Labels:
      None
    • Database:
      Any
    • Affected Branches:
      MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE, MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE, MOODLE_20_STABLE
    • Rank:
      34477

      Description

      Moodle renders Tex-images as GIF-files of rather low quality. Images of higher quality, like the png-version of wikipedia.org, would be nice.

      1. mdl-10197-19.diff
        12 kB
        Iñaki Arenaza
      2. mdl-10197-20.diff
        12 kB
        Iñaki Arenaza
      3. TEX.tar
        29 kB
        Vadim Dvorovenko
      4. TexFilter.zip
        8 kB
        Vadim Dvorovenko
      5. texpng.patch
        5 kB
        Vadim Dvorovenko
      1. Png example.jpg
        33 kB

        Issue Links

          Activity

          Hide
          Helen Foster added a comment -

          component change

          Show
          Helen Foster added a comment - component change
          Hide
          Vadim Dvorovenko added a comment -

          So i have updaterd plugin source, so that output extention (gif or png) is selected on filtersettings page.
          I don't know yet how to use CVS and create patches, so i'm posted updated sourses.
          Can you update cvs with this files?

          Show
          Vadim Dvorovenko added a comment - So i have updaterd plugin source, so that output extention (gif or png) is selected on filtersettings page. I don't know yet how to use CVS and create patches, so i'm posted updated sourses. Can you update cvs with this files?
          Hide
          Vadim Dvorovenko added a comment -

          Newer version of TeXfilter with ability to select use png or gif images

          Show
          Vadim Dvorovenko added a comment - Newer version of TeXfilter with ability to select use png or gif images
          Hide
          Tim Hunt added a comment -

          My computer will not unzip that latest zip file So you have any idea what is wrong.

          And, if you could submit it as a patch, that would be a bonus. Have you seen http://docs.moodle.org/en/Development:How_to_create_a_patch?

          Show
          Tim Hunt added a comment - My computer will not unzip that latest zip file So you have any idea what is wrong. And, if you could submit it as a patch, that would be a bonus. Have you seen http://docs.moodle.org/en/Development:How_to_create_a_patch?
          Hide
          James Heather added a comment -

          On my system (Fedora 11, Moodle 1.9.5, texlive), the GIF tex output is pretty much unreadable. I'm not sure this should be classed as minor.

          Is there any reason to keep support for generating GIFs? Wouldn't it be rather easier to switch to creating PNGs and have done with it?

          Show
          James Heather added a comment - On my system (Fedora 11, Moodle 1.9.5, texlive), the GIF tex output is pretty much unreadable. I'm not sure this should be classed as minor. Is there any reason to keep support for generating GIFs? Wouldn't it be rather easier to switch to creating PNGs and have done with it?
          Hide
          Mauno Korpelainen added a comment -

          The idea of changing the default CFG setting from administration menu (see the first package Vadim sent) is good and the only reason I can find to defend gif is that Mimetex in filter/tex/ can't create png files - you need to have other distribution of Latex like Tex Live installed with some png converter (Ghostscript or ImageMagick) and correct paths in administration of tex filter + gif-tags mentioned in http://moodle.org/mod/forum/discuss.php?d=120418#p532389 changed to png or changed with Vadim's patch to get high quality png files.

          In addition to selecting file type you can get better quality TeX also by changing settings of density (dpi), gammacorrection, fonts, packages (usepackage) etc

          There have been some changes lately in files of TeX filter but it should not cause any trouble even if gifs are by default permanently changed to png like James suggests. Mimetex will show the files with wrong extension (png) but saves the files in gif format - so if no png conversion is made you just keep getting gif files with image type gif but extension is named png. Most moodle sites don't probably use tex filter at all and those sites that really need Maths most likely want to use png if possible...

          Show
          Mauno Korpelainen added a comment - The idea of changing the default CFG setting from administration menu (see the first package Vadim sent) is good and the only reason I can find to defend gif is that Mimetex in filter/tex/ can't create png files - you need to have other distribution of Latex like Tex Live installed with some png converter (Ghostscript or ImageMagick) and correct paths in administration of tex filter + gif-tags mentioned in http://moodle.org/mod/forum/discuss.php?d=120418#p532389 changed to png or changed with Vadim's patch to get high quality png files. In addition to selecting file type you can get better quality TeX also by changing settings of density (dpi), gammacorrection, fonts, packages (usepackage) etc There have been some changes lately in files of TeX filter but it should not cause any trouble even if gifs are by default permanently changed to png like James suggests. Mimetex will show the files with wrong extension (png) but saves the files in gif format - so if no png conversion is made you just keep getting gif files with image type gif but extension is named png. Most moodle sites don't probably use tex filter at all and those sites that really need Maths most likely want to use png if possible...
          Hide
          Mauno Korpelainen added a comment -

          Attached an example rendered as png with Mathtex / Tex Live 2007 , dpi 600, gammacorrection 0.4 and displaystyle with normal AMS fonts

          Show
          Mauno Korpelainen added a comment - Attached an example rendered as png with Mathtex / Tex Live 2007 , dpi 600, gammacorrection 0.4 and displaystyle with normal AMS fonts
          Hide
          Mauno Korpelainen added a comment -

          The background of that example is gray in screenshot but click the image to see it larger - I was just demonstrating the other possible settings...

          Show
          Mauno Korpelainen added a comment - The background of that example is gray in screenshot but click the image to see it larger - I was just demonstrating the other possible settings...
          Hide
          Tim Hunt added a comment -

          So, can we come up with a patch that automatically generates .gif if you are stuck using MimeTeX, and otherwise generates PNGs, without bothering the admin about it?

          If anyone can come up with a patch for that, it would be great. Thanks.

          Show
          Tim Hunt added a comment - So, can we come up with a patch that automatically generates .gif if you are stuck using MimeTeX, and otherwise generates PNGs, without bothering the admin about it? If anyone can come up with a patch for that, it would be great. Thanks.
          Hide
          James Heather added a comment -

          I don't have time to turn this into a patch-if anyone wants to do that with this idea, feel free-but my local fix here is only 4 chars long, and involves getting the TeX filter to generate PNGs, but still with the .gif extension. Seems to work fine on Firefox and IE.

          In web/filter/tex/latex.php, change line

          $command = "{$CFG->filter_tex_pathconvert} -density $density -trim $bg_opt $ps $gif";

          to

          $command = "{$CFG->filter_tex_pathconvert} -density $density -trim $bg_opt $ps png:$gif";

          The 'png:' in front of the output filename tells ImageMagick to create a PNG file (even though the filename is still as for the GIF file).

          This won't affect MimeTeX. If it still wants to produce GIFs, it can.

          Show
          James Heather added a comment - I don't have time to turn this into a patch- if anyone wants to do that with this idea, feel free -but my local fix here is only 4 chars long, and involves getting the TeX filter to generate PNGs, but still with the .gif extension. Seems to work fine on Firefox and IE. In web/filter/tex/latex.php, change line $command = "{$CFG->filter_tex_pathconvert} -density $density -trim $bg_opt $ps $gif"; to $command = "{$CFG->filter_tex_pathconvert} -density $density -trim $bg_opt $ps png:$gif"; The 'png:' in front of the output filename tells ImageMagick to create a PNG file (even though the filename is still as for the GIF file). This won't affect MimeTeX. If it still wants to produce GIFs, it can.
          Hide
          Tim Hunt added a comment -

          Howard, I just thought you might have an opinion on this.

          I don think that using the wrong extension is horrible, can anyone come up with a less evil solution?

          Show
          Tim Hunt added a comment - Howard, I just thought you might have an opinion on this. I don think that using the wrong extension is horrible, can anyone come up with a less evil solution?
          Hide
          Vadim Dvorovenko added a comment -

          Repacked archive with tar. I tried to create patch using netbeans, but it put's absolute filenames instead of relative and creates separate file for each patched file. I can't find how to create patch relative to cvs, so instructions for creation patchers in neatbeans are welcome.

          Show
          Vadim Dvorovenko added a comment - Repacked archive with tar. I tried to create patch using netbeans, but it put's absolute filenames instead of relative and creates separate file for each patched file. I can't find how to create patch relative to cvs, so instructions for creation patchers in neatbeans are welcome.
          Hide
          Tim Hunt added a comment -

          The code here is not based on the latest version of the Tex filter code from 1.9.4+ or 2.0 dev (and recent changes there have been to fix security problems, and so are important). Also, the changes do not make any sense to me. Please can someone make a patch - it is not rocket science - and explain why the changes in the patch make things better.

          Show
          Tim Hunt added a comment - The code here is not based on the latest version of the Tex filter code from 1.9.4+ or 2.0 dev (and recent changes there have been to fix security problems, and so are important). Also, the changes do not make any sense to me. Please can someone make a patch - it is not rocket science - and explain why the changes in the patch make things better.
          Hide
          Vadim Dvorovenko added a comment -

          Finally I did it! This patch allows you to select gif or png extention. Please add to cvs

          Show
          Vadim Dvorovenko added a comment - Finally I did it! This patch allows you to select gif or png extention. Please add to cvs
          Hide
          Dan Poltawski added a comment -

          I reported a bug in debian about the quality issue:
          http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=536892

          Who discussed it with imagemagick upstream:
          http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=14368

          And suggestion the solution of adding -flatten to the command.

          Show
          Dan Poltawski added a comment - I reported a bug in debian about the quality issue: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=536892 Who discussed it with imagemagick upstream: http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=14368 And suggestion the solution of adding -flatten to the command.
          Hide
          Vlas Voloshin added a comment -

          Please consider that using -flatten parameter is not a universal solution - we also encountered the same problem with gif images and tried -flatten, but we need transparent background, so this was not an option. Using png should prove better solution, I think.

          Show
          Vlas Voloshin added a comment - Please consider that using -flatten parameter is not a universal solution - we also encountered the same problem with gif images and tried -flatten, but we need transparent background, so this was not an option. Using png should prove better solution, I think.
          Hide
          Vlas Voloshin added a comment -

          We also applied the patch that Vadim submitted here - it works ok.

          Show
          Vlas Voloshin added a comment - We also applied the patch that Vadim submitted here - it works ok.
          Hide
          Iñaki Arenaza added a comment -

          Ok, here's a patch I have created before I've seen there's already a bug open for it, and code that I could have used to do it in 30' instead of nearly 2 hours of coding and testing

          The patch offers the admin the ability to choose the format (GIF and PNG) in case the user base is stuck using browsers that have still problems with certain PNG images (like first versions of IE 6.0 that had a lot of trouble with transparent PNGs). It also automatically 'downgrades' the output format to GIF if convert is not available but the admin selected PNG as the output format.

          The patch is for 1.9.7+ (current as of today) and should be easy to forward port it to 2.0 if accepted (I'd do it).

          Saludos,
          Iñaki

          Show
          Iñaki Arenaza added a comment - Ok, here's a patch I have created before I've seen there's already a bug open for it, and code that I could have used to do it in 30' instead of nearly 2 hours of coding and testing The patch offers the admin the ability to choose the format (GIF and PNG) in case the user base is stuck using browsers that have still problems with certain PNG images (like first versions of IE 6.0 that had a lot of trouble with transparent PNGs). It also automatically 'downgrades' the output format to GIF if convert is not available but the admin selected PNG as the output format. The patch is for 1.9.7+ (current as of today) and should be easy to forward port it to 2.0 if accepted (I'd do it). Saludos, Iñaki
          Hide
          Mauno Korpelainen added a comment -

          Iñaki,

          the patch looks otherwise good but remember that 4th file - filter/tex/texed.php and lines 25 & 26

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

          should also use $CFG->filter_tex_convertformat

          ( http://moodle.org/mod/forum/discuss.php?d=120418#p532389 )

          Show
          Mauno Korpelainen added a comment - Iñaki, the patch looks otherwise good but remember that 4th file - filter/tex/texed.php and lines 25 & 26 $image = md5($texexp) . ". gif "; $filetype = 'image/ gif '; should also use $CFG->filter_tex_convertformat ( http://moodle.org/mod/forum/discuss.php?d=120418#p532389 )
          Hide
          Iñaki Arenaza added a comment -

          Hi Mauno,

          if fact they shouldn't , as that file always uses mimeTeX to render the images, so only GIFs will be created.

          Saludos,
          Iñaki.

          Show
          Iñaki Arenaza added a comment - Hi Mauno, if fact they shouldn't , as that file always uses mimeTeX to render the images, so only GIFs will be created. Saludos, Iñaki.
          Hide
          Mauno Korpelainen added a comment -

          Ah - you are right!!!

          I never checked my comments for Ian and now after your comment I noticed that this file filter/tex/texed.php could be deleted - or at least the code should be changed.

          It seems to be a standalone file that is not used by any other file of moodle (if it ever has been), not by tex filter or by algebra filter but it makes all moodle sites open for external (miss)use of tex filter...if they use mimetex with tex filter.

          I will open a new bug for that issue for Petr or Eloy to check.

          Thanks, Iñaki!

          Show
          Mauno Korpelainen added a comment - Ah - you are right!!! I never checked my comments for Ian and now after your comment I noticed that this file filter/tex/texed.php could be deleted - or at least the code should be changed. It seems to be a standalone file that is not used by any other file of moodle (if it ever has been), not by tex filter or by algebra filter but it makes all moodle sites open for external (miss)use of tex filter...if they use mimetex with tex filter. I will open a new bug for that issue for Petr or Eloy to check. Thanks, Iñaki!
          Hide
          Vadim Dvorovenko added a comment -

          Is there anyone with commit rights? I think nothing would be bad in adding such a simple feature and delete unused files.
          If nobody has such rights please vote for this issue.
          If someone will commit, please chex texdebug file. The default expression never renders normally - replace Bigint with int, and slashes incorrectly escapes, when renedering with mimetex

          Show
          Vadim Dvorovenko added a comment - Is there anyone with commit rights? I think nothing would be bad in adding such a simple feature and delete unused files. If nobody has such rights please vote for this issue. If someone will commit, please chex texdebug file. The default expression never renders normally - replace Bigint with int, and slashes incorrectly escapes, when renedering with mimetex
          Hide
          Iñaki Arenaza added a comment -

          Hi,

          here are updated patches for both 1.9.7+ and HEAD (current as of today). The patch does add a configurable filter setting that defaults to GIF. There are a couple of reasons for this:

          • It's the safe default value for every single graphical browser going back to Mosaic (not that Mosaic supported transparent GIFs, but you get the idea ), and has been the default format in Moodle so far (so you get no surprises by default).
          • On my test machine, 'convert' consistently creates smaller files for the same LaTeX expression when creating GIF files (sometimes noticeably smaller, even less than half the size of th PNG file). This is a real gain when you don't actually need PNG because your GIFs are the same quality of your PNGs (the ones I get on my test machine are identical quality wise).

          To summarize, if you need PNGs, you can get them (provided you have LaTeX, dvips and convert installed and you configure the filter settings acdordingly), but if you don't need them or want to play on the safe side, you can still get your gool ole trusted GIFs

          Saludos,
          Iñaki.

          Show
          Iñaki Arenaza added a comment - Hi, here are updated patches for both 1.9.7+ and HEAD (current as of today). The patch does add a configurable filter setting that defaults to GIF. There are a couple of reasons for this: It's the safe default value for every single graphical browser going back to Mosaic (not that Mosaic supported transparent GIFs, but you get the idea ), and has been the default format in Moodle so far (so you get no surprises by default). On my test machine, 'convert' consistently creates smaller files for the same LaTeX expression when creating GIF files (sometimes noticeably smaller, even less than half the size of th PNG file). This is a real gain when you don't actually need PNG because your GIFs are the same quality of your PNGs (the ones I get on my test machine are identical quality wise). To summarize, if you need PNGs, you can get them (provided you have LaTeX, dvips and convert installed and you configure the filter settings acdordingly), but if you don't need them or want to play on the safe side, you can still get your gool ole trusted GIFs Saludos, Iñaki.
          Hide
          James Heather added a comment -

          Nice!

          So how do we get this into the official code? It is pretty obviously worth including.

          James

          Show
          James Heather added a comment - Nice! So how do we get this into the official code? It is pretty obviously worth including. James
          Hide
          Dan Poltawski added a comment -

          Thanks Iñaki, just briefly looking at it - does filter_tex_convertformat need some cleaning to ensure users can't put && rm *?

          Show
          Dan Poltawski added a comment - Thanks Iñaki, just briefly looking at it - does filter_tex_convertformat need some cleaning to ensure users can't put && rm *?
          Hide
          Iñaki Arenaza added a comment -

          Hi Dan,

          filter_tex_convertformat can only be set by users with moodle/site:config permission in the system context (just like the rest of the TeX filter settings in the same page, which as far as I know are not cleaned either).

          I'd say that anyone that gives that permission to non-trusted users has a big problem already . And I'd expect users with that permission to know what they'll get if they put '&& rm *' as part of the setting value

          Saludos,
          Iñaki.

          Show
          Iñaki Arenaza added a comment - Hi Dan, filter_tex_convertformat can only be set by users with moodle/site:config permission in the system context (just like the rest of the TeX filter settings in the same page, which as far as I know are not cleaned either). I'd say that anyone that gives that permission to non-trusted users has a big problem already . And I'd expect users with that permission to know what they'll get if they put '&& rm *' as part of the setting value Saludos, Iñaki.
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Looks perfect (while keeping current behavior for "mimetex" sites), isn't it?

          +1 Great work Iñaki (and the rest!)

          Ciao

          Show
          Eloy Lafuente (stronk7) added a comment - Looks perfect (while keeping current behavior for "mimetex" sites), isn't it? +1 Great work Iñaki (and the rest!) Ciao
          Hide
          Iñaki Arenaza added a comment -

          Dan,

          would you mind if I commit the fixes from my patches?

          Saludos,
          Iñaki.

          Show
          Iñaki Arenaza added a comment - Dan, would you mind if I commit the fixes from my patches? Saludos, Iñaki.
          Hide
          Dan Poltawski added a comment -

          Hi Iñaki,

          No, not at all - very sorry to have not commited them already

          cheers
          Dan

          Show
          Dan Poltawski added a comment - Hi Iñaki, No, not at all - very sorry to have not commited them already cheers Dan
          Hide
          Iñaki Arenaza added a comment -

          Fixed in CVS for both 1.9.x and HEAD.

          Thanks a lot to Miro Goepel for the bug report and all the people that contributed suggestions and feedback

          Saludos,
          Iñaki.

          Show
          Iñaki Arenaza added a comment - Fixed in CVS for both 1.9.x and HEAD. Thanks a lot to Miro Goepel for the bug report and all the people that contributed suggestions and feedback Saludos, Iñaki.

            People

            • Votes:
              4 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: