git.iko.soy/typeable/pandoc
on master help sign in
Fixed #3760. (#3784)

Using the same solution as in the LaTeX reader: equation -> displaymath align -> displaymath \begin{aligned} ... \end{aligned} etc..

commit8b502dd50ff842bdbbf346a67a607d1a7905bda3 authorYuchen Pei <ycpei@users.noreply.github.com> dateWed 12 Jul 2017, 11:19 (9 years ago) parentde117fb
3 files changed+44−10
src/Text/Pandoc/Readers/Vimwiki.hs+26−6 test/vimwiki-reader.native+8−4 test/vimwiki-reader.wiki+10
src/Text/Pandoc/Readers/Vimwiki.hs+26−6
@@ -75,7 +75,8 @@ import qualified Text.Pandoc.Builder
7575 as B (headerWith, str, space, strong, emph, strikeout, code, link, image,
7676 spanWith, para, horizontalRule, blockQuote, bulletList, plain,
7777 orderedList, simpleTable, softbreak, codeBlockWith, imageWith, divWith,
78− setMeta, definitionList, superscript, subscript)
78+ setMeta, definitionList, superscript, subscript, displayMath,
79+ math)
7980import Text.Pandoc.Class (PandocMonad(..))
8081import Text.Pandoc.Definition (Pandoc(..), Inline(Space),
8182 Block(BulletList, OrderedList), Attr, nullMeta, Meta, ListNumberStyle(..),
@@ -265,13 +266,32 @@ displayMath :: PandocMonad m => VwParser m Blocks
265266displayMath = try $ do
266267 many spaceChar >> string "{{$"
267268 mathTag <- option "" mathTagParser
269+ many space
268270 contents <- manyTill anyChar (try (char '\n' >> many spaceChar >> string "}}$"
269271 >> many spaceChar >> newline))
270272 let contentsWithTags
271− | mathTag == "" = "\\[" ++ contents ++ "\n\\]"
272− | otherwise = "\\begin{" ++ mathTag ++ "}" ++ contents
273+ | mathTag == "" = contents
274+ | otherwise = "\\begin{" ++ mathTag ++ "}\n" ++ contents
273275 ++ "\n\\end{" ++ mathTag ++ "}"
274− return $ B.plain $ B.str contentsWithTags
276+ return $ B.para $ B.displayMath contentsWithTags
277+
278+
279+mathTagLaTeX :: String -> String
280+mathTagLaTeX s = case s of
281+ "equation" -> ""
282+ "equation*" -> ""
283+ "gather" -> "gathered"
284+ "gather*" -> "gathered"
285+ "multline" -> "gathered"
286+ "multline*" -> "gathered"
287+ "eqnarray" -> "aligned"
288+ "eqnarray*" -> "aligned"
289+ "align" -> "aligned"
290+ "align*" -> "aligned"
291+ "alignat" -> "aligned"
292+ "alignat*" -> "aligned"
293+ _ -> s
294+
275295
276296mixedList :: PandocMonad m => VwParser m Blocks
277297mixedList = try $ do
@@ -598,7 +618,7 @@ inlineMath :: PandocMonad m => VwParser m Inlines
598618inlineMath = try $ do
599619 char '$'
600620 contents <- many1Till (noneOf "\n") (char '$')
601− return $ B.str $ "\\(" ++ contents ++ "\\)"
621+ return $ B.math contents
602622
603623tag :: PandocMonad m => VwParser m Inlines
604624tag = try $ do
@@ -650,4 +670,4 @@ mathTagParser = do
650670 s <- try $ lookAhead (char '%' >> (manyTill (noneOf spaceChars)
651671 (try $ char '%' >> many (noneOf $ '%':spaceChars) >> space)))
652672 char '%' >> string s >> char '%'
653− return s
673+ return $ mathTagLaTeX s
test/vimwiki-reader.native+8−4
@@ -81,7 +81,7 @@ Pandoc (Meta {unMeta = fromList [("date",MetaInlines [Str "2017-05-01"]),("title
8181,Header 2 ("lists",[],[]) [Str "lists"]
8282,OrderedList (1,DefaultStyle,DefaultDelim)
8383 [[Plain [Str "ordered",Space,Str "list",Space,Str "item",Space,Str "1,",Space,Str "and",Space,Str "here",Space,Str "is",Space,Str "some",Space,Str "math",Space,Str "belonging",Space,Str "to",Space,Str "list",Space,Str "item",Space,Str "1"]
84− ,Plain [Str "\\[\n a^2 + b^2 = c^2\n\\]"]
84+ ,Para [Math DisplayMath "a^2 + b^2 = c^2"]
8585 ,Plain [Str "and",Space,Str "some",Space,Str "preformatted",Space,Str "and",Space,Str "tables",Space,Str "belonging",Space,Str "to",Space,Str "item",Space,Str "1",Space,Str "as",Space,Str "well"]
8686 ,CodeBlock ("",[],[]) "I'm part of item 1."
8787 ,Table [] [AlignDefault,AlignDefault] [0.0,0.0]
@@ -184,9 +184,13 @@ Pandoc (Meta {unMeta = fromList [("date",MetaInlines [Str "2017-05-01"]),("title
184184 ,[Plain [Str "b"]]]]]]]
185185 ,[Plain [Span ("",["done4"],[]) [],Str "task",Space,Str "2"]]]
186186,Header 2 ("math",[],[]) [Str "math"]
187−,Para [Str "\\( \\sum_i a_i^2 = 1 \\)"]
188−,Plain [Str "\\[\n\\sum_i a_i^2\n=\n1\n\\]"]
189−,Plain [Str "\\begin{align}\n\\sum_i a_i^2 &= 1 + 1 \\\\\n&= 2.\n\\end{align}"]
187+,Para [Math InlineMath " \\sum_i a_i^2 = 1 "]
188+,Para [Math DisplayMath "\\sum_i a_i^2\n=\n1"]
189+,Para [Math DisplayMath "\\begin{aligned}\n\\sum_i a_i^2 &= 1 + 1 \\\\\n&= 2.\n\\end{aligned}"]
190+,Para [Str "edge",Space,Str "case",Space,Str "(the",Space,Code ("",[],[]) "c^2 + ",Space,Str "after",Space,Str "the",Space,Str "multline",Space,Str "tag",Space,Str "is",Space,Str "in",Space,Str "the",Space,Str "equation):"]
191+,Para [Math DisplayMath "\\begin{gathered}\nc^2 + \na^2 + b^2\n\\end{gathered}"]
192+,Para [Str "edge",Space,Str "case",Space,Str "(the",Space,Str "tag",Space,Str "is",Space,Code ("",[],[]) "hello%bye",Str ")"]
193+,Para [Math DisplayMath "\\begin{hello%bye}\n\\int_a^b f(x) dx\n\\end{hello%bye}"]
190194,Para [Str "Just",Space,Str "two",Space,Str "dollar",Space,Str "signs:",Space,Str "$$"]
191195,Para [Str "[not",Space,Str "math]",Space,Str "You",Space,Str "have",Space,Str "$1",SoftBreak,Str "and",Space,Str "I",Space,Str "have",Space,Str "$1."]
192196,Header 2 ("tags",[],[]) [Str "tags"]
test/vimwiki-reader.wiki+10
@@ -297,6 +297,16 @@ $ \sum_i a_i^2 = 1 $
297297&= 2.
298298}}$
299299
300+edge case (the `c^2 + ` after the multline tag is in the equation):
301+{{$%multline%c^2 +
302+a^2 + b^2
303+}}$
304+
305+edge case (the tag is `hello%bye`)
306+{{$%hello%bye%
307+\int_a^b f(x) dx
308+}}$
309+
300310Just two dollar signs: $$
301311
302312[not math] You have $1