roniemartinez / latex2mathml

Pure Python library for LaTeX to MathML conversion
MIT License
183 stars 25 forks source link

Escaping of “<”, “>” kept in XML #45

Closed 06180339 closed 5 years ago

06180339 commented 5 years ago

Edit: I have a more comprehensive proposal now; please see the next commit https://github.com/roniemartinez/latex2mathml/commit/ecb1a59ffc4a697aa404bbdb0e764d24681d02fc


I don’t fully understand the escaping / unescaping behaviour of the function convert, as it is now:

With and without this change:

convert('1 < 2') yields <math><mrow><mn>2</mn><mi><</mi><mn>4</mn></mrow></math>, which is not well-formed XML. I cannot escape now, because the string already contains the XML tags. I also cannot escape the latex before, because convert('1 &lt; 2') leads to an undesired result.

With this change:

convert('1 < 2', unescaping = False) yields <math><mrow><mn>2</mn><mi>&lt;</mi><mn>4</mn></mrow></math>, which is well-formed XML.

So, the proposed change would provide the possibility of keeping “<”, “>” escaped within the resulting XML.

Maybe the old behaviour is not even needed. The new code perhaps could be then:

def _convert(tree):
    xml_string = eTree.tostring(tree)
    try:
        return xml_string.decode('utf-8')
    except AttributeError:
        return xml_string

without the parameter unescaping anywhere.

If this is just a misunderstanding, that is not intended.

roniemartinez commented 5 years ago

Thanks @06180339

Could you include unit tests too?

06180339 commented 5 years ago

Thank you for this library (latex2mathml)! Sorry for the double-commit; the first one can and probably should be superseded with https://github.com/roniemartinez/latex2mathml/commit/ecb1a59ffc4a697aa404bbdb0e764d24681d02fc

“Could you include unit tests too?”

Yes, thanks for the hint. It will just take some time, sorry.

roniemartinez commented 5 years ago

Thanks @06180339 ,

I'll check on it tonight. (sorry we are on different timezones)

06180339 commented 5 years ago

Thank you, roniemartinez. There’s no hurry for me. Maybe the proposed solution is possible, maybe not.

roniemartinez commented 2 years ago

@all-contributors please add @06180339 for code

allcontributors[bot] commented 2 years ago

@roniemartinez

I've put up a pull request to add @06180339! :tada: