academic-moodle-cooperation / moodle-mod_offlinequiz

The Offline Quiz activity allows the creation of multiple choice tests with questions from the question bank of a Moodle course, which are handed out to students in printed form. After completion, the answer forms are scanned and can be automatically evaluated online directly in Moodle.
https://academic-moodle-cooperation.org/mod_offlinequiz/
GNU General Public License v3.0
31 stars 58 forks source link

TeX issue #19

Closed fwsl closed 6 years ago

fwsl commented 7 years ago

Hi, I've got problem while creating pdf (and latex) question forms that contain latex code eg. $$\mathbf{x}^{i+1}=(0,1)$$. Everything looks fine in the Create forms Preview tab, but there is additional new line before and after each $$TeX$$ when pdf form is created. This may be because $$TeX$$ is the way moodle recognizes when to use TeX filter, but in latex $$ is a new line symbol.

kaspot commented 7 years ago

Thanks for reporting this. We forwarded this issue to our developer for further checking.

univietw commented 7 years ago

I reviewed this bug and can confirm this.

The creating of the pdf file works as follows: Every Latex-Formula is converted into an image of the formula and inserted in an html-Version of the question. This is then printed on the PDF by our used pdf-library, which is integrated in Moodle (tcpdf). I tried to fix your problem by changing the way the html is printed onto the PDF, but that caused other problems, which isn't really easy to fix, because the Code there is really old and horrible to read You can try it, just look up the pdflib.php file and try to understand what exactly happens, if you want. Therefore I would recommend you to print your questionsheets as word or directly as latex-File, which is a feature introduced some versions ago, although the latex-Version doesn't support images (yet).

fwsl commented 7 years ago

This problem exists in all of the formats. In docx tex equations are in new line and centered on the page, and in tex they are in $$ $$ $$\mathbf{x}^{i+1}=(0,2,2)$$ which creates new line before and after the equation.

fwsl commented 7 years ago

Hello, This bug is still present in v3.3.0 (2017081100) in pdf, latex and docx formats. I'll make a pull request with simple workaround for the latex version. could you check if this doesn't break anything else? Thanks

univietw commented 6 years ago

Thanks for the pull request. Ive merged it into the master, and it will be solved for Version 3.4. We will discuss, if we also release a bugfix-version for version 3.3.0

fwsl commented 6 years ago

This is a simple fix, I can create a pull request for v3.3 if needed.

fwsl commented 6 years ago

I've dug into this, and it wasn't pretty

There were two issues

  1. The "In answer texts we want a line break to avoid the picture going above the line." in html2text adds a new line before every img, because of this it is impossible to put image inline, or two images side by side. I've removed it, and things got a lot better for LATEX and also text based answers with images. Because of this removal images start above the line. But I think this repairs more than it breaks.

  2. The span attribute added by TEX filter generated line break after each LATEX usage. I've added two preg replaces. This fixes the line break after each LATEX usage.

I've made a pull request, let me know if this fix is acceptable.

fwsl commented 6 years ago

@univietw Hi, any update on my second pull request?

fwsl commented 6 years ago

@kaspot @univietw Hi, any update if my pull request is ok?

univietw commented 6 years ago

Hi, I was looking through your pull request and your point in 1.) is not as easy as it seems.

I don't know the exact story behind this, but I had a conversation with the old maintainer of the software once, where he told me, that he tried a lot of things, and every time something else broke and the solution we have now is the one that produces the lowest amount of support tickets. I would consider an option in the plugin, so everyone can choose what works best for him.

fwsl commented 6 years ago

Ok, I understand your point. This would change output for all quizes. I'll try adding:

Would this be ok?

fwsl commented 6 years ago

@univietw I've made this behavior configurable by default sitewide setting and per quiz override setting. Could you check if it's ok? I've created a new pull requests for master and 3.3 branches.

crosj commented 6 years ago

Hello, I'm a bit lost with those informations, can we consider that this bug is fixed with Moodle 3.4 and plugin v3.4.0..? We are currently testing it on Moodle 3.2 and plugin v3.2.5.. What if we install plugin 3.4.0 on MDL 3.2..? Thanks in advance

goggo24 commented 6 years ago

