How to input a double tilde in the answer?

How to input a double tilde in the answer?

by Marcin Miłkowski -
Number of replies: 7
Hi, I'm having a critical error in short answers. I'm using Moodle to teach logic, and I need my students to complete short answers in a process of building a proof. Now, I need two tildes (~~) in some of my proof lines. Unfortunately, escaping them doesn't work: when I input {1:SA:=\~\~p} I get \\~\\~p as decoded answer. The problem is that Moodle wants \~\~p as the answer, and that makes no sense...

Without \, however, the answers gets parsed into two.

Seems like parsing of backslashes is broken somewhere. I'm using Moodle 1.9.5. I tried regexp module but even though I replaced questiontype.php, I could not save the quiz with regexp questions (could not insert question options or something similar).

Thanks for any pointers, Marcin
Average of ratings: -
In reply to Marcin Miłkowski

Odp: How to input a double tilde in the answer?

by Marcin Miłkowski -
Answering myself: though backslashes do not work correctly, you can input ~ as a Unicode hex entity this way: ~ (you need to switch the WYSIWYG mode off). So two tildes are ~~.

Anyway, backslash escaping support is buggy. I wasted 6 hrs on that sad

Regards
Marcin
In reply to Marcin Miłkowski

Re: How to input a double tilde in the answer?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Marcin

I tried regexp module but even though I replaced questiontype.php, I could not save the quiz with regexp questions (could not insert question options or something similar).

What do you mean by "I replaced questiontype.php"? The regexp question type is a question type of its own, you have to install it in moodle/question/folder; it does not "replace" anything.

You cannot say that the backslash escaping support is buggy; what happens is that - as you know - the tilde ~ is used a separator between the cloze question's subquestions, and the sequence of 2 tildes ~~ ruins the close question's syntax analysis. You are probably the first user of Moodle ever to have needed a sequence of 2 tildes in their question's answer text.

I'm glad that you found a solution using the Unicode hex entity. It seems the most sensible workaround to adopt for such rare occurrences of ~~.wink

Joseph

In reply to Joseph Rézeau

Odp: Re: How to input a double tilde in the answer?

by Marcin Miłkowski -
What do you mean by "I replaced questiontype.php"? The regexp question type is a question type of its own, you have to install it in moodle/question/folder; it does not "replace" anything. Sorry for being vague, it was late at night...

What I meant was that I added the files to moodle/question/type/regexp and replaced the file moodle/question/multianswer/questiontype.php as I wanted to use regexp in cloze quizzes. It would be useful to have a regexp for catching possible whitespace around operators smile So regexp doesn't work for me in cloze quizzes (embedded answers). I don't know why it doesn't work... :/

Anyway, I don't quite get what you mean by saying "you cannot say that backslash escaping is buggy". It doesn't do what it is supposed to do according to the (scarce) documentation. The docs don't say it doesn't escape many characters in a row, they say I can escape them, so it's a bug when escaping is impossible. As a matter of fact, this is one of the best candidates for regression testing when you're writing tests for escaping functions or methods. All programming languages that use backslash escaping that I know behave like this - you can escape as many control characters as you wish.

What actually happens in Moodle is that you don't have to escape a single ~ or # in a html entity in a short answer (contrary to what docs say, it's OK), but if you escape two, backslash starts to quote itself, which is obviously a bug. I'm not sure if it's not a bug due to some hidden php.ini setting on my Apache but it is a bug.

I'm not sure if I'm the first user of Moodle in need of this. I googled before I started the course in Moodle - I found quite a few papers saying that they developed a custom online tutor system for teaching logic as Moodle wasn't appropriate sad I think Moodle is quite OK but some additional math plugins for writing custom code would be a bonus.

BTW, beware that Moodle will garble the entity when you edit the question. ~ will become &\x007e;, so this will break again. But automatic escaping of "#" in the entity doesn't occur when rendering the question in the quiz for students so I may live with this glitch.

Joys of php... :/

Marcin
In reply to Marcin Miłkowski

Re: Odp: Re: How to input a double tilde in the answer?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Marcin,

Thanks for the clarification. You are right, if you want to use my regexp question type as a sub-question in a cloze question you have to make a few modifications to question/type/multianswer/questiontype.php, and to do that you have to download the appropriate replacement questiontype.php file as instructed on the regexp plugin page. However the reason it does not work any more than the SHORTANSWER sub-question type in CLOZE is due to the syntax analysis of the CLOZE question itself, not to anything wrong with REGEXP.

And I have to agree with your reasoning about the bug in CLOZE question not being able to escape several ~ in a row. I hope Tim - or Pierre Pichet - will take your suggestion into consideration and provide a better way to escape that ~ separator character.

All the best,

Joseph

In reply to Joseph Rézeau

Odp: Re: Odp: Re: How to input a double tilde in the answer?

by Marcin Miłkowski -
Hi Joseph,

well, I already filed the bug about html unicode entities being escaped, and I will file a bug against the double tilde problem as well.

But returning to my problem regarding REGEXP in CLOZE - I cannot make it to work as I get "Could not insert quiz regexp options!" as an error message when I try to save a regexp type of CLOZE ({1:REGEXP:=first answer~=first +answer}). How could I fix that?

Thanks in advance,
Marcin
In reply to Marcin Miłkowski

Re: Odp: Re: Odp: Re: How to input a double tilde in the answer?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Marcin,
Your syntax is not what is expected by the REGEXP question type. Please see the REGEXP online help, from which I have extracted the following:

Inserting regexp sub-questions in Cloze type questions

The syntax for inserting regexp sub-questions in Cloze type questions is as shown in the following examples.

  • The colors of the French flag are {:REGEXP:=blue, white and red#Correct!~=it’s blue, white(,| and) red#Correct!~--.*blue.*#The color of the sky is missing.}
  • The colors of the French flag are {:REGEXP:%100%blue, white and red#Correct!~%100%it’s blue, white(,| and) red#Correct!~--.*blue.*#The color of the sky is missing.}

Please note that the best (or only) correct answer must be Graded 100% (in Cloze type question syntax, correct is either = or %100%) and it must not be a regular expression.

Please note that the syntax of the sub-questions inside a Cloze-type question must be followed exactly and that you must never ever copy and paste any question text from e.g. a word-processor into the Cloze-type question editing window. Quite often Cloze-type questions yield errors because extraneous blank spaces, new lines, or any odd formatting character has made its way into the question text.


In reply to Marcin Miłkowski

Re: Odp: Re: Odp: Re: How to input a double tilde in the answer?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Marcin,
Please give the reference of your bug reports concerning the problem at hand, for easy reference. All you have to do is write the bug report's reference in your message; do not put any link, the correct link will be added automatically. e.g. "HTML numerical entities get escaped when editing the question" : MDL-21012
Joseph