WeBWorK Main Forum

gateway formatting ans_array() in Safari and Chrome

gateway formatting ans_array() in Safari and Chrome

by Gavin LaRose -
Number of replies: 3
Hi all,

I'm seeing the following odd behavior when viewing a gateway/quiz assignment with an ans_array(). The problem code, stripped down, is the following.

DOCUMENT();
loadMacros( "PGstandard.pl", "MathObjects.pl" );

Context("Vector");
$x1 = ColumnVector( 1, 2 );

Context()->texStrings;
BEGIN_TEXT
\(\vec x = \) \{ $x1->ans_array() \}
END_TEXT
Context()->normalStrings;

ANS( $x1->cmp() );

ENDDOCUMENT();

In Firefox, this displays as I expect (first image in attached):

\vec x = [ ]
         [ ]

while in Safari and Chrome, it breaks after each equation (second image):
\vec x =
[ ]
[ ]

If I change the answer blank call to ans_rule(), this behavior is not seen (all formatting is as I expect); if I view the same problem in a regular homework set, it is not seen either. All of this behavior is the same in PG and PGML, and the same whether the vector is a column vector or not.

My next step is to start tracking back through the HTML generated by the different content generators. It's odd to me that there is a difference, however, in that the problem HTML is generated in either case through PG and is therefore the same. So it's something to do with the styling or javascript in the gateway page that isn't there in the problem page (or vice versa, of course).

Any insight on this is very welcome.
Thanks,
Gavin

Attachment ansarray.png
In reply to Gavin LaRose

Re: gateway formatting ans_array() in Safari and Chrome

by Davide Cervone -
The problem is that ans_array() uses an HTML <table> to do the alignment, which is a block-level tag. When a block-level tag appears inside a tag that only allows in-line tags, then that tag will be ended before the <table> (the browser inserts an end tag before the table begins).

The paragraph tag (<p>) is a tag that can only contain in-line tags. So the answer array will always cause a line break in that case, since the paragraph will be ended automatically by the browser before the table starts.

When the ans_array() code was written, browsers didn't do that (the HTML language hadn't been as standardized at that point), so this didn't happen originally. It also doesn't happen if there is no explicit paragraph tag, so it doesn't always happen, but recent changes to force paragraphing to help knowls appear better will also make this situation worse. Apparently, Firefox and WebKit (the engine that underlies both Safari and Chrome) disagree on how this should be handled.

In any case, the problem is in the MathObject library, and I need to rewrite the ans_array() code to use CSS rather than tables to lay out the arrays. That's a bit of a pain, but can (and should) be done, so that the arrays can be used in-line without trouble.

It's on my list...
In reply to Davide Cervone

Re: gateway formatting ans_array() in Safari and Chrome

by Gavin LaRose -
Thanks, Davide. That was basically what I was thinking was the issue. I was a little surprised that it was manifest only when the problem appeared in a gateway test, and not in a regular problem set, but the issue with paragraph handling around the solution knowls could well account for the difference.

Gavin
In reply to Gavin LaRose

Re: gateway formatting ans_array() in Safari and Chrome

by Davide Cervone -
I just made a pull request that replaces the <table> elements with CSS styling instead, so this should resolve the problem. You should be able to download the pg/lib/Value/AnswerChecker.pm file and replace your current one (and restart the server) to get the change.