grzegorzmazur / yacas

Computer calculations made easy
http://www.yacas.org
GNU Lesser General Public License v2.1
124 stars 24 forks source link

TeXForm brackets #285

Closed mikldk closed 4 years ago

mikldk commented 4 years ago

TeXForm(Sin(a*x)) gives me \sin a x. Can I somehow instruct yacas to put brackets to obtain \sin \left ( a x \right )? I know there is various opinions, but in this case I need it. So I am not seeking a change in yacas but maybe a yacas rule or option to get what I need for my current session.

mikldk commented 4 years ago

Maybe this is a global fix:

# texform.rep/code.ys
   // generic math functions of one argument
-  120 # TeXForm(expr_IsFunction, _p) _ (NrArgs(expr)=1 And Contains(AssocIndices(TeXFormMathFunctions), Type(expr)) ) <-- TeXFormBracketIf(p<OpPrecedence("*"), ConcatStrings(TeXFormMathFunctions[Type(expr)], TeXForm( Listify(expr)[2], OpPrecedence("*")) ) );
+  120 # TeXForm(expr_IsFunction, _p) _ (NrArgs(expr)=1 And Contains(AssocIndices(TeXFormMathFunctions), Type(expr)) ) <-- TeXFormBracketIf(p<OpPrecedence("*"), ConcatStrings(TeXFormMathFunctions[Type(expr)], TeXForm( Listify(expr)[2], OpPrecedence("^")) ) ); 

I.e. replacing the last OpPrecedence("*") with OpPrecedence("^"). Can I somehow override such a rule in my local session? Or maybe make it an an option somewhere?

grzegorzmazur commented 4 years ago

Hi,

I've just committed a fix based on your idea, only with a new parameter TeXForm'FuncPrec. It allows for setting the precedence without modifying the rule.

Cheers, Grzesiek

mikldk commented 4 years ago

Thanks!

Should it check for a positive number instead of just a number?

grzegorzmazur commented 4 years ago

Hi,

I'd rather not silently override user settings, even if silly. In principle I should have checked if it evaluates to anything other than itself, checking for a number is already cheating 😉

Grzesiek