Comments (19)
@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.
@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.
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 < x <= 5
.
from latexify_py.
Could I get assigned to this issue? I would love to contribute to this repo!
from latexify_py.
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.
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.
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.
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
from latexify_py.
That makes a lot of sense! Thanks for the clarification
from latexify_py.
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.
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.
Are there any other cases that would be relevant for latex? If you could provide examples that would be extremely helpful!
from latexify_py.
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.
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
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
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
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.
@odashi Hi, we cannot get the match statement in the jupyter notebook running. For now, we are getting this error:
This is what we did:
- Cloned the repo
- Ran the jupyter notebook
Is there any step we missed? Thanks ahead!
from latexify_py.
@Yuqi07 Not sure how you installed the library. Could you provide the complete step you tried?
from latexify_py.
@Yuqi07 Not sure how you installed the library. Could you provide the complete step you tried?
- pip install latexify-py
- jupyter notebook
I think these were the only steps I ran. Did I miss anything? Thxx!
from latexify_py.
pip install from PyPI doesn't work for development. You need to install the main branch directly: pip install -e '.[dev]'
from latexify_py.
Thanks! Now it works!
from latexify_py.
Related Issues (20)
- Custom multiplication behavior (option to use \cdot everywhere) HOT 1
- Should `def(x): func(x)` generate `\func x` or `\func \mathopen{}\left( x \mathclose{}\right)`? HOT 2
- Fine-grained control over function name replacements
- Designing "plugin" interface HOT 3
- Use `latex.py` for to standardize codegen HOT 2
- Feedback From a User HOT 14
- Please add support for Python >3.11 HOT 2
- IPython extension to automatically use conversions on displayed objects HOT 1
- Better Identifier For Multi Index and RHS HOT 4
- Can you sub in values for show work? HOT 1
- Сonverting expressions or strings to latex format HOT 5
- Release New Version HOT 6
- Support for sqrt-like nth-roots when rendering x**(1/p)? HOT 2
- Support for log1p and expm1? HOT 4
- `if-elif` statements break if there's no `else` HOT 1
- Typo in \mathopen HOT 3
- Counterintuitive (wrong?) parenthesis when combining exp() and powers HOT 16
- Function docstring and reduce_assignments enabled does not play nice HOT 2
- Include .tex output examples in latexify_py/examples/examples.ipynb HOT 3
- math.pow not working properly on google colab HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from latexify_py.