Hi all,

> I have been toying around with a couple of ideas which might be worth
> investigating for the LaTeX printer. First off, different bracket
> styles depending on the nesting level. So it might go:
> { [ ( ( ) ) ] }; exactly how to do this I am unsure. It depends on how
> easy it is to maintain the nesting level. Ideally {} and [] should
> only be used for adjacent brackets, for example:
>
> (x*(y+3)+4)^3 doesn't really require nested brackets, but:
>
> [a*exp(z*I)] does.
>
> This is the kind of thing that I might be tempted towards the evils of
> regular expressions to achieve. Hopefully, however there is a much
> more elegant solution.

Currently the best idea on the table, so far as I can discern, is the  
following:
  - Use a regular expression to find pairs and triplets of brackets  
adjacent to each other, so (( and (((;
  - for the outermost bracket(s) find the complementary bracket (so  
its opposite) -- this is easy to do using a stack;
  - replace it and its complement with the appropriate substitution,  
'[' or '{'.

It is not possible to use closing brackets and work backwards as  
function calls should *always* use ( ), e.g., in (x + ln(x*(x+1)))^n  
working backwards would give us {x + ln[x*(x+1)]} -- not what we want.

> Secondly, constant expanding. If one has a fraction <x>/k where k is a
> constant it is often nice to pull the constant out front when
> printing, giving 1/k * <x> where <x> is an arbitrary expression. This,
> again sacrifices horizontal space for better readability (a larger
> font size can be used for <x>). I am yet to look into how hard this
> would be to achieve, however.

I am currently putting together some examples where I feel this has a  
positive impact on readability. A good example is sin(1/2 * x), on in  
LaTeX \operatorname{sin}\frac{1}{2} x as opposed to \operatorname{sin} 
\frac{x}{2}. The output of Wolfram's Interator, 
http://integrals.wolfram.com/index.jsp 
  is usually quite good at deciding whether to pull the constant out  
or not. (Although do not believe the claim about it being the "world's  
only full-power integration solve", Axiom eats it for breakfast :)

> Finally, an option to use exp() as opposed to {e}^{<x>}. This is most
> useful when outputting the solutions to differential equations, which
> often raise e to quite a large fraction/expression. Using exp() leads
> to better readability (due to the larger font size and greater
> spacing). I propose the following: we have a configuration option to
> choose between {e}^{x}, exp(x) and auto, where auto uses heuristics to
> decide (as soon as you get to needing brackets or fractions exp() is
> often nicer).

Again, some examples are needed. e^{\operatorname{tan}x} looks okay,  
as does e^{ax+b} but two fractions (so a/b + p/q) usually don't. A way  
to see if a mul will end up as a fraction would be nice.

Finally, while playing around some more with the LaTeX output (and  
showing it to whoever was willing to listen) I found that some have an  
affinity for tan-1 (\operatorname{tan}^{-1}x as opposed to atan or  
arctan. G&R use arc<x> where <x> is an trigonometric function.

My proposal here is to support all three inverse trigonometric forms,  
arc<x> being the default (it is what LaTeX defines, \arctan{x}) but  
also supporting the other two forms by way of an optional parameter to  
latex(expr,...).

The simplest way of implementing this is probably to use a look-up  
table to identify a function as an inverse trigonometric function.  
Then it is a simple case of stripping the first character and  
appending either 'arc', 'a' or suffixing '^{-1}'.

In the case of atan(x)**2 being output in the form of tan-1 the output  
would be: \operatorname{tan}^{-1}\left(x\right)^{2}. (Even if bracket  
folding is enabled and applicable, when outputting as tan-1 where tan  
is raised to a power brackets would be mandatory.)

Regards, Freddie.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com
To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to