Coder Social home page Coder Social logo

Comments (13)

odashi avatar odashi commented on May 18, 2024 1

I think we eventually need more informative object than the raw string for expression codegen to implement this feature (and other stuff that rely on the LaTeX syntax rules). let me implement it later

from latexify_py.

odashi avatar odashi commented on May 18, 2024

Anyway, I will handle this issue today.

from latexify_py.

odashi avatar odashi commented on May 18, 2024

Anyway some simple heuristic can be applied without waiting for #82

from latexify_py.

odashi avatar odashi commented on May 18, 2024

Re-open this issue since it is actually not resolved yet.

from latexify_py.

ZibingZhang avatar ZibingZhang commented on May 18, 2024

Mind if I take a look into this?

from latexify_py.

odashi avatar odashi commented on May 18, 2024

Maybe it's good if we get a list of possible LHS-RHS pairs with/without the multiplication symbol, e.g.,

left right tex
3 x $3 x$
x y $x \cdot y$

from latexify_py.

ZibingZhang avatar ZibingZhang commented on May 18, 2024

I can't think of a case where we would want to remove the \cdot other than the case of constant * name.

left right tex why
3 x $3x$ basic multiplication with constant (should work with floats and complex)
x 3 $x \cdot 3$ should not reorder for user, if they want lack of \cdot, can change order themselves
two names $two \cdot names$ two variables should always have a \cdot
3 x * 4 * y $3x \cdot 4y$ should work in more complicated expression as well

from latexify_py.

odashi avatar odashi commented on May 18, 2024

Some complete examples:

numeric alphabet math word function bracket
numeric $2 \cdot 3$ $\color{red} 2 y$ $\color{red} 2 \beta$ $\color{red} 2 \mathrm{bar}$ $\color{red} 2 g(y)$ $\color{red} 2 (u + v)$
alphabet $x \cdot 3$ $\color{red} x y$ $\color{red} x \beta$ $x \cdot \mathrm{bar}$ $x \cdot g(y)$ $x \cdot (u + v)$
math $\alpha \cdot 3$ $\color{red} \alpha y$ $\color{red} \alpha \beta$ $\alpha \cdot \mathrm{bar}$ $\alpha \cdot g(y)$ $\alpha \cdot (u + v)$
word $\mathrm{foo} \cdot 3$ $\mathrm{foo} \cdot y$ $\mathrm{foo} \cdot \beta$ $\mathrm{foo} \cdot \mathrm{bar}$ $\mathrm{foo} \cdot g(y)$ $\mathrm{foo} \cdot (u + v)$
function $f(x) \cdot 3$ $f(x) \cdot y$ $f(x) \cdot \beta$ $f(x) \cdot \mathrm{bar}$ $f(x) \cdot g(y)$ $f(x) \cdot (u + v)$
bracket $(s + t) \cdot 3$ $\color{red} (s + t) y$ $\color{red} (s + t) \beta$ $\color{red} (s + t) \mathrm{bar}$ $\color{red} (s + t) g(y)$ $\color{red} (s + t) (u + v)$

In cases {alphabet,math,word}-{bracket} it would make some confusion between them and function calls if we removed \cdot.

EDIT(2023-10-16)

Added some consistent rules:

  1. Numeric should always keep the preceding \cdot.
  2. Functions should always keep the following \cdot due to some ambiguity (e.g., sin(x) * y -> $\sin xy$)
  3. Numeric and brackets can remove the following \cdot without ambiguity, except the next operand is numeric.

from latexify_py.

ZibingZhang avatar ZibingZhang commented on May 18, 2024

I think alphabet-alphabet would also cause confusion, because you could have a (arguably dumb) case like

def (x, y, xy):
    return xy

In general though when user sees $xy$ there's no easy way of telling if it's $x \cdot y$ or a single variable $xy$, so I think it we should keep the \cdot.

edit: I'm realizing that word is stylized differently than alphabet, so it should be clear that $\mathrm{xy}$ is different than $xy$.

from latexify_py.

odashi avatar odashi commented on May 18, 2024

I'm realizing that word is stylized differently than alphabet

Yes this is intended in #139, but maybe the result is somewhat confusing for some users.

from latexify_py.

ZibingZhang avatar ZibingZhang commented on May 18, 2024

Looking through the code this seems like we'll have to utilize information from expr codegen to figure out what nodes are wrapped in parens , as well as information from identifier replacer to differentiate between math vs. alphabet vs. word.

from latexify_py.

ZibingZhang avatar ZibingZhang commented on May 18, 2024

Another situation, if we have a * b @ x @ y, this should result in $ab \cdot xy$.

from latexify_py.

odashi avatar odashi commented on May 18, 2024

Another situation, if we have a * b @ x @ y, this should result in .

It looks $abxy$ is acceptable. $ab \cdot xy$ looks to represent (a*b)@(x@y), but:

  • Matrix multiplication is an associative operation: position of parenthesis is meaningless
  • We get the AST (((a*b)@x)@y) for this expression.

from latexify_py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.