WeBWorK Problems

Adding Curly Braces to enclose a set of column vectors.

Adding Curly Braces to enclose a set of column vectors.

by Elbridge Gerry Puckett -
Number of replies: 2
Hi,

I am fairly literate with TeX, LaTeX and it's AMS variants etc. but I am a novice writing problems in WeBWorK.

I have been trying to change a problem that I took from the common library which has the following line

\{ mbox( 'Let \(W\) be the set: ', display_matrix([[-2], [3], [0]]), ',', display_matrix([[6], [-1], [5]]), '.' ) \}

which simply prints the column vectors separated by a comma. I would like to enclose these vectors in curly braces, sort of like this

{ b_1 , b_2 }

However, whenever I try something like

\{ mbox( 'Let \(W\) be the set: ', \left\{display_matrix([[-2], [3], [0]]), ',', display_matrix([[6], [-1], [5]]),\right\} '.' ) \}

or any number of variants, I get an error. Can anyone tell me what I am doing wrong?

Thanks,

- Gerry

In reply to Elbridge Gerry Puckett

Re: Adding Curly Braces to enclose a set of column vectors.

by Danny Glin -
Well, I can solve some of your problem, but I haven't been able to get it to display exactly as you desire.

First a couple of notes:
\{ and \} are reserved in WeBWorK. They indicate that the system should execute the code inside these delimiters. If you want curly braces in math mode, you need to use \lbrace and \rbrace.

The next thing is that anything you want displayed inside an mbox() function should be in single quotes to indicate that it is a string. Since you are using LaTeX commands, you will also need to be in math mode, meaning you would need to prefix \left\lbrace with \(.

The other problem is that the display_matrix function automatically puts you in math mode, which would cause problems with the \( that I suggested earlier. The expected solution would be to use display_matrix_mm instead, which assumes that you are already in math mode, only this doesn't quite seem to work.

Here is the code that I would expect to work:
\{ mbox( 'Let \(W\) be the set: \(\left\lbrace', display_matrix_mm([[-2], [3], [0]]), ',', display_matrix_mm([[6], [-1], [5]]),'\right\rbrace\).' ) \}

This code displays fine in a hard copy, but on the screen it adds some extra text inside the set braces (and yet it gets the set braces the right size).

Perhaps in this case the easiest solution is to get rid of the mbox and display_matrix commands altogether, and just use straight LaTeX to display the column vectors properly.

Hopefully this helps..
Danny
In reply to Danny Glin

Re: Adding Curly Braces to enclose a set of column vectors.

by Arnold Pizer -
Davide responded on the old server. I copied his response here. I hope the formatting holds up. --Arnie

The reason your mbox command added extra text is because in HTML mode, mbox creates an HTML table and puts each entry in the mbox into a separate cell of the table. But since you have used an open math delimiter in one and a close math delimiter in another, the math mode includes the HTML tags that separate the cells, and these become part of the typeset equation.
Instead, you would want to concatenate the math strings to form a single string, as in:

\{ mbox( 'Let \(W\) be the set: \(\left\lbrace'. display_matrix_mm([[-2], [3], [0]]),','.display_matrix_mm([[6], [-1], [5]]).'\right\rbrace\).' ) \}

(using dots rather than commas).

Alternatively, you can use MathObjects to format the vectors rather than the more verbose display_matrix commands:

Context("Matrix");

$V1 = ColumnVector(-2,3,0);
$V2 = ColumnVector(6,-1,5);

Context()->texStrings;
BEGIN_TEXT
Let \(W\) be the set: \(\left\lbrace $V1,$V2\right\rbrace\).
END_TEXT
Context()->normalStrings;

or if you don't want to make separate vector objects:

Context()->texStrings;
BEGIN_TEXT
Let \(W\) be the set: \(\left\lbrace \{ColumnVector(-2,3,0)\},\{ColumnVector(6,-1,5)\}\right\rbrace\).
END_TEXT
Context()->normalStrings;

Or you could use Matrix([[-2],[3],[0]]) in place of the ColumnVector call.

Hope that helps.

Davide