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

Pairs of numbers incorrectly concatenated with cdot = false #304

Open
kapple19 opened this issue Aug 10, 2024 · 4 comments
Open

Pairs of numbers incorrectly concatenated with cdot = false #304

kapple19 opened this issue Aug 10, 2024 · 4 comments
Labels

Comments

@kapple19
Copy link

I initially opened this issue in Symbolics.jl since I superficially noticed this issue occurs with @variables and not Exprs or Strings fed to latexify.

image

image

Basically the @latexrecipes defined in Symbolics.jl/src/latexify_recipes.jl all set cdot --> false, which avoids placing \cdots everywhere.

There isn't a simple solution to this, but I'm happy to look into the challenge of designing an algorithm and non-breaking (additive) API that places \cdots in some nicely disambiguating places.

@gustaphe
Copy link
Collaborator

Interesting.

To simplify the problem description a little:

julia> @latexify 2x + 2*3 cdot=false
L"$2 x + 2 3$"
$$2 x + 2 3$$

should be

"$2 x + 2 \cdot 3$"
$$2 x + 2 \cdot 3$$

Since the current representation is incorrect, this is a bug. I don't think the solution has to be technically non-breaking.
If you can think of a good heuristic to solve this, I'd be happy to merge it.

@ChrisRackauckas
Copy link
Contributor

Why not use parenthesis?

@gustaphe gustaphe changed the title Displayed math shows numbers incorrectly related Pairs of numbers incorrectly concatenated with cdot = false Aug 11, 2024
@gustaphe
Copy link
Collaborator

gustaphe commented Aug 11, 2024

Why not use parenthesis?

For one thing I think that's an even harder algorithm to implement.
And it's my understanding cdot=false is used for aesthetic reasons, and then $3(2)$ is no better than $3 \cdot 2$ in my opinion.

I'm toying with one idea where a step of str = replace(str, r" \\cdot (?![0-9])"=>" ") is added to multiplication in latexoperation if cdot is false.

julia> @latexify 2x+2*(3)+2*3^4+3^4*2+x^4*x cdot=false
L"$2 x + 2 \cdot 3 + 2 \cdot 3^{4} + 3^{4} \cdot 2 + x^{4} x$"
$$2 x + 2 \cdot 3 + 2 \cdot 3^{4} + 3^{4} \cdot 2 + x^{4} x$$

This catches many of these things, but it's not perfect. For instance, I would expect $(3u"cm")*x to be $3 \mathrm{cm} \cdot x$ rather than $3 \mathrm{cm} x$. But that would basically require a separate vector like prevop, and that system is difficult enough.

@gustaphe gustaphe added the bug label Aug 11, 2024
@kapple19
Copy link
Author

kapple19 commented Aug 11, 2024

It'll also be a battle of preference between users. Right now we have set_default (iirc) with the option to set cdot = true or false, and my idealistic mind is imagining some more specific options that users can tweak such as whether to represent multiplication as a space, a dot, parentheses (very tricky as noted above) or even other things, maybe user-inputable, e.g. \times.

On tip of that, I'm (again idealistically) imagining users can specify which multiplication presentation to use for different contexts, e.g. between two numbers, between two symbols, between a number-then-symbol, or between a symbol-then-number (I haven't checked if Latexify aleays places numbers first), or even as your example, number-with-units-then-symbol.

And yes, such a change doesn't need to be API breaking, and my (again idealistic) mind might be motivated enough to come up with an algorithm for this, or at least a simpler improvement. I'll try out some things and give it a shot. Also a nice challenge yet introductory experience to more complicated contributions into the Julia ecosystem. That said someone else might have a better solution.

Edit: My brain misprocessed the double-negative in your statement about breaking changes. I'll see what I can do with the current API and whether we'll need a breaking change or not - I imagine we will need to break things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants