WeBWorK Problems

latex newcommand

latex newcommand

by Helena Verrill -
Number of replies: 1
Is it possible to use the "newcommand" of latex in a problem?
for example, I would like to include something along the following lines:

\(\newcommand{\abcd}[4]{\left(
         \begin{smallmatrix}#1&#2\\ #3&#4\end{smallmatrix}\right)}\)


\(\abcd{6}{3}{4}{7}\)

I put this with the BEGIN_TEXT  END_TEXT
However, this does not produce what it would if it was in latex.
I've inserting brackets or extra backslashes in various places, but perhaps
not the right ones.
Thanks for your help,
Helena
In reply to Helena Verrill

Re: latex newcommand

by Michael Gage -
You probably won't be able to do this the way you planned. Probably what you want is to use the Matrix MathObjects (see below).

However if absolutely necessary one can add tex commands to the files webwork2/conf/snippets/hardcopyPreamble.tex which is loaded before printing a hardcopy and to webwork2/lib/WeBWorK/Constants.pm which is loaded before each equation is typeset. In order to maintain compatibility of p[roblems over a period of time one should be pretty cautious about doing this.

For the math objects make sure to load the macro file "Parser.pl"
and try something like this snippet:

TEXT(beginproblem());

($a,$b,$c,$d) = (23, 25, 45,8);
$ma = Matrix([$a, $b], [$c, $d]);

Context()->texStrings;
BEGIN_TEXT

\( $ma \)

END_TEXT
Context()->normalStrings;