## WeBWorK Problems

### Force all parens to be parentheses

by Alex Jordan -
Number of replies: 4

Now that we can use tikz in a PG problem, it's nice to plot a function using pgfplots ad the \addplot macro. However there are some incompatibilities between how MathObjects prints a formula and what the syntax for an argument to \addplot must be. One of these incompatibilities is that \addplot does not understand brackets as a grouping symbol. So if you have like:

$f = Formula("1/(x(x+1))"); Later if you are in tikz code and use \addplot ... {$f};

It becomes

and the latex image compilation fails.

Is there a way to force brackets (and braces?) to be parentheses in MathObjects string output?

I have hit a few other incompatibilities and I resort to manually re-writing the formula in the tikz code. But most of these time, this issue has been this bracket issue.

### Re: Force all parens to be parentheses

by Andrew Swanson -
I use these two lines (this is from a subroutine, so the variable $exp is local): my$exp = $f->string;$exp =~ tr /[]/()/; #TikZ does not like square brackets so translate them for parentheses

Then you can

### Re: Force all parens to be parentheses

by Alex Jordan -

Yes, I did think about something like this that would search-and-replace on the strings. But I'd like to know if there is something more slick like a context flag. So it would be set once (well, once for each context where it's needed) and then work for all the functions I might plot in that problem. I looked at the wiki for a flag like this and didn't find one. I have not yet searched the MathObjects code, but that is my next step if something doesn't come up on this thread about it.