You should not expect nested constructions involving limits, trig functions or integrals to work. It's difficult if not impossible to do this via regular expression substitution on the TeX expression output by the WeBWorK algebra parser. To get this to work properly, one would need to delve into the innards of the WeBWorK parser and make modifications there. I won't have time to do this in the near future.
You can write such expressions using TeX notation. You use algebradebug.php to do a translation into TeX and then repair the incorrect translation there.