## WeBWorK Problems

### math in tables ### math in tables

by Helena Verrill -
Number of replies: 5
I want to put some math in the top of an array, eg:

TEXT(
begintable(2),
row("$$x$$","$$x^2$$"),
row($a, ans_rule(10)), row($a, ans_rule(10)),
row($a, ans_rule(10)), endtable() ); However, this just puts the string $$x$$ and $$x^2$$ in the top row of the array. I can't work out how to get this to look like nice typeset math. What should I be including to get this to work? Also, where do I find a list of options/attributes for the begintable function, such as spacing options, or if it's possible to center elements, etc? Thanks, Helena In reply to Helena Verrill ### Re: math in tables by Michael Gage - Good questions -- and there are several answers. First -- the magic that replaces the perl strings in curly brackets and the LaTeX strings in  and  is done by a function EV3() (for evaluator 3 -- it was the third attempt :-) ) So TEXT( begintable(2), row(EV3("$$x$$"),EV3("$$x^2$$")), row($a, ans_rule(10)),
row($a, ans_rule(10)), row($a, ans_rule(10)),
endtable()
);

will work.

BEGIN_TEXT
...
END_TEXT

translates into perl as

TEXT(EV3(<<'END_TEXT'));

...
END_TEXT

and all of the text before END_TEXT is passed through the EV3
filter.

So you could also write your table as

BEGIN_TEXT
\{begintable(2)\}
\{row("$$x$$","$$x^2$$"\}
\{row($a, ans_rule(10))\} \{row($a, ans_rule(10))\}
\{row($a, ans_rule(10))\} \{endtable() END_TEXT To get more control over the tables you'll need to load the table macros defined (and commented) in the macro file unionTables.pl which is in the union_problib/macros directory in the CVS. Hope this helps. In reply to Michael Gage ### Re: math in tables by Helena Verrill - I am still not getting quite what I want, though using EV3 now strips off the backslash; but it still doesn't latex the math. I am using webwork version 2.3.0 - is this too old? Also, for the "unionTables.pl" file, I get an error message when I try and put it under "loadmacros". Do I first have to download and install this? Thanks Helena In reply to Helena Verrill ### Re: math in tables by Michael Gage - The backslashes are being swallowed -- use this instead for the first method: row(EV3('$$x$$'),EV2("$$x^2$$")), You can either use EV3 and double the backslashes or you can use EV2 and not double the backslashes. A complete explanation of this involves what perl does with backslashes and the hoops that PG jumps through to compensate. EV3 compensates in one way (and the second method above should work fine) EV2 compensates in another. (There is a typo at the end of the second example -- there is a missing \} after endtable() ) If you are running your own server you need (1) make sure that you have a copy of the union macros on your machine (download the union_problib from the CVS) and (2) put those macro files in the search path (this is an entry in global.conf )  # # The macro file search path. Each directory in this list is seached # (in this order) by loadMacros() when it looks for a .pl file. #$pg{directories}{macrosPath} = [ ".", # search the problem file's directory $courseDirs{macros},$pg{directories}{macros}, 'path-to-libraries/union_problib/macros', ]; 
That will allow you enter "unionTables.pl" as one of the files to be loaded using loadMacros( );

-- Mike ### Re: math in tables

by Michael Gage -
The backslashes are still being swallowed

row(EV3('\$$x\$$'),EV2("$$x^2$$")),

is what I meant. 