Menu

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

None
closed
nobody
3
2023-03-13
2023-03-05
No
(%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.

Discussion

  • Andrii Sokolov

    Andrii Sokolov - 2023-03-05

    Sorry, the workaround in the original bug report does not take into account the case when there is some expression in the power of conjugate(...). A workaround that works for that case is:

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

    Robert Dodier - 2023-03-07
    • status: open --> closed
     
  • Robert Dodier

    Robert Dodier - 2023-03-07

    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).

     
    • Andrii Sokolov

      Andrii Sokolov - 2023-03-13

      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.

       

Log in to post a comment.