Hey, actually the bugfix is included in our develop_33, master and Moodle_34_Stable branch. That means, that it`s included in offline test v3.4.0. We made some small changes to your pull requests (langstring, appearance). You can finde now two settings - an adminsetting (global) and a setting for every offlne instance (local). Have fun! new_lines

crosj commented 6 years ago

Hello Thanks a lot for the fast answer ! We'll postpone use of latex until couple 3.4/3.4.0 so I guess the best way to use it is to set it locally when questions includes latex..? Or can it be set widely without side effects..? I think i didn't understood what they were... :/ Thanks in advance

fwsl commented 6 years ago

Hi global setting - what the default value for all new quizzes should be local setting - can overwrite the global setting in quiz.

It will also change how other images(not only tex) are printed in question sheets(no new lines before and after the image).

@goggo24 will this change be available in Moodle_33_Stable?

crosj commented 6 years ago

Hi @fwsl does this affect only this plugin or it has effects on other images in other activities or questions types, that's what i don't distinguish in conversation below.. Thanks !

fwsl commented 6 years ago

This only affects how images are printed in documents (mainly pdf) generated by this plugin.

goggo24 commented 6 years ago

The setting only effects the offline test PDF question sheets. The option disables new lines before and after images (picture, latex formula) in answers. Picture left without / picture right with the settting. newline_pdf

@fwsl : at the moment in the develop_33 your pull request is included and tested. So you could use develop_33. For 3.4. we did some small changes, we haven't transfered them back in 33 and therefore we didn't do a new 3.3 version.

crosj commented 6 years ago

Thanks ! ^^ ..but in fact i read again the discussion and the issue is "only" a matter of new line, in my case latex doesn't appear at all, only a new line, does latest versions solves this too..?

goggo24 commented 6 years ago

@crosj: What do you mean with "latex doesn't appear at all"?

Our teachers work with Latex in offlinequiz too. Most of them use the LATEX format for the questions sheets (form settings) and so get the whole answer sheet output in latex. Or use the DOCX format to reviste aferwards the file instead of PDF. Maybe you can open a new github issue for the problem and provide more information/screenshots.

crosj commented 6 years ago

@goggo24 On this screenshot on the left : PDF generated with online quiz and on the right : the same question in an usual test from the bank capture I used $$\frac{8}{2}$$ and $$\sqrt{16}$$ As i'm testing on MDL 3.2 and plugin 3.2.5 maybe it's outdated even if those versions are quiet recent.. Could it be an issue of pdf generation of moodle..? I may test in a book resource i guess..

fwsl commented 6 years ago

@crosj It looks like you may have problem with latex. In filters disable mathjax and enable tex notation filter. If you stop seeing latex formulas, go to https://docs.moodle.org/33/en/TeX_notation_filter#Debugging_TeX_filter

crosj commented 6 years ago

Thanks for the recommandation @fwsl i deactivated mathjax and left tex notation filter activated and regenerated PDF : no formulas (but they were in preview)..did the opposite : the same (as well in preview)...i can't tell if it's a plugin issue or filter or pdf generation.. :/

goggo24 commented 6 years ago

The offline Test uses TEX Notation for creating the PDF Output. I tried $$\frac{8}{2}$$ and $$\sqrt{16}$$ and it works fine in our moodle installation. I can see it in the pdf.

crosj commented 6 years ago

i checked but i don't see imagemagick (i added a scrshot of the page) I don't see where i could output docx..? If it's supposed to be in plugin's settings page, i don't have it (3.2.5 ?) screenshot-2018-1-19 ametice - enseigner et apprendre avec le numerique administration plugins filtres notation tex Thanks for your suggestions !

goggo24 commented 6 years ago

We have nearly the same settings, but use GIF instead of SVG. I just tried it with SVG and it works fine & I can see the formula in the pdf. Can you try to install convert on your server and try again?

crosj commented 6 years ago

Hello Thanks @goggo24 looking up my issue I'm not keen on administration, but isn't it yet installed as i see "/usr/bin/convert" in filter_tex | pathconvert's field..or the X means it is not..? Thanks Julien

goggo24 commented 6 years ago

@crosj: yes, x means that it is not installed. Has the installation changed anything? Does it work now?

crosj commented 6 years ago

Hello @goggo24 Not yet installed (i haven't the ability to do so), i'll keep up to date the conversation if i have any change. Thanks for the reply

kama-jo commented 6 years ago

Hello, I have same problem, did the proposed answer fix this bug ? Thanks