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

Weird LaTeX representation of sin^2 x #2899

Open
nickkolok opened this issue Feb 16, 2023 · 5 comments
Open

Weird LaTeX representation of sin^2 x #2899

nickkolok opened this issue Feb 16, 2023 · 5 comments
Labels
Needs more information For issues that cannot be acted on without more information from the poster. question

Comments

@nickkolok
Copy link

Describe the bug
LaTeX representation of sin^2 x depends on the way how the squared sinus was got.

To Reproduce

math.parse('(sin(x))^2').toTex()
"{\\left(\\sin\\left( x\\right)\\right)}^{2}"

math.parse('sin(x)*sin(x)').toTex()
"\\sin\\left( x\\right)\\cdot\\sin\\left( x\\right)"

math.simplify(math.parse('sin(x)*sin(x)')).toTex()
"{\\sin\\left( x\\right)}^{2}"

math.simplify(math.parse('(sin(x))^2')).toTex()
"{\\sin\\left( x\\right)}^{2}"
@josdejong
Copy link
Owner

The difference is that in your first expression you have extra parenthesis (sin(x))^2. These are redundant but will be part of the output. Function simplify will remove those parenthesis. You can also pass options to toTex to specify whether you want optional parenthesis or not:

math.parse('(sin(x))^2').toTex()
"{\\left(\\sin\\left( x\\right)\\right)}^{2}"

math.parse('(sin(x))^2').toTex({ parenthesis: 'auto' }) // default is 'keep'
"{\\sin\\left( x\\right)}^{2}"

Documentation: https://mathjs.org/docs/expressions/customization.html#custom-html-latex-and-string-output

@gwhitney gwhitney added the Needs more information For issues that cannot be acted on without more information from the poster. label Oct 3, 2023
@gwhitney
Copy link
Collaborator

gwhitney commented Oct 3, 2023

But I think the original report needs some clarification: @nickkolok was your primary concern that the "usual" mathematical notation for the square of sin(x) would be rendered in TeX as \sin^2(x) rather than \sin(x)^2 ? Or are you ok with the latter notation, just concerned that the exact notation was depending on how you arrived at the "same" expression? (Note as Jos says, with respect to this second concern, mathjs is behaving as intended.)

@josdejong
Copy link
Owner

I'll close this issue now due to lack of response. Please reopen if needed.

@gwhitney
Copy link
Collaborator

I'd like to make a vote for leaving this open, because it is true that the usual way to write the square of sin x in mathematical notation is sin^2 x rather than the actually systematic (sin x)^2. If mathjs is striving to match mathematical practice (not sure if that's always the case) then it should detect this situation and convert to sin^2 x notation.

@josdejong
Copy link
Owner

Ok I'll reopen the issue.

So what we can improve here in toTex is basically remove parentheses of the left hand side of power and only then interpret it.

@josdejong josdejong reopened this Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs more information For issues that cannot be acted on without more information from the poster. question
Projects
None yet
Development

No branches or pull requests

3 participants