Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latex bug with minus and Mul #9202

Closed
proy87 opened this issue Mar 25, 2015 · 12 comments
Closed

Latex bug with minus and Mul #9202

proy87 opened this issue Mar 25, 2015 · 12 comments
Labels
Easy to Fix This is a good issue for new contributors. Feel free to work on this if no one else has already. printing

Comments

@proy87
Copy link

proy87 commented Mar 25, 2015

Latex printer can't handle expressions like -(x+5).

from sympy.printing.latex import latex
from sympy.abc import x
from sympy import Mul
expr = Mul(-1,x+5, evaluate=False)
latex(expr) # outputs -x+5 instead of -(x+5)

I looked int code and found

        if denom is S.One:
            # use the original expression here, since fraction() may have
            # altered it when producing numer and denom
            tex += convert(expr)

convert returns simple addition (since minus was previously taken and now x+5 is_Add), then minus is simply prepended.

@proy87 proy87 changed the title Latex bug Latex bug with minus and Mul Mar 25, 2015
@moorepants moorepants added Easy to Fix This is a good issue for new contributors. Feel free to work on this if no one else has already. printing Latex labels Mar 25, 2015
@Sumith1896
Copy link
Member

What answer is expected?
Is it -(x + 5) or - ( x + 5 ) or something else?

@debugger22
Copy link
Member

See this: latex(expr) # outputs -x+5 instead of -(x+5)

@Sumith1896
Copy link
Member

Before fix it's printing - x + 5, I just wanted to confirm the exact output required(proper spacing)?

@debugger22
Copy link
Member

I think it should be - x - 5 because autosimplification will -(x + 5) will simplify it.

@Sumith1896
Copy link
Member

But evaluate is set to False.

@debugger22
Copy link
Member

Oh sorry! Then I think - (x + 5) should be fine.

@debugger22
Copy link
Member

Actually I'm not sure because pretty printer gives this -(x + 5)

@proy87
Copy link
Author

proy87 commented Mar 29, 2015

Answer should be -(x+5). Printer should print expression, not evaluate and print.

@debugger22
Copy link
Member

@simamura87 the confusion is about the space after -.

@proy87
Copy link
Author

proy87 commented Mar 29, 2015

Latex ignores implicit whitespaces, isn't it?

@jcrist jcrist removed the Latex label Apr 17, 2015
wumadeline added a commit to wumadeline/sympy that referenced this issue Apr 27, 2015
wumadeline added a commit to wumadeline/sympy that referenced this issue Apr 27, 2015
@tokencolour
Copy link
Contributor

Why is this issue still open?

@gxyd
Copy link
Contributor

gxyd commented Nov 5, 2017

Closing. Fixed by #10889.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Easy to Fix This is a good issue for new contributors. Feel free to work on this if no one else has already. printing
Projects
None yet
Development

No branches or pull requests

7 participants