blaisewang / img2latex-mathpix

Mathpix has changed their billing policy and no longer has free monthly API requests. This repo is now archived and will not receive any updates for the foreseeable future.
Apache License 2.0
1.39k stars 209 forks source link

[Bug] Incorrect MathML export for multiple entries at once #105

Closed jhulala closed 2 years ago

jhulala commented 3 years ago

When an image contains multiple lines/entries, the exported MathML code is incorrect

To reproduce, follow these steps:

(1) Use this image: math_example

(2) The exported MathML code is as follows:

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mfrac>
    <mrow>
      <mn>2</mn>
      <mo stretchy="false">(</mo>
      <mn>1</mn>
      <mo>+</mo>
      <mi>sin</mi>
      <mo data-mjx-texclass="NONE">⁡</mo>
      <mo stretchy="false">(</mo>
      <mi>x</mi>
      <mo stretchy="false">)</mo>
      <mo stretchy="false">)</mo>
    </mrow>
    <mrow>
      <mi>cos</mi>
      <mo data-mjx-texclass="NONE">⁡</mo>
      <mo stretchy="false">(</mo>
      <mi>x</mi>
      <mo stretchy="false">)</mo>
      <mo stretchy="false">(</mo>
      <mi>sin</mi>
      <mo data-mjx-texclass="NONE">⁡</mo>
      <mo stretchy="false">(</mo>
      <mi>x</mi>
      <mo stretchy="false">)</mo>
      <mo>+</mo>
      <mn>1</mn>
      <mo stretchy="false">)</mo>
    </mrow>
  </mfrac>
</math>

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mfrac>
    <mn>2</mn>
    <mrow>
      <mi>cos</mi>
      <mo data-mjx-texclass="NONE">⁡</mo>
      <mo stretchy="false">(</mo>
      <mi>x</mi>
      <mo stretchy="false">)</mo>
    </mrow>
  </mfrac>
</math>

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mn>2</mn>
  <mi>sec</mi>
  <mo data-mjx-texclass="NONE">⁡</mo>
  <mo stretchy="false">(</mo>
  <mi>x</mi>
  <mo stretchy="false">)</mo>
</math>

(3) The expected result should be similar to this:

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mfrac>
    <mrow>
      <mn>2</mn>
      <mo stretchy="false">(</mo>
      <mn>1</mn>
      <mo>+</mo>
      <mi>sin</mi>
      <mo data-mjx-texclass="NONE">⁡</mo>
      <mo stretchy="false">(</mo>
      <mi>x</mi>
      <mo stretchy="false">)</mo>
      <mo stretchy="false">)</mo>
    </mrow>
    <mrow>
      <mi>cos</mi>
      <mo data-mjx-texclass="NONE">⁡</mo>
      <mo stretchy="false">(</mo>
      <mi>x</mi>
      <mo stretchy="false">)</mo>
      <mo stretchy="false">(</mo>
      <mi>sin</mi>
      <mo data-mjx-texclass="NONE">⁡</mo>
      <mo stretchy="false">(</mo>
      <mi>x</mi>
      <mo stretchy="false">)</mo>
      <mo>+</mo>
      <mn>1</mn>
      <mo stretchy="false">)</mo>
    </mrow>
  </mfrac>
  <mfrac>
    <mn>2</mn>
    <mrow>
      <mi>cos</mi>
      <mo data-mjx-texclass="NONE">⁡</mo>
      <mo stretchy="false">(</mo>
      <mi>x</mi>
      <mo stretchy="false">)</mo>
    </mrow>
  </mfrac>
  <mn>2</mn>
  <mi>sec</mi>
  <mo data-mjx-texclass="NONE">⁡</mo>
  <mo stretchy="false">(</mo>
  <mi>x</mi>
  <mo stretchy="false">)</mo>
</math>

The problem is that the export contains the tag <math xmlns="http://www.w3.org/1998/Math/MathML"> multiple times, which prevents a proper pasting into Microsoft Word document. Adding an extra space between independent parts would be also beneficial, so the formulas are not squeezed into one line/part.

I used the latest and up-to-date version of Windows 10

github-actions[bot] commented 3 years ago

[Auto response] Looks like this is your first issue. I will look into it as soon as possible.

blaisewang commented 3 years ago

The result is returned by the Mathpix API which contains multiple MathML equations. This app simply concatenates all equations together.

jhulala commented 3 years ago

@blaisewang, I understand that Mathpix API returns multiple MathML equations, but grouping them together is not a solution, because users won't be able to paste them into Microsoft Word. You perhaps haven't tried it, so you don't know how useless it is. A simple one-line regex command (regular expression substitution) would fix this very easily. See https://regexr.com/5mpo7 for the solution.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 10 days