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

improve formatting of formulas in OpenDocument #4170

Merged
merged 1 commit into from
Dec 29, 2017
Merged

improve formatting of formulas in OpenDocument #4170

merged 1 commit into from
Dec 29, 2017

Conversation

oltolm
Copy link
Contributor

@oltolm oltolm commented Dec 18, 2017

This commit greatly improves the formatting of formulas in ODT documents.

Formulas are wrapped in a span element. Two formula styles are generated. One for display math and one for inline math.

An inline math formula is marked as text. See "Text mode" in Math Guide.

Display math is placed in a paragraph of its own, which is centered. A new paragraph style is generated for each formula.

@mb21
Copy link
Collaborator

mb21 commented Dec 19, 2017

This improves how the generated math looks visually? Sounds like a welcome change...

I guess you'll have to adjust the failing tests (and possibly add a new one that covers you new code).

@oltolm
Copy link
Contributor Author

oltolm commented Dec 20, 2017

I fixed the test.

selfClosingTag "draw:object" [("xlink:href", dirname)
, ("xlink:type", "simple")
, ("xlink:show", "embed")
, ("xlink:actuate", "onLoad")]

transformPicMath _ x = return x

isTextMode :: Bool -> B.ByteString
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a stylistic matter, I'd expect a function named isTextMode to return a Bool.
Maybe inTextMode or withTextMode would be a better name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed it to documentSettings. That's the name of the element it creates.

@@ -87,7 +87,7 @@ pandocToODT opts doc@(Pandoc meta _) = do
P.readDataFile "reference.odt"
-- handle formulas and pictures
-- picEntriesRef <- P.newIORef ([] :: [Entry])
doc' <- walkM (transformPicMath opts) $ walk fixDisplayMath doc
doc' <- walkM (transformPicMath opts) $ walk wrapMath $ walk fixDisplayMath doc
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should think about whether some of these transformations should go in the OpenDocument writer rather than here. (We had to put tarnsformPicMath here, originally at least, because OpenDocument writer was pure. Now that we have PandocMonad we could even think about putting it all in the OpenDocument writer.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed wrapMath. It was not needed anymore.

@@ -446,7 +474,9 @@ inlineToOpenDocument o ils
| writerWrapText o == WrapPreserve
-> return $ preformatted "\n"
| otherwise ->return space
Span attr xs -> withLangFromAttr attr (inlinesToOpenDocument o xs)
il@(Span attr xs)-> do
S.when (isDisplayMath il) (setDisplayMath True)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to set stDisplayMath to True at the first occurrence of display math; it then stays True throughout the rest of the document -- at least I don't see anywhere where it gets reset. Is this the intent? AS noted above, I'm confused about what work this is doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to put display math into an own paragraph and center it. I have changed the implementation so that it is not needed anymore. Now I set the anchor-type of the formula to paragraph. which is what pandoc did before. Now I put the properties like style:vertical-pos and style:vertical-rel into a style, because these properties are not supported directly on a draw:frame. The document produced by pandoc was not compliant to the spec, I think.

@@ -213,6 +214,15 @@ fixDisplayMath (Para lst)
not (isDisplayMath x || isDisplayMath y)) lst
fixDisplayMath x = x

wrapMath :: Block -> Block
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be used only in the ODT writer, so it should go there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrapMath has been removed.

@oltolm
Copy link
Contributor Author

oltolm commented Dec 28, 2017

Thank you for the review. I have improved the code.

This commit greatly improves the formatting of formulas in ODT documents. An inline math formula is marked as text. See "Text mode" in Math Guide. Two formula styles are generated. One for display math and one for inline math. Pandoc now generates documents which better comply to the OpenDocument spec.

@jgm
Copy link
Owner

jgm commented Dec 29, 2017

Thanks! Looks good.

@jgm jgm merged commit ac8e72a into jgm:master Dec 29, 2017
@jgm
Copy link
Owner

jgm commented Dec 29, 2017

PS. I did a before-and-after test, and this did really improve things.

@oltolm oltolm deleted the opendocument branch December 29, 2017 07:58
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

Successfully merging this pull request may close these issues.

3 participants