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

Parsing the content of math environments? #106

Closed
jonathan-laurent opened this issue Jul 26, 2020 · 4 comments · Fixed by #108
Closed

Parsing the content of math environments? #106

jonathan-laurent opened this issue Jul 26, 2020 · 4 comments · Fixed by #108

Comments

@jonathan-laurent
Copy link

Currently, it seems to me that TexSoup treats the content of a math environment ($...$, (...) or [...]) like a single token.
Is there any way to get a structured representation of this content too? I was thinking of getting a string representation of the inside of $...$ and then calling TexSoup on it recursively but I am not sure this would work.

To be even more concrete, here is an example of a task I am interested in performing:

  • Find all instances of \infer{A}{B} within a math environment and replace it by \infer{B}{A} where A and B could be arbitrary Latex code.

Could one use TexSoup to do this?

@alvinwan
Copy link
Owner

alvinwan commented Aug 1, 2020

@jonathan-laurent Thanks for creating this issue! I've just made a change that will allow this. The linked PR will have a passing test for this math env replacement, reproduced below:

    soup = TexSoup(r'$$\infer{A}{B}\infer{C}{D}$$')
    assert soup.infer is not None, repr(soup.expr)
    for infer in soup.find_all('infer'):
        infer.args = infer.args[::-1]
    assert str(soup) == r'$$\infer{B}{A}\infer{D}{C}$$'

@qwenger
Copy link

qwenger commented Aug 2, 2020

Wow, that's exactly the issue I was searching for.

Thank you very much @alvinwan for this really handy library! Would you consider pushing a release to PyPI for this new math parsing feature?

@jonathan-laurent
Copy link
Author

I just tried it and it works great. Thanks!

alvinwan added a commit that referenced this issue Aug 3, 2020
alvinwan added a commit that referenced this issue Aug 3, 2020
* fixes #106 version bump request

* finished basic guides (added modification)

* added crazy opt arg test from plastex/plastex#129
@alvinwan
Copy link
Owner

alvinwan commented Aug 3, 2020

@qwenger yup, just pushed! https://pypi.org/project/TexSoup/0.3.1/

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

Successfully merging a pull request may close this issue.

3 participants