Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-34171

GIFT export does not escape \ in the question text.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.2.3, 2.3
    • Fix Version/s: 2.2.5, 2.3.2
    • Component/s: Quiz
    • Labels:
    • Testing Instructions:
      Hide

      1. Create a question with \ and \ \ (but without the space. Stupid tracker) in the question text.
      2. Export this question in GIFT format.
      3. Import to another course.
      4. Verify that the question text has come through unmodified.

      Show
      1. Create a question with \ and \ \ (but without the space. Stupid tracker) in the question text. 2. Export this question in GIFT format. 3. Import to another course. 4. Verify that the question text has come through unmodified.
    • Affected Branches:
      MOODLE_22_STABLE, MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_22_STABLE, MOODLE_23_STABLE
    • Pull from Repository:
    • Pull Master Branch:

      Description

      I have several hundreds of quiz questions that use TeX to render mathematical equations in Moodle 1.9.

      I've just installed the new version of Moodle 2.2. I exported my question categories from Moodle 1.9 in GIF format and imported them to Moodle 2.3. During this process, Moodle 2.2 deletes one of the double backslashes that TeX uses to build mathematical Matrices.

      Since I can't upload example files here, I'll leave you with an example of what happened to one of the questions:

      -> Question exported from Moodle 1.9

      // question: 743  name: InversaCalculo_01 
      ::InversaCalculo_01::[html]<p><span>A inversa da matriz $$A \= \left[ \{\begin\{array\}1 &amp; 0 &amp; 0\\0 &amp; 1&amp; 0\\1 &amp; 0 &amp; 1\\ \end\{array\}\} \right]$$ é </span></p>\n<p></p>\n<p></p>\n<p></p>{
      	=$$\left[ \{\begin\{array\}1 & 0 & 0\\0 & 1& 0\\-1 & 0 & 1\\ \end\{array\}\} \right]$$
      	~%-33.333%$$\left[ \{\begin\{array\}1 & 0 & 0\\0 & -1& 0\\1 & 0 & -1\\ \end\{array\}\} \right]$$
      	~%-33.333%$$\left[ \{\begin\{array\}1 & 1 & 0\\0 & 1& 0\\1 & 0 & 1\\ \end\{array\}\} \right]$$
      	~%-33.333%$$\left[ \{\begin\{array\}-1 & 0 & 0\\0 & 1& 0\\1 & 0 & -1\\ \end\{array\}\} \right]$$
      }

      -> Same question after importing to Moodle 2.2 (the same thing happens in Moodle 2.3)

      // question: 4  name: InversaCalculo_01
      ::InversaCalculo_01::[html]<p><span>A inversa da matriz $$A \= \left[ \{\begin\{array\}1 &amp; 0 &amp; 0\0 &amp; 1&amp; 0\1 &amp; 0 &amp; 1\ \end\{array\}\} \right]$$ é </span></p>\n<p> </p>\n<p> </p>{
      	=<p>$$\left[ \{\begin\{array\}1 &amp; 0 &amp; 0\0 &amp; 1&amp; 0\-1 &amp; 0 &amp; 1\ \end\{array\}\} \right]$$</p>
      	~<p>$$\left[ \{\begin\{array\}1 &amp; 0 &amp; 0\0 &amp; -1&amp; 0\1 &amp; 0 &amp; -1\ \end\{array\}\} \right]$$</p>
      	~<p>$$\left[ \{\begin\{array\}1 &amp; 1 &amp; 0\0 &amp; 1&amp; 0\1 &amp; 0 &amp; 1\ \end\{array\}\} \right]$$</p>
      	~<p>$$\left[ \{\begin\{array\}-1 &amp; 0 &amp; 0\0 &amp; 1&amp; 0\1 &amp; 0 &amp; -1\ \end\{array\}\} \right]$$</p>
      }

      Thank you!

        Gliffy Diagrams

        1. newtex.gift.txt.txt
          0.9 kB
          Jean-Michel Vedrine
        2. tex.gift.txt
          0.6 kB
          Tim Hunt
        1. math_choices.png
          75 kB
        2. math_questiontext.png
          35 kB
        3. matrix_question.png
          173 kB

          Activity

          Hide
          timhunt Tim Hunt added a comment -

          Here is the test question as a file. The problem definitely happens on import.

          Show
          timhunt Tim Hunt added a comment - Here is the test question as a file. The problem definitely happens on import.
          Hide
          timhunt Tim Hunt added a comment -

          Actually, this is a known issue: MDL-28540

          The problem is that a lot of the characters used by TeX are also special characters used by GIFT. Therefore you need to escape them. That includes \.

          I suppose the problem is that Moodle 1.9 is not correctly doing the export It should be exporting \ as
          , and
          as \\\\.

          However, we are not fixing bugs in 1.9 any more.

          If you want to transfer questions from 1.9 to 2.x I recommend Moodle XML format.

          Show
          timhunt Tim Hunt added a comment - Actually, this is a known issue: MDL-28540 The problem is that a lot of the characters used by TeX are also special characters used by GIFT. Therefore you need to escape them. That includes \. I suppose the problem is that Moodle 1.9 is not correctly doing the export It should be exporting \ as , and as \\\\. However, we are not fixing bugs in 1.9 any more. If you want to transfer questions from 1.9 to 2.x I recommend Moodle XML format.
          Hide
          jmvedrine Jean-Michel Vedrine added a comment - - edited

          Hello Tim,
          I can confirm that your fix is working. Here is the test I made.
          I created a similar multichoice in Moodle 2.3. I exclusively used Dragmath to create the matrix both in questiontext and in choices.
          For reference I will upload picture of the question preview and of the display in the editor (both question text and choices) when creating the question. Then I exported it using GIFT format and re-imported it. I find no difference with the original question and the display of math formulas is still OK. I will post the GIFT file so that it is possible to make comparisons with the tex.gift.txt file that you posted.
          But if this fix is applied to Moodle, I think that the doc at http://docs.moodle.org/23/en/GIFT#Special_Characters_.7E_.3D_.23_.7B_.7D need to be fixed too because currently it tells NOT to escape the backslash character so this must be changed.

          Show
          jmvedrine Jean-Michel Vedrine added a comment - - edited Hello Tim, I can confirm that your fix is working. Here is the test I made. I created a similar multichoice in Moodle 2.3. I exclusively used Dragmath to create the matrix both in questiontext and in choices. For reference I will upload picture of the question preview and of the display in the editor (both question text and choices) when creating the question. Then I exported it using GIFT format and re-imported it. I find no difference with the original question and the display of math formulas is still OK. I will post the GIFT file so that it is possible to make comparisons with the tex.gift.txt file that you posted. But if this fix is applied to Moodle, I think that the doc at http://docs.moodle.org/23/en/GIFT#Special_Characters_.7E_.3D_.23_.7B_.7D need to be fixed too because currently it tells NOT to escape the backslash character so this must be changed.
          Hide
          jmvedrine Jean-Michel Vedrine added a comment -

          All files from my test with moodle 2.3

          Show
          jmvedrine Jean-Michel Vedrine added a comment - All files from my test with moodle 2.3
          Hide
          jmvedrine Jean-Michel Vedrine added a comment -

          Unfortunately fixing broken GIFT files is very difficult because we must escape backslash used as backslash but not backslash used to escape all other special characters !! For instance backslash+bracket used outside of a TeX formula should be left unchanged but inside a TeX formula the backslash should be escaped !!
          I will look at MDL-28540 to see if I can make a math GIFT format.

          Show
          jmvedrine Jean-Michel Vedrine added a comment - Unfortunately fixing broken GIFT files is very difficult because we must escape backslash used as backslash but not backslash used to escape all other special characters !! For instance backslash+bracket used outside of a TeX formula should be left unchanged but inside a TeX formula the backslash should be escaped !! I will look at MDL-28540 to see if I can make a math GIFT format.
          Hide
          timhunt Tim Hunt added a comment -

          I think import leave \ alone, so to fix an existing GIFT file, just try replacing
          with \\\\.

          Show
          timhunt Tim Hunt added a comment - I think import leave \ alone, so to fix an existing GIFT file, just try replacing with \\\\.
          Hide
          jmvedrine Jean-Michel Vedrine added a comment -

          Yes you are right, I hadn't spotted that in Luciana's description : fortunately import leave single backslash untouched. I was able to fix tex.gift.text just by replacing double backslahs by quad backslashs (By the way it's very painfull to have a discussion about backslashs on JIRA !!) and it imported fine.
          So I think the docs should be modified

          • to enforce the need to escape backslashs when writting files in GIFT format
          • to explain the trick to import 1.9 GIFT files
            If you are OK I can try to edit the doc page ?
          Show
          jmvedrine Jean-Michel Vedrine added a comment - Yes you are right, I hadn't spotted that in Luciana's description : fortunately import leave single backslash untouched. I was able to fix tex.gift.text just by replacing double backslahs by quad backslashs (By the way it's very painfull to have a discussion about backslashs on JIRA !!) and it imported fine. So I think the docs should be modified to enforce the need to escape backslashs when writting files in GIFT format to explain the trick to import 1.9 GIFT files If you are OK I can try to edit the doc page ?
          Hide
          timhunt Tim Hunt added a comment -

          Yes, please edit the docs.

          Show
          timhunt Tim Hunt added a comment - Yes, please edit the docs.
          Hide
          poltawski Dan Poltawski added a comment -

          Thanks a lot Tim, integrated to master, 23 and 22

          Show
          poltawski Dan Poltawski added a comment - Thanks a lot Tim, integrated to master, 23 and 22
          Hide
          abgreeve Adrian Greeve added a comment -

          Tested in 2.2 and master. Gift files are now exporting \ characters as expected.
          Test passed

          Show
          abgreeve Adrian Greeve added a comment - Tested in 2.2 and master. Gift files are now exporting \ characters as expected. Test passed
          Hide
          poltawski Dan Poltawski added a comment -

          Congratulations!

          You've made it into the weekly release!

          Thanks for your contribution - here are some random drummers to keep you inspired for the next week!
          http://www.youtube.com/watch?v=_QhpHUmVCmY

          Show
          poltawski Dan Poltawski added a comment - Congratulations! You've made it into the weekly release! Thanks for your contribution - here are some random drummers to keep you inspired for the next week! http://www.youtube.com/watch?v=_QhpHUmVCmY

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                10/Sep/12