Giter VIP home page Giter VIP logo

py_asciimath's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

py_asciimath's Issues

Also about LaTex translate to AsciiMath

py_asciimath.exe "\[a=60{}^\circ\ ]" from latex to asciimath
py_asciimath.exe "\[a=45{}^\circ \]" from latex to asciimath
py_asciimath.exe "\[\bar{N}t=m{{v}{0}}\sin \alpha \]" from latex to asciimath
py_asciimath.exe "\[\bar{f}t=\mu \bar{N}t=\mu m{{v}
{0}}\sin \alpha \approx 0.6m{{v}{0}}\]" from latex to asciimath
py_asciimath.exe "\[\alpha ={{45}^{{}^\circ }},\mu =0.5\]" from latex to asciimath
py_asciimath.exe "\[\bar{N}t=m{{v}
{0}}\sin \alpha \]" from latex to asciimath
py_asciimath.exe "\[\bar{f}t=\mu m{{v}{0}}\sin \alpha =m{{v}{0}}\cos \alpha -mv\]" from latex to asciimath
py_asciimath.exe "\[\alpha ={{30}^{{}^\circ }}\]" from latex to asciimath
looks like they dont work.

TeX to ASCIImath \frac error

When running this code:

from py_asciimath.translator.translator import (
    ASCIIMath2MathML,
    ASCIIMath2Tex,
    MathML2Tex,
    Tex2ASCIIMath
)

latex_input = r"\frac{3}{2^4}"
tex2asciimath = Tex2ASCIIMath(log=False, inplace=True)
parsed = tex2asciimath.translate(latex_input, from_file=False, pprint=False,)
print(parsed)

prints this:

frac(3)((2)^(4))

when it's meant to print:

(3)/(2^4)

Is there something wrong with how the LaTeX equation is being input or is it a bug?

lxml.etree.XMLSyntaxError: failed to load external entity "NULL", line 1, column 128

I installed py_asciimath, update lxml for my python-3.8.1.amd64 on Windows 10 64 bits
then I try to run the code bellowing, which is actually the code on https://github.com/belerico/py_asciimath, but I get

ASCIIMath to MathML
WARNING:root:No connection available...
WARNING:root:No XML declaration with 'encoding' attribute set: default encoding to None
WARNING:root:The XML encoding is None: default to UTF-8
WARNING:root:No DTD declaration found: set to local mathml2 DTD
Traceback (most recent call last):
  File "a.py", line 12, in <module>
    parsed = asciimath2mathml.translate(
  File "E:\_PRG_BAK\py_asciimath-master\py_asciimath\translator\translator.py", line 336, in translate
    return super(ASCIIMath2MathML, self).translate(
  File "E:\_PRG_BAK\py_asciimath-master\py_asciimath\translator\translator.py", line 136, in translate
    return super(LarkTranslator, self).translate(
  File "E:\_PRG_BAK\py_asciimath-master\py_asciimath\translator\translator.py", line 65, in translate
    exp = self._translate(exp, **kwargs)
  File "E:\_PRG_BAK\py_asciimath-master\py_asciimath\translator\translator.py", line 266, in _translate
    parsed = MathMLParser.parse(
  File "E:\_PRG_BAK\py_asciimath-master\py_asciimath\parser\parser.py", line 297, in parse
    return lxml.etree.fromstring(xml, mathml_parser)
  File "src\lxml\etree.pyx", line 3236, in lxml.etree.fromstring
  File "src\lxml\parser.pxi", line 1876, in lxml.etree._parseMemoryDocument
  File "src\lxml\parser.pxi", line 1764, in lxml.etree._parseDoc
  File "src\lxml\parser.pxi", line 1127, in lxml.etree._BaseParser._parseDoc
  File "src\lxml\parser.pxi", line 601, in lxml.etree._ParserContext._handleParseResultDoc
  File "src\lxml\parser.pxi", line 711, in lxml.etree._handleParseResult
  File "src\lxml\parser.pxi", line 640, in lxml.etree._raiseParseError
  File "<string>", line 1
lxml.etree.XMLSyntaxError: failed to load external entity "NULL", line 1, column 128

the code is

from py_asciimath.translator.translator import (
    ASCIIMath2MathML,
    ASCIIMath2Tex,
    MathML2Tex,
    Tex2ASCIIMath
)


if __name__ == "__main__":
    print("ASCIIMath to MathML")
    asciimath2mathml = ASCIIMath2MathML(log=False, inplace=True)
    parsed = asciimath2mathml.translate(
        r"e^x > 0 forall x in RR",
        displaystyle=True,
        dtd="mathml2",
        dtd_validation=True,
        from_file=False,
        output="string",
        network=True,
        pprint=False,
        to_file=None,
        xml_declaration=True,
        xml_pprint=True,
    )

    print(parsed, "\n\nMathML to LaTeX")
    mathml2tex = MathML2Tex()
    parsed = mathml2tex.translate(parsed, network=False, from_file=False,)

    print(parsed, "\n\nASCIIMath to LaTeX")
    asciimath2tex = ASCIIMath2Tex(log=False, inplace=True)
    parsed = asciimath2tex.translate(
        r"e^x > 0 forall x in RR",
        displaystyle=True,
        from_file=False,
        pprint=False,
    )

    print(parsed, "\n\nLaTeX to ASCIIMath")
    tex2asciimath = Tex2ASCIIMath(log=False, inplace=True)
    parsed = tex2asciimath.translate(
        parsed,
        from_file=False,
        pprint=False,
    )
    print(parsed)

logging.basicConfig might be in the wrong place

I think it's not proper to config log level DEBUG inside many inner modules:

logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.DEBUG)

It makes this package unusable in interactive mode, unless the user understand how to deal with the logging stuff.

My suggestion is to put the logging.basicConfig only inside your entry point scripts / functions.

ASCIIMath2Tex frac error

when running unit test

parser = ASCIIMath2Tex(log=False)
s = parser.translate("f(x)/g(x)")
self.assertEqual(s,r"$\frac{f(x)}{g(x)}$")

it outputs

======================================================================
FAIL: test_asciimath2tex_ok_10 (__main__.TestASCIIMath2Tex.test_asciimath2tex_ok_10)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "e:\Folder\py_asciimath\tests\test_ASCIIMath2Tex.py", line 119, in test_asciimath2tex_ok_10
    self.assertEqual(s,r"$\frac{f(x)}{g(x)}$")
AssertionError: '$f \\frac{x}{g} \\left(x\\right)$' != '$\\frac{f(x)}{g(x)}$'
- $f \frac{x}{g} \left(x\right)$
+ $\frac{f(x)}{g(x)}$

Mathjax, who renders asciimath formula, will treat $f$ and $g$ as a function symbol like $\sin$, will render f(x)/g(x) to the view $\frac{f(x)}{g(x)}$. I hope it can be fixed.

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.