|
From: LÓPEZ M. D. J. <Dav...@up...> - 2025-10-18 12:07:22
|
Thank you for your answers. I think that (setf (get 'mminus 'tex-rbp) 100) is just the code I was looking for. Best regards, David. ________________________________ De: Robert Dodier <rob...@gm...> Enviado: sábado, 18 de octubre de 2025 6:00 Para: LÓPEZ MEDINA, DAVID JAVIER <Dav...@up...> Cc: max...@li... <max...@li...> Asunto: Re: [Maxima-discuss] Weird behaviour of maxima and tex function with minus signs On Fri, Oct 17, 2025 at 11:54 AM LÓPEZ MEDINA, DAVID JAVIER <Dav...@up...> wrote: > (%i1) -1-2*x-(-3*y)-4*z; > > leads to the output > > (%o1) - 4 z + 3 y - 2 x - 1 > > (what is nice), but the tex output is strange > > (%i2) tex(%)$ > $$-\left(4\,z\right)+3\,y-2\,x-1$$ Placement of parentheses is governed by what is called right binding power and left binding power -- these are essentially operator precedence levels. The rbp and lbp for various operators have been adjusted over the years to solve parentheses placement problems, in particular, to ensure that there are parentheses to make the expression unambiguous. This sometimes leads to excess parentheses, as we see here. A quick fix for this specific problem is :lisp (setf (get 'mminus 'tex-rbp) 100) which, for TeX output, reduces the right binding power from its current value (134) to 100. This is enough to get the expected behavior in the example shown -- after that, I get tex (-1-2*x-(-3*y)-4*z); => $$-4\,z+3\,y-2\,x-1$$ Whether the different binding power is generally desirable would depend on how it interacts with other operators such as "+", "*", "/", and "^". I will open a bug report about to keep track of whatever I (or anyone else) can figure out. Robert |