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

overline and bar are mixed up in pandoc 2.9.1.1 #152

Closed
pianzuo opened this issue Jan 25, 2020 · 13 comments
Closed

overline and bar are mixed up in pandoc 2.9.1.1 #152

pianzuo opened this issue Jan 25, 2020 · 13 comments
Milestone

Comments

@pianzuo
Copy link

pianzuo commented Jan 25, 2020

I don't know whether or not this is a bug. I use pandoc 2.9.1.1.
This is a very simple demo latex:
\documentclass{article}
\begin{document}
This is overline: $\overline{ABC}$.

This is bar: $\bar{ABC}$.
\end{document}
The correct result looks like this:
image

But if I run convert it to MS word by command:
pandoc demo.tex -o demo.docx
I get:
image

All files are in the attached zip file.demo.zip

@jgm jgm transferred this issue from jgm/pandoc Jan 25, 2020
@jgm
Copy link
Owner

jgm commented Jan 25, 2020

texmath does distinguish these in parsing, but the distinction apparently gets collapsed when rendering to OMML.

 %     texmath -t native
\overline{ABC} \bar{ABC}
[EOver False (EGrouped [EIdentifier "A",EIdentifier "B",EIdentifier "C"]) (ESymbol TOver "\175"),EOver False (EGrouped [EIdentifier "A",EIdentifier "B",EIdentifier "C"]) (ESymbol Accent "\8254")]

@pianzuo
Copy link
Author

pianzuo commented Jan 26, 2020

Oh, thx. Is this will be handled in the next version of pandoc? or next version of texmath?

@pianzuo
Copy link
Author

pianzuo commented Jan 26, 2020

I have tried it texmath demo [here](https://johnmacfarlane.net/texmath.html. LaTeX convert to MathML and then convert back works fine.

@jgm
Copy link
Owner

jgm commented Jan 26, 2020

Yes - texmath's tex parsing and MathML rendering do distinguish these things. But its OMML rendering (Word equation) does not.

@pianzuo
Copy link
Author

pianzuo commented Jan 27, 2020

I think word equation also distinguish these things. This is a example:
image

The first one is input as \overline(A)[sp]\overline(B)[sp]\overline(C)[sp] under math mode. [sp] means press space key. The second one is input as A\bar[sp]B\bar[sp]C\bar[sp] under math mode.

Example files:
demo2.docx

@pianzuo
Copy link
Author

pianzuo commented Jan 27, 2020

I unzip demo2.docx as a zip. Then the first A looks like:
<m:bar>
<m:barPr>
<m:pos m:val="top"/>
<m:ctrlPr>
<w:rPr>
<w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
<w:i/>
</w:rPr>
</m:ctrlPr>
</m:barPr>
<m:e>
<m:r>
<w:rPr>
<w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math" w:hint="eastAsia"/>
</w:rPr>
<m:t>A</m:t>
</m:r>
</m:e>
</m:bar>

The second A looks like
<m:acc>
<m:accPr>
<m:chr m:val="̅"/>
<m:ctrlPr>
<w:rPr>
<w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
<w:i/>
</w:rPr>
</m:ctrlPr>
</m:accPr>
<m:e>
<m:r>
<w:rPr>
<w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math" w:hint="eastAsia"/>
</w:rPr>
<m:t>A</m:t>
</m:r>
<m:ctrlPr>
<w:rPr>
<w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math" w:hint="eastAsia"/>
<w:i/>
</w:rPr>
</m:ctrlPr>
</m:e>
</m:acc>

@pianzuo
Copy link
Author

pianzuo commented Jan 27, 2020

Then I convert demo2.docx to demo2.tex, they are mixed up.
(\overline{A}\overline{B}\overline{C}) v.s.
(\overline{A}\overline{B}\overline{C})

I put demo2.tex in here. demo2.zip

@pianzuo
Copy link
Author

pianzuo commented Jan 27, 2020

So I think there maybe some problem with the translation between mathml and word.

@jgm
Copy link
Owner

jgm commented Jan 27, 2020

texmath doesn't go via a MathML intermediary. It uses a Haskell data structure. But yes, the problem lies there, in the translation from our equation structure to omml.

@jgm
Copy link
Owner

jgm commented Jan 27, 2020

Thank you for the xml samples, which show the output we should be getting.

@jgm
Copy link
Owner

jgm commented Jan 27, 2020

To recap, overline is parsed as

EOver False XXX (ESymbol TOver "\175")

and bar as

EOver False XXX (ESymbol Accent "\8254")

We want to use m:bar in the first case and m:acc in the second.

@pianzuo
Copy link
Author

pianzuo commented Jan 27, 2020

thx for reply.

@jgm
Copy link
Owner

jgm commented Jan 27, 2020

With this patch

diff --git a/src/Text/TeXMath/Writers/OMML.hs b/src/Text/TeXMath/Writers/OMML.hs
index 342d95fa..23a7b555 100644
--- a/src/Text/TeXMath/Writers/OMML.hs
+++ b/src/Text/TeXMath/Writers/OMML.hs
@@ -221,11 +221,11 @@ showExp props e =
      | n > 1.8               -> [str props "\x2001\x2001"]
      | otherwise             -> [str props "\x200B"]
        -- this is how the xslt sheet handles all spaces
-   EUnder _ x (ESymbol _ (T.unpack -> [c])) | isBarChar c ->
+   EUnder _ x (ESymbol TUnder t) | T.all isBarChar t ->
                        [mnode "bar" [ mnode "barPr" $
                                         mnodeA "pos" "bot" ()
                                     , mnode "e" $ showExp props x ]]
-   EOver _ x (ESymbol _ (T.unpack -> [c])) | isBarChar c ->
+   EOver _ x (ESymbol TOver t) | T.all isBarChar t ->
                        [mnode "bar" [ mnode "barPr" $
                                         mnodeA "pos" "top" ()
                                     , mnode "e" $ showExp props x ]]

we get the following output:

% stack exec texmath -- -t tex -t omml
\bar{AB} \overline{AB}
<m:oMathPara>
  <m:oMathParaPr>
    <m:jc m:val="center" />
  </m:oMathParaPr>
  <m:oMath>
    <m:acc>
      <m:accPr>
        <m:chr m:val="‾" />
      </m:accPr>
      <m:e>
        <m:r>
          <m:t>A</m:t>
        </m:r>
        <m:r>
          <m:t>B</m:t>
        </m:r>
      </m:e>
    </m:acc>
    <m:bar>
      <m:barPr>
        <m:pos m:val="top" />
      </m:barPr>
      <m:e>
        <m:r>
          <m:t>A</m:t>
        </m:r>
        <m:r>
          <m:t>B</m:t>
        </m:r>
      </m:e>
    </m:bar>
  </m:oMath>
</m:oMathPara>

which looks right I think. However, this induces a number of failures in our automated tests, which I'll need to go through and look at before committing.

@jgm jgm added this to the next-release milestone Jan 27, 2020
@jgm jgm closed this as completed in 1c76506 Feb 14, 2020
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

2 participants