-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Conversation
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). |
I fixed the test. |
src/Text/Pandoc/Writers/ODT.hs
Outdated
selfClosingTag "draw:object" [("xlink:href", dirname) | ||
, ("xlink:type", "simple") | ||
, ("xlink:show", "embed") | ||
, ("xlink:actuate", "onLoad")] | ||
|
||
transformPicMath _ x = return x | ||
|
||
isTextMode :: Bool -> B.ByteString |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
src/Text/Pandoc/Writers/ODT.hs
Outdated
@@ -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 |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/Text/Pandoc/Writers/Shared.hs
Outdated
@@ -213,6 +214,15 @@ fixDisplayMath (Para lst) | |||
not (isDisplayMath x || isDisplayMath y)) lst | |||
fixDisplayMath x = x | |||
|
|||
wrapMath :: Block -> Block |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrapMath
has been removed.
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. |
Thanks! Looks good. |
PS. I did a before-and-after test, and this did really improve things. |
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.