Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alignment of equations in docx #2310

Closed
tsuikitho opened this issue Jul 18, 2015 · 6 comments
Closed

Alignment of equations in docx #2310

tsuikitho opened this issue Jul 18, 2015 · 6 comments

Comments

@tsuikitho
Copy link

Hello, I don't know whether this is a bug related to pandoc. Please help me.

I write a txt file as follows:

$$
\begin{align*}
ax^2+bx+c &= 0\\
x &= \frac{-b\pm\sqrt{b^2-4ac}}{2a}
\end{align*}
$$

Save it as test.txt.
then convert the file to docx by pandoc (1.15.0.6):

pandoc -s test.txt -o test.docx

The equations can be displayed, but cannot be aligned correctly, see the following screen capture:
convertedfrompandoc

I am using word 2013 in windows 8.1.
The equations should be aligned with the "=" sign. But It seems that word treats the equations as a matrix with 4 entries.

When I convet the same latex code to mml in formula sheet (http://formulasheet.com/) and paste the mml code obtained into word, the equation can be displayed and aligned correctly:
pastemml

For your reference, here is the mml code

<math xmlns="http://www.w3.org/1998/Math/MathML">
<mtable>
<mtr><mtd>
<mrow><mi>a</mi><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><mi>b</mi><mi>x</mi><mo>+</mo><mi>c</mi><maligngroup/><maligngroup/><mo>=</mo><mn>0</mn></mrow></mtd></mtr>
<mtr><mtd>
<mrow><mi>x</mi><maligngroup/><maligngroup/><mo>=</mo><mfrac><mrow><mo>-</mo><mi>b</mi><mo>&#xb1;</mo><msqrt><msup><mi>b</mi><mn>2</mn></msup><mo>-</mo><mn>4</mn><mi>a</mi><mi>c</mi></msqrt></mrow><mrow><mn>2</mn><mi>a</mi></mrow></mfrac></mrow></mtd></mtr>
<mtr><mtd>
<mrow/></mtd></mtr>
</mtable>
</math>

Is this an issue related to pandoc? How to solve it? Thank you very much.

@jgm
Copy link
Owner

jgm commented Jul 21, 2015

Can you send a docx file with the correct equation
(which you produced by pasting the mml code)? I'd
like to look at how Word lays it out.

+++ tsuikitho [Jul 18 15 07:21 ]:

Hello, I don't know whether this is a bug related to pandoc. Please
help me.

I write a txt file as follows:
$$
\begin{align_}
ax^2+bx+c &= 0
x &= \frac{-b\pm\sqrt{b^2-4ac}}{2a}
\end{align_}
$$

Save it as test.txt.
then convert the file to docx by pandoc (1.15.0.6):
pandoc -s test.txt -o test.docx

The equations can be displayed, but cannot be aligned correctly, see
the following screen capture:
[1]convertedfrompandoc

I am using word 2013 in windows 8.1.
The equations should be aligned with the "=" sign. But It seems that
word treats the equations as a matrix with 4 entries.

When I convet the same latex code to mml in formula sheet
([2]http://formulasheet.com/) and paste the mml code obtained into
word, the equation can be displayed and aligned correctly:
[3]pastemml

For your reference, here is the mml code

ax2+bx< mo>+c=0 x=-b±b2-4ac2a

Is this an issue related to pandoc? How to solve it? Thank you very
much.


Reply to this email directly or [4]view it on GitHub.

References

  1. https://cloud.githubusercontent.com/assets/13394147/8761863/b7c18512-2d99-11e5-805d-bcccc9c82fc2.png
  2. http://formulasheet.com/
  3. https://cloud.githubusercontent.com/assets/13394147/8761877/2cd8277a-2d9a-11e5-9bb0-9f56f75b30c5.png
  4. Alignment of equations in docx #2310

@tsuikitho
Copy link
Author

@hftf
Copy link
Contributor

hftf commented Jul 22, 2015

It seems texmath converts both align* (and similar structures) and matrices (and similar) to EArray. An EArray element becomes a matrix element (<m:m>) instead of an equation array element (<m:eqArr>):

$ ghci

Prelude> import Text.TeXMath

Prelude Text.TeXMath> readTeX "\\begin{align*}a&=b\\end{align*}"
Right [EArray [AlignRight,AlignLeft] [[[EIdentifier "a"],[ESymbol Rel "=",EIdentifier "b"]]]]

Prelude Text.TeXMath> writeOMML DisplayInline [Text.TeXMath.Types.EArray [] []]
Element {elName = QName {qName = "oMath", qURI = Nothing, qPrefix = Just "m"}, ...

@jgm
Copy link
Owner

jgm commented Jul 23, 2015

So, maybe we need to add an EEqnArray element in texmath,
and modify all the readers and writers to use it?

+++ Ophir Lifshitz [Jul 22 15 13:45 ]:

It seems texmath [1]converts both align* (and similar structures) and
matrices (and similar) to EArray. An EArray element [2]becomes a
[3]matrix element (<m:m>) instead of an equation array element
(<m:eqArr>):

$ ghci

Prelude> import Text.TeXMath

Prelude Text.TeXMath> readTeX "\begin{align_}a&=b\end{align_}"
Right [EArray [AlignRight,AlignLeft] [[[EIdentifier "a"],[ESymbol Rel "=",EIdent
ifier "b"]]]]

Prelude Text.TeXMath> writeOMML DisplayInline [Text.TeXMath.Types.EArray [] []]
Element {elName = QName {qName = "oMath", qURI = Nothing, qPrefix = Just "m"}, .
..


Reply to this email directly or [4]view it on GitHub.

References

  1. https://github.com/jgm/texmath/blob/b747cde8f3cfb1a2e5651fd8426eb51d126b20dd/src/Text/TeXMath/Readers/TeX.hs#L388-L389
  2. https://github.com/jgm/texmath/blob/b747cde8f3cfb1a2e5651fd8426eb51d126b20dd/src/Text/TeXMath/Writers/OMML.hs#L203
  3. https://github.com/jgm/texmath/blob/b747cde8f3cfb1a2e5651fd8426eb51d126b20dd/src/Text/TeXMath/Writers/OMML.hs#L71
  4. Alignment of equations in docx #2310 (comment)

@jgm
Copy link
Owner

jgm commented Nov 1, 2015

The ooml generated by texmath (and used by pandoc in the docx) has:

    <m:m>
      <m:mPr>
        <m:baseJc m:val="center" />
        <m:plcHide m:val="on" />
        <m:mcs>
          <m:mc>
            <m:mcPr>
              <m:mcJc m:val="right" />
            </m:mcPr>
          </m:mc>
          <m:mc>
            <m:mcPr>
              <m:mcJc m:val="left" />
            </m:mcPr>
          </m:mc>
        </m:mcs>
      </m:mPr>
...

My understanding is that this should cause the second column of the array to be left-justified. But for some reason it is centered in Word. If it were left-justified, the equation would look right.

Anyone understand why it isn't?

@danil-tolkachev
Copy link

danil-tolkachev commented Apr 18, 2016

Move message to #2864. Sorry for noise.

@jgm jgm closed this as completed Apr 20, 2016
jgm added a commit that referenced this issue Apr 20, 2016
Closes several texmath-related bugs:  #2775, #2310, #2310.

This fixes issues with sub/superscript positioning and
matrix column alignment in docx.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants