Hi,

I have been toying around with the LaTeX printing over the last couple  
of days and in the process have put together a few (potentially  
idiosyncratic) changes to the printing class. I would be interested to  
know what everyone thinks of this (i.e., is there enough interest that  
it is worth making them mainstream).

Firstly, I added support for fractional power folding. If an exponent  
is of the form p/q where both p and q are rational (and q is not 2, as  
then a square-root is appropriate) then the fraction is folded. Here  
is an example:
 >>> ex = sympify('x^(3/4)')
 >>> latex(ex)
'$x^{\\frac{3}{4}}$'
 >>> latex(ex,foldFracPowers=True)
'$x^{3/4}$'

As you can see instead of a fraction a plain old division symbol is  
used. This is often nice when handling fractions of the form p/q^a as  
it saves all-important vertical space and makes the power much more  
readable (as the font size will be larger).

Secondly, I have added support for function bracket folding. If a  
function (lets say tan) has one and only one argument which does not  
itself need brackets, then it is possible to fold them. Another  
example if you will:
 >>> ex = sympify('tan(2*x)')
 >>> latex(ex)
'$\\operatorname{tan}\\left(2 x\\right)$'
 >>> latex(ex,foldFuncBrackets=True)
'$\\operatorname{tan}2 x$'

This is done by the addition of a new function  
_needs_function_brackets, which is a more generalised form of  
needs_brackets, namely one that allows Mul and Pow to not require  
them. I am still testing this, however, so there may be some cases  
where it (erroneously) omits brackets. I am still working on a way to  
handle tan(x)*cos(x) (currently '$\\operatorname{cos}x \ 
\operatorname{tan}2 x$') but it might come down to either a) folding  
tan(x*cos(x)) to tan xcos x or b) folding tan(x)*cos(x) to tan x cos x.

Finally, I would like to apologise for my use of camelCase, I'll fix  
that soon.

Regards, Freddie.

Attachment: PGP.sig
Description: This is a digitally signed message part

Reply via email to