Git Product home page Git Product logo

Comments (19)

odashi avatar odashi commented on April 27, 2024 1

@erica-w-fu Hi, feel free to work on this!
Since the overall syntax around Match is very huge, I'd like to decompose it to small developments (pull requests) mainly for ease of reviewing.

from latexify_py.

odashi avatar odashi commented on April 27, 2024 1

@erica-w-fu I will add some documentation. For now you can install the development version as follows:

cd /path/to/latexify_py
python -m venv venv  # Create a virtual environment
python -m pip install -e '.[dev]' # Install latexify as the editable mode with some libraries

jupyter notebook is also installed by the command above.

from latexify_py.

odashi avatar odashi commented on April 27, 2024 1

Thanks! if each case doesn't require additional identifiers (capture), it would be good to be implemented. I guess they could be proposed by separate pull requests (to keep minimality of the change).

MatchOr

It looks we need to use boolean operation: x = 0 \lor x = 1. Multiple ifs for a single expression look weird IMO.

Would we want to combine these ranges

The library has to keep the original expression unless users specified appropriate options. In this case, if the user wanted to get $0 &lt; x \leq 5$, the user basically needs to write 0 < x <= 5.

from latexify_py.

erica-w-fu avatar erica-w-fu commented on April 27, 2024

Could I get assigned to this issue? I would love to contribute to this repo!

from latexify_py.

erica-w-fu avatar erica-w-fu commented on April 27, 2024

Could I get some clarification on what is expected? Are we trying to convert match statements to latex? What does support mean exactly?

from latexify_py.

odashi avatar odashi commented on April 27, 2024

Basically implementing some codegen rules in function_codegen.py is all you need.

As for "small development", you can start to implement only a specific portion in the whole syntax (e.g., I think supporting only MatchValue is the easiest one).
For all other cases, we should raise LatexifyNotSupportedError, which marks "not supported, but we'll support it in the future". For example:

class FunctionCodegen(NodeVisitor):
    ...
    def visit_Match(self, node: ast.Match) -> str:
        if isinstance(node.pattern, ast.MatchValue):
            return ...something...
        
        raise exceptions.LatexifyNotSupportedError("Unsupported match syntax.")

from latexify_py.

odashi avatar odashi commented on April 27, 2024

I think the whole match case can't be supported in latexify.function because there are capture clauses that there aren't any corresponding syntax in math. It would be better to support only syntaxes with:

  • Constants
  • sequence/dict with only constants

from latexify_py.

odashi avatar odashi commented on April 27, 2024

The resulting LaTeX could be expressed semilarly to that of the if clause:

match x:
    case 0:
        return 1
    case _:
        return math.sin(x)/x

$$\left\{ \begin{array}{ll} 1, & \mathrm{if} \ x = 0 \\ \frac{\sin(x)}{x}, & \mathrm{otherwise} \end{array} \right.$$

from latexify_py.

erica-w-fu avatar erica-w-fu commented on April 27, 2024

That makes a lot of sense! Thanks for the clarification

from latexify_py.

erica-w-fu avatar erica-w-fu commented on April 27, 2024

How can we build the project for development? Are there any detailed docs that explain how to build and test latexify/our implementation?

from latexify_py.

erica-w-fu avatar erica-w-fu commented on April 27, 2024

Thanks! I was able to run all of the tests. Are there any build tools and commands that you use to test within jupyter notebook?

from latexify_py.

erica-w-fu avatar erica-w-fu commented on April 27, 2024

Are there any other cases that would be relevant for latex? If you could provide examples that would be extremely helpful!

from latexify_py.

odashi avatar odashi commented on April 27, 2024

Are there any build tools and commands that you use to test within jupyter notebook?

This library doesn't run tests within jupyter. If you need to run tests on jupyter, you need either (1) run CI libraries programmatically, or (2) run shell command from the notebook. If you know some other tools to run tests on jupyter, it is still fine to use it on your local environment.

Are there any other cases that would be relevant for latex?

I'm not sure for now. If you have some ideas, please share on this thread.

from latexify_py.

erica-w-fu avatar erica-w-fu commented on April 27, 2024

Here are two ideas for things to support:

1. MatchOr

In conditional equations, multiple conditions can lead to one of the cases, thus we should implement MatchOr to support this.

Code example

match x:
  case 0 | 1:
    1
  case _:
    2

Latex example
Screen Shot 2022-12-06 at 10 39 05 PM

2. MatchAs (nonempty/not the wildcard)

In conditional equations, ranges are often used to define certain cases, thus we should implement when MatchAs is not empty so the guard attribute can be evaluated and comparisons through <, >, <=, >= can be made

Code example

match x:
  case x if x > 0:
    1
  case _:
    2

Latex example
Screen Shot 2022-12-06 at 10 47 08 PM

For this case, we might also want to implement a fixed range like this

Code example

match x:
  case x if (x > 0 and x <= 5):
    1
  case _:
    2

Latex example
Screen Shot 2022-12-06 at 10 54 01 PM

Would we want to combine these ranges (so instead of x>0 and x<=5 we have 0<x<=5? That would require more testing but could be a valuable feature.

from latexify_py.

Yuqi07 avatar Yuqi07 commented on April 27, 2024

@odashi Hi, we cannot get the match statement in the jupyter notebook running. For now, we are getting this error:

Screen Shot 2022-12-11 at 14 57 23

This is what we did:

  • Cloned the repo
  • Ran the jupyter notebook

Is there any step we missed? Thanks ahead!

from latexify_py.

odashi avatar odashi commented on April 27, 2024

@Yuqi07 Not sure how you installed the library. Could you provide the complete step you tried?

from latexify_py.

Yuqi07 avatar Yuqi07 commented on April 27, 2024

@Yuqi07 Not sure how you installed the library. Could you provide the complete step you tried?

  1. pip install latexify-py
  2. jupyter notebook

I think these were the only steps I ran. Did I miss anything? Thxx!

from latexify_py.

odashi avatar odashi commented on April 27, 2024

pip install from PyPI doesn't work for development. You need to install the main branch directly: pip install -e '.[dev]'

from latexify_py.

Yuqi07 avatar Yuqi07 commented on April 27, 2024

Thanks! Now it works!

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.