rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

Double superscript in tex(conjugate(z))^2 #3937

Closed rtoy closed 2 months ago

rtoy commented 2 months ago

Imported from SourceForge on 2024-07-08 21:25:19 Created by matan-bebop on 2023-03-05 14:45:11 Original: https://sourceforge.net/p/maxima/bugs/4112


(%i1) declare(z, complex)$
(%i2) tex(conjugate(z)^2);
$$a^\star^2$$

Workaround:

texput(conjugate, lambda([conje], sconcat(tex1(first(conje)), "^*")))$

texput("^", lambda([e], block(
                   [base : first(e), pow : second(e)],
                   if atom(base) then
                        sconcat(tex1(base), "^*")
                   else if op(base) # conjugate then
                         sconcat("\\left(", tex1(base), "\\right)^", pow)
                   else
                         sconcat(tex1(first(base)), "^{*", pow, "}"))))$

Note i also changed \star to plain * in my workaround.

rtoy commented 2 months ago

Imported from SourceForge on 2024-07-08 21:25:21 Created by robert_dodier on 2023-03-07 17:18:37 Original: https://sourceforge.net/p/maxima/bugs/4112/#59f6


rtoy commented 2 months ago

Imported from SourceForge on 2024-07-08 21:25:24 Created by robert_dodier on 2023-03-07 17:18:38 Original: https://sourceforge.net/p/maxima/bugs/4112/#eb9c


Thanks for this bug report. I've reworked the TeX output for conjugate so that it interacts correctly with exponents. See commit [ d188f74 ]. Closing this bug as fixed.

The TeX output system infers whether parentheses are needed from the so-called left and right binding powers (i.e., operator precedence). In this case I was able to convince tex to output parentheses by reducing the binding powers (i.e., lowering the precedence).

rtoy commented 2 months ago

Imported from SourceForge on 2024-07-08 21:25:28 Created by matan-bebop on 2023-03-13 19:57:45 Original: https://sourceforge.net/p/maxima/bugs/4112/#eb9c/9976


Thanks for your fix! Your solution is rather elegant, but I should say it's not ideal, at least to my taste. declare(a, complex)$ tex(conjugate(a^2)) gives $$\left(a^{\ast}\right)^2$$, while I would prefer $$a^{\ast2}$$. The latter is what my re-definition of "^" achieves.