WeBWorK Problems

How to align displayed equations?

How to align displayed equations?

by Siman Wong -
Number of replies: 6
Does webwork allow us to align displayed equations? I have in mind something like this:

Xone= two

= three some comments

= four some comments

Note: one of those one/two/three/four could be input boxes for students.

Thanks!



EDIT: my message does not come out properly the way I want (why is there an X at the beginning of "one"?!!), so here's a latex version of what I have in mind:

$$
\begin{array}{llllll}
one & = & two
\\
& = & three & comments
\\
& = & four & comments
\end{array}
$$

In reply to Siman Wong

Re: How to align displayed equations?

by Dick Lane -
Here is a version (omitting the comments) which WeBWorK / MathJax can display

\[ \begin{aligned}
one
 & = two  \\
 & = three = thrice = tripled  \\
 & = four
\end{aligned} \]

This seems a good topic for a new page in the wiki (especially if we learn about a variety of ways to do this task).
In reply to Dick Lane

Re: How to align displayed equations?

by Jim Fischer -
Hi Dick,

I tried your snipet and Simon's too. They both displayed arrays fine. However, when I tried to insert an answer box by entering perl mode there is an error in the display. Im sure I have seen problems where authors insert perl within tex mode, but I cant seem to find one. Here is an example of what I mean and what I believe Simon wants to do:

\[ \begin{aligned}
one
& = two \\
& = three = \{ ans_rule(5) \} = tripled \\
& = four
\end{aligned} \]

In reply to Jim Fischer

Re: How to align displayed equations?

by Jim Fischer -
I hope I didn't hijack your question Siman. After looking thru the library, it appears that one can't insert perl commands within tex mode. I guess this makes sense. If this is the case, maybe you have to format the array outside of tex?



In reply to Jim Fischer

Re: How to align displayed equations?

by Siman Wong -
I too had tried to insert perl commands inside the tex codes before I posted my question; I just like to confirm that I'm not missing something obvious.

And feel free to hijack my thread; one day maybe I too will be about to help others :-)
In reply to Siman Wong

Re: How to align displayed equations?

by Alex Jordan -
Instead of inserting Perl into TeX, you can insert TeX into Perl. There are PG table commands that produce aligned tables. You can have TeX, or other Perl/PG objects at any entry in the table.

I believe that PG has a simple table command, but I go straight to the one provided by PGunion.pl. Read about it here:
http://webwork.maa.org/wiki/Tables
Scroll to the bottom to read about the tables that PGunion allows. There's more documentation here:
http://webwork.maa.org/viewvc/system/trunk/pg/macros/unionTables.pl?revision=6499&view=markup

Each entry in these tables can be:
  • strings encased in " "
  • LaTeX encased in "\( \)"
  • some kind of Perl/PG command (including ans_rule), with no surrounding quotation marks
If you are using PGunion's tables, then the whole thing was surrounded with \{ \}, and you are inserting TeX into Perl.
In reply to Alex Jordan

Re: How to align displayed equations?

by Dick Lane -
If the intent is to present an organized collection of answer boxes, perhaps
        http://webwork.maa.org/wiki/AlignedChoice
(which discusses presentation of Aligned Answer Blanks) will be relevant.

FWIW: that example loads PGunion.pl, but I have been able to omit it --- perhaps because alignedChoice.pl loads unionUtils.pl.