roniemartinez / latex2mathml

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

Missing `\pmod` command #229

Closed leingang closed 2 years ago

leingang commented 3 years ago

Hello, and thank you for writing this package! It's been serving me well up to now.

The convert function doesn't recognize the \pmod command:

>>> latex2mathml.converter.convert("7 \equiv 2 \pmod 5")
'<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>7</mn><mo>&#x02261;</mo><mn>2</mn><mi>\\pmod</mi><mn>5</mn></mrow></math>'

Notice that \pmod is just passed through to the MathML. In LaTeX, the command puts parentheses around “mod n”, where n is the argument. So the MathML output should be closer to this (taken from another converter, edited to match the latex2mathml output, and pretty-printed for human readers):

<math title="" xmlns="http://www.w3.org/1998/Math/MathML" display="inline">
  <mrow>
    <mn>7</mn>
    <mo>&#x02261;</mo>
    <mn>2</mn>
    <mspace width="1em"></mspace>
    <mo stretchy="false">(</mo>
      <mi>mod</mi><mspace width="0.333em"></mspace><mn>5</mn>
    <mo stretchy="false">)</mo>
  </mrow>
</math>

I'd be willing to contribute a PR if you tell me where in the repo to focus. I gather I need to add an element to commands.COMMANDS_WITH_ONE_PARAMETER, but not quite sure how it gets implemented.

roniemartinez commented 2 years ago

@all-contributors please add @leingang for bug

allcontributors[bot] commented 2 years ago

@roniemartinez

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