Matrix of answer boxes?

Matrix of answer boxes?

by Ton Boerkoel -
Number of replies: 9

Is it possible to create a question like


where the {_0} {_1} {_2} and {_3} are arranged in an inline array. The math in TeX form is easy to create before and after. I just need to know if the Formulas Question type allows for an inline array like the one shown.

Whenever I tried this using changes to the HTML code, the HTML created by Moodle Formulas changed my HTML code again. I tried putting a table there, but tables are automatically displayed on a new separate line (left aligned). Can I get an inline table (with vertical alignment: center)?


Average of ratings: -
In reply to Ton Boerkoel

Re: Matrix of answer boxes?

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
Hello Ton,

There are different ways of doing this. For 2 x 2 matrices, I didn't bother to put the coefficients in arrays, but you can certainly do that if you want. I like MathML, but I used TeX as you.

As for using a table, I found the formatting easier by simply positioning the input boxes directly with coordinates.

Besides, I sometimes find it much easier to use the "Plain text area" editor rather than the "Atto HTML editor" when editing slightly complex formatting code. But be careful, you end up without a net. Woe to you if you forget to close a <div>, because the "Plain text area" editor won't close it for you, and you might end up in a sticky situation.

You can try the question at: https://moodleformulas.org/course/view.php?id=78&section=3 ↗. The XML file of the question is attached and this is what it looks like:

Formulas_20200821_2111.png

In reply to Dominique Bauer

Re: Matrix of answer boxes?

by Ton Boerkoel -
Thank you Dominique,

I really appreciate your answer. The link you included, did display slightly differently on my safari browser, though ... not on one line:


But I am glad to see that indeed the 2x2 answer boxes can be created this way. I am not familiar with MathML. I also have to confess that I was not quite sure what to do with the XML file. I did manage to directly import the file into Moodle though. There too, the matrix appeared not all on the same line. Actually worse, in the Moodle preview, the boxes seem to overlap:
)  

I guess I have to figure out why the safari browser displays your linked picture differently, and why the Moodle preview also displays it differently from your image. I did notice that you had to code the matrix multiplication. That would be a pain for bigger matrices. I wish Moodle could interface with a computer algebra system, like my TI-Nspire calculator.  

Again thanks very much for your help! If you have any idea how we can fix the display and get everything on one line, please let me know. Also what is a good source to learn about MathML?



In reply to Ton Boerkoel

Re: Matrix of answer boxes?

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
Ton,

The full equation is split into three lines, corresponding to the three equations I used to build it.
I used the LaTeX standard inline delimiters \( and \) for the equations. I'm not sure, but I think it's not a problem with the browser but maybe with MathJax or whatever.

Regarding MathML, I think it is sometimes easier to use than LaTeX. Typically, you need an editor to create MathML equations. So you must be satisfied with what the editor offers you. You won't waste your youth trying for example to fine-tune the exact position of a bar above a symbol, as most LaTeX users do. smile You just have to find a good equation editor. Most provide both LaTeX and MathML codes.

If you do a lot of math, you might want to take a look at the STACK plugin, which specializes in math.
In reply to Dominique Bauer

Re: Matrix of answer boxes?

by Ton Boerkoel -
I have been looking at your solution. It seems that you basically write several lines of text (TeX/MathML) and superimpose the boxes {_0}, {_1}, {_2} and {_3} at their correct relative locations on a page. Although I find it an interesting solution,  it does seem like a 'hack'. There must be a general way of doing this. Matrices are so important in math: someone must have included this option in Formulas as a standard feature (or someone should create it). I teach linear algebra every semester and cannot possibly see myself hacking my way through every question using the method you outlined. I have to deal with matrices of all kinds of dimensions. [ I did ask our IT to install STACK, and a matrix editor plugin. ]

The following can be created easily with a table:

It would be great if this table can somehow be put on one line with TeX before and after it!  That would solve it.
In reply to Ton Boerkoel

Re: Matrix of answer boxes?

by Ton Boerkoel -
I can now create

using html tables. Each line is a table, and the answer boxes, within those,  are inline tables [ <table style="display:inline;"> ].
I can live with the answer boxes being slightly offset vertically. Don't have the time to figure out how to correct that. 
I can cut and paste the html setup each time I need it, and change the TeX separately. Thanks for your help, Dominique!
Average of ratings:Useful (2)
In reply to Ton Boerkoel

Re: Matrix of answer boxes?

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
Hello Ton,

It looks great!

Would you like to share the XML file for the question you show in your last post?
In reply to Dominique Bauer

Re: Matrix of answer boxes?

by Ton Boerkoel -
Not quite sure how to do this. Below is the XML file (I hope I did that correctly).  Here is what it looks like on my Mac.
I don't think my school uses the latest Moodle version yet.


The main idea is that every part is basically a HTML table with text (or TeX) on the left, an inline table, and text (or TeX) on the right.  I insert it directly using the <> button. Here is the code:

<table>

<tbody>

<tr>

<td>Text on the left

<table style="display:inline;"><tbody><tr><td>{_0}</td><td>{_1}</td></tr><tr><td>{_2}</td><td>{_3}</td></tr> </tbody></table>

Text on the right</td>

 </tr>

</tbody>

</table>

In my case I inserted TeX (for the text) which created the square brackets. You can make these any size with \left[ and using a phantom space for the appropriate hight (and of course \right. etc.) In the above example I just used \Big[  for simplicity.  I Hope that helps. [I don't really know HTML code but this seems to work.]
Average of ratings:Useful (1)
In reply to Ton Boerkoel

Re: Matrix of answer boxes?

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
Hello Ton,

Thank you very much for sharing your question. I'm sure the way you've devised it can serve as an example and will be helpful to many people.
In reply to Dominique Bauer

Re: Matrix of answer boxes?

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello Ton,

I can live with the answer boxes being slightly offset vertically.
You can adjust the vertical position of the table by adding the following properties: "position:relative;top:-5px;":

<table style="display:inline;position:relative;top:-5px;">

which simply means that the table will be displayed 5px higher relative to its normal position.

I don't really know HTML code but this seems to work.
You might find it helpful to know a little bit, it's not difficult. https://www.w3schools.com/ is a great place to learn.