Code Monkey home page Code Monkey logo

Comments (4)

certik avatar certik commented on September 23, 2024

Can you summarize the differences between the two math_dollar implementations?

from theoretical-physics.

asmeurer avatar asmeurer commented on September 23, 2024

sphinx-math-dollar is more rigorous about not parsing dollars that shouldn't be parsed. For instance, if you have a doctest like

>>> print("$x$")
$x$

then sphinx-math-dollar won't parse it, because it ignores docstrings (this was important for SymPy because of the latex() docstring). It also ignores things in code (double backticks) and other things like that. The way it works is that it uses an AST transformer on the docutils tree, rather than replacing stuff in the raw rst text. So it can tell the difference between dollars in a paragraph and dollars in a code block. The debug environment variable I mentioned will print out any instances of dollars that are not parsed as math, so you can see if there are any.

I also improved the regular expression a little bit to handle some cases the old one wasn't handling correctly. It now no longer incorrectly parses something like

$ cd doc
$ make html

as math, because it ignores it if there is a space after the dollar. There were also some incorrect parsings of escaped dollars, like $13\$ + 14\$$ (I doubt you have any escaped dollars here, but it's worth mentioning).

Eventually I want to add support for double dollars for display math, so you don't have to use .. math:: anymore. I just need to modify the regular expression to parse them, or figure out some better way to lex dollars. If you have any suggestions on a good way to write a simple lexer in Python that can handle backslash escapes, let me know. Currently the regular expression with backtracking to handle the escapes is a bit unwieldy, and it will only get worse if we add double dollar support.

And finally, a lot of other people have shown interest in sphinx-math-dollar (I got a ton of feedback on Twitter). So hopefully it should get some use, and be well maintained. I put it under the sympy user on GitHub rather than my personal user so that we can maintain it as a community.

from theoretical-physics.

asmeurer avatar asmeurer commented on September 23, 2024

Also your extension doesn't work with docstrings, only stuff in rst files.

from theoretical-physics.

certik avatar certik commented on September 23, 2024

I see, that sounds nice. I'll try it out.

from theoretical-physics.

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.