git.iko.soy/typeable/pandoc
on master help sign in
TexMath: Export readTeXMath', which attends to display/inline.
0d95c15John MacFarlane
pandoc.cabal+1−1
@@ -215,7 +215,7 @@ Library
215 old-locale >= 1 && < 1.1,
215 old-locale >= 1 && < 1.1,
216 time >= 1.2 && < 1.5,
216 time >= 1.2 && < 1.5,
217 HTTP >= 4000.0.5 && < 4000.3,
217 HTTP >= 4000.0.5 && < 4000.3,
218− texmath >= 0.6.4 && < 0.7,
218+ texmath >= 0.6.5 && < 0.7,
219 xml >= 1.3.12 && < 1.4,
219 xml >= 1.3.12 && < 1.4,
220 random >= 1 && < 1.1,
220 random >= 1 && < 1.1,
221 extensible-exceptions >= 0.1 && < 0.2,
221 extensible-exceptions >= 0.1 && < 0.2,
src/Text/Pandoc/Readers/TeXMath.hs+19−5
@@ -27,16 +27,30 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
27
28Conversion of TeX math to a list of 'Pandoc' inline elements.
28Conversion of TeX math to a list of 'Pandoc' inline elements.
29-}
29-}
30−module Text.Pandoc.Readers.TeXMath ( readTeXMath ) where
30+module Text.Pandoc.Readers.TeXMath ( readTeXMath, readTeXMath' ) where
31
31
32import Text.Pandoc.Definition
32import Text.Pandoc.Definition
33import Text.TeXMath
33import Text.TeXMath
34
34
35-- | Converts a raw TeX math formula to a list of 'Pandoc' inlines.
35-- | Converts a raw TeX math formula to a list of 'Pandoc' inlines.
36−-- Defaults to raw formula between @$@ characters if entire formula
36+-- Defaults to raw formula between @$@ or @$$@ characters if entire formula
37-- can't be converted.
37-- can't be converted.
38+readTeXMath' :: MathType
39+ -> String -- ^ String to parse (assumes @'\n'@ line endings)
40+ -> [Inline]
41+readTeXMath' mt inp = case texMathToPandoc dt inp of
42+ Left _ -> [Str (delim ++ inp ++ delim)]
43+ Right res -> res
44+ where (dt, delim) = case mt of
45+ DisplayMath -> (DisplayBlock, "$$")
46+ InlineMath -> (DisplayInline, "$")
47+
48+{-# DEPRECATED readTeXMath "Use readTeXMath' from Text.Pandoc.JSON instead" #-}
49+-- | Converts a raw TeX math formula to a list of 'Pandoc' inlines.
50+-- Defaults to raw formula between @$@ characters if entire formula
51+-- can't be converted. (This is provided for backwards compatibility;
52+-- it is better to use @readTeXMath'@, which properly distinguishes
53+-- between display and inline math.)
38readTeXMath :: String -- ^ String to parse (assumes @'\n'@ line endings)
54readTeXMath :: String -- ^ String to parse (assumes @'\n'@ line endings)
39 -> [Inline]
55 -> [Inline]
40−readTeXMath inp = case texMathToPandoc DisplayInline inp of
56+readTeXMath = readTeXMath' InlineMath
41− Left _ -> [Str ("$" ++ inp ++ "$")]
42− Right res -> res
src/Text/Pandoc/Writers/Docbook.hs+2−2
@@ -281,8 +281,8 @@ inlineToDocbook opts (Math t str)
281 $ fixNS
281 $ fixNS
282 $ removeAttr r
282 $ removeAttr r
283 Left _ -> inlinesToDocbook opts
283 Left _ -> inlinesToDocbook opts
284− $ readTeXMath str
284+ $ readTeXMath' t str
285− | otherwise = inlinesToDocbook opts $ readTeXMath str
285+ | otherwise = inlinesToDocbook opts $ readTeXMath' t str
286 where (dt, tagtype) = case t of
286 where (dt, tagtype) = case t of
287 InlineMath -> (DisplayInline,"inlineequation")
287 InlineMath -> (DisplayInline,"inlineequation")
288 DisplayMath -> (DisplayBlock,"informalequation")
288 DisplayMath -> (DisplayBlock,"informalequation")
src/Text/Pandoc/Writers/Docx.hs+1−1
@@ -669,7 +669,7 @@ inlineToOpenXML opts (Math mathType str) = do
669 else DisplayInline
669 else DisplayInline
670 case texMathToOMML displayType str of
670 case texMathToOMML displayType str of
671 Right r -> return [r]
671 Right r -> return [r]
672− Left _ -> inlinesToOpenXML opts (readTeXMath str)
672+ Left _ -> inlinesToOpenXML opts (readTeXMath' mathType str)
673inlineToOpenXML opts (Cite _ lst) = inlinesToOpenXML opts lst
673inlineToOpenXML opts (Cite _ lst) = inlinesToOpenXML opts lst
674inlineToOpenXML opts (Code attrs str) =
674inlineToOpenXML opts (Code attrs str) =
675 withTextProp (rStyle "VerbatimChar")
675 withTextProp (rStyle "VerbatimChar")
src/Text/Pandoc/Writers/HTML.hs+2−2
@@ -685,14 +685,14 @@ inlineToHtml opts inline =
685 Right r -> return $ preEscapedString $
685 Right r -> return $ preEscapedString $
686 ppcElement conf r
686 ppcElement conf r
687 Left _ -> inlineListToHtml opts
687 Left _ -> inlineListToHtml opts
688− (readTeXMath str) >>= return .
688+ (readTeXMath' t str) >>= return .
689 (H.span ! A.class_ "math")
689 (H.span ! A.class_ "math")
690 MathJax _ -> return $ H.span ! A.class_ "math" $ toHtml $
690 MathJax _ -> return $ H.span ! A.class_ "math" $ toHtml $
691 case t of
691 case t of
692 InlineMath -> "\\(" ++ str ++ "\\)"
692 InlineMath -> "\\(" ++ str ++ "\\)"
693 DisplayMath -> "\\[" ++ str ++ "\\]"
693 DisplayMath -> "\\[" ++ str ++ "\\]"
694 PlainMath -> do
694 PlainMath -> do
695− x <- inlineListToHtml opts (readTeXMath str)
695+ x <- inlineListToHtml opts (readTeXMath' t str)
696 let m = H.span ! A.class_ "math" $ x
696 let m = H.span ! A.class_ "math" $ x
697 let brtag = if writerHtml5 opts then H5.br else H.br
697 let brtag = if writerHtml5 opts then H5.br else H.br
698 return $ case t of
698 return $ case t of
src/Text/Pandoc/Writers/Man.hs+3−2
@@ -330,9 +330,10 @@ inlineToMan opts (Cite _ lst) =
330inlineToMan _ (Code _ str) =
330inlineToMan _ (Code _ str) =
331 return $ text $ "\\f[C]" ++ escapeCode str ++ "\\f[]"
331 return $ text $ "\\f[C]" ++ escapeCode str ++ "\\f[]"
332inlineToMan _ (Str str) = return $ text $ escapeString str
332inlineToMan _ (Str str) = return $ text $ escapeString str
333−inlineToMan opts (Math InlineMath str) = inlineListToMan opts $ readTeXMath str
333+inlineToMan opts (Math InlineMath str) =
334+ inlineListToMan opts $ readTeXMath' InlineMath str
334inlineToMan opts (Math DisplayMath str) = do
335inlineToMan opts (Math DisplayMath str) = do
335− contents <- inlineListToMan opts $ readTeXMath str
336+ contents <- inlineListToMan opts $ readTeXMath' DisplayMath str
336 return $ cr <> text ".RS" $$ contents $$ text ".RE"
337 return $ cr <> text ".RS" $$ contents $$ text ".RE"
337inlineToMan _ (RawInline f str)
338inlineToMan _ (RawInline f str)
338 | f == Format "man" = return $ text str
339 | f == Format "man" = return $ text str
src/Text/Pandoc/Writers/Markdown.hs+3−3
@@ -45,7 +45,7 @@ import Text.Pandoc.Pretty
45import Control.Monad.State
45import Control.Monad.State
46import qualified Data.Set as Set
46import qualified Data.Set as Set
47import Text.Pandoc.Writers.HTML (writeHtmlString)
47import Text.Pandoc.Writers.HTML (writeHtmlString)
48−import Text.Pandoc.Readers.TeXMath (readTeXMath)
48+import Text.Pandoc.Readers.TeXMath (readTeXMath')
49import Text.HTML.TagSoup (renderTags, parseTags, isTagText, Tag(..))
49import Text.HTML.TagSoup (renderTags, parseTags, isTagText, Tag(..))
50import Network.URI (isURI)
50import Network.URI (isURI)
51import Data.Default
51import Data.Default
@@ -697,7 +697,7 @@ inlineToMarkdown opts (Math InlineMath str)
697 return $ "\\(" <> text str <> "\\)"
697 return $ "\\(" <> text str <> "\\)"
698 | isEnabled Ext_tex_math_double_backslash opts =
698 | isEnabled Ext_tex_math_double_backslash opts =
699 return $ "\\\\(" <> text str <> "\\\\)"
699 return $ "\\\\(" <> text str <> "\\\\)"
700− | otherwise = inlineListToMarkdown opts $ readTeXMath str
700+ | otherwise = inlineListToMarkdown opts $ readTeXMath' InlineMath str
701inlineToMarkdown opts (Math DisplayMath str)
701inlineToMarkdown opts (Math DisplayMath str)
702 | isEnabled Ext_tex_math_dollars opts =
702 | isEnabled Ext_tex_math_dollars opts =
703 return $ "$$" <> text str <> "$$"
703 return $ "$$" <> text str <> "$$"
@@ -706,7 +706,7 @@ inlineToMarkdown opts (Math DisplayMath str)
706 | isEnabled Ext_tex_math_double_backslash opts =
706 | isEnabled Ext_tex_math_double_backslash opts =
707 return $ "\\\\[" <> text str <> "\\\\]"
707 return $ "\\\\[" <> text str <> "\\\\]"
708 | otherwise = (\x -> cr <> x <> cr) `fmap`
708 | otherwise = (\x -> cr <> x <> cr) `fmap`
709− inlineListToMarkdown opts (readTeXMath str)
709+ inlineListToMarkdown opts (readTeXMath' DisplayMath str)
710inlineToMarkdown opts (RawInline f str)
710inlineToMarkdown opts (RawInline f str)
711 | f == "html" || f == "markdown" ||
711 | f == "html" || f == "markdown" ||
712 (isEnabled Ext_raw_tex opts && (f == "latex" || f == "tex")) =
712 (isEnabled Ext_raw_tex opts && (f == "latex" || f == "tex")) =
src/Text/Pandoc/Writers/OpenDocument.hs+1−1
@@ -374,7 +374,7 @@ inlineToOpenDocument o ils
374 | SmallCaps l <- ils = withTextStyle SmallC $ inlinesToOpenDocument o l
374 | SmallCaps l <- ils = withTextStyle SmallC $ inlinesToOpenDocument o l
375 | Quoted t l <- ils = inQuotes t <$> inlinesToOpenDocument o l
375 | Quoted t l <- ils = inQuotes t <$> inlinesToOpenDocument o l
376 | Code _ s <- ils = withTextStyle Pre $ inTextStyle $ preformatted s
376 | Code _ s <- ils = withTextStyle Pre $ inTextStyle $ preformatted s
377− | Math _ s <- ils = inlinesToOpenDocument o (readTeXMath s)
377+ | Math t s <- ils = inlinesToOpenDocument o (readTeXMath' t s)
378 | Cite _ l <- ils = inlinesToOpenDocument o l
378 | Cite _ l <- ils = inlinesToOpenDocument o l
379 | RawInline f s <- ils = if f == "opendocument" || f == "html"
379 | RawInline f s <- ils = if f == "opendocument" || f == "html"
380 then withTextStyle Pre $ inTextStyle $ preformatted s
380 then withTextStyle Pre $ inTextStyle $ preformatted s
src/Text/Pandoc/Writers/RTF.hs+1−1
@@ -324,7 +324,7 @@ inlineToRTF (Quoted DoubleQuote lst) =
324 "\\u8220\"" ++ (inlineListToRTF lst) ++ "\\u8221\""
324 "\\u8220\"" ++ (inlineListToRTF lst) ++ "\\u8221\""
325inlineToRTF (Code _ str) = "{\\f1 " ++ (codeStringToRTF str) ++ "}"
325inlineToRTF (Code _ str) = "{\\f1 " ++ (codeStringToRTF str) ++ "}"
326inlineToRTF (Str str) = stringToRTF str
326inlineToRTF (Str str) = stringToRTF str
327−inlineToRTF (Math _ str) = inlineListToRTF $ readTeXMath str
327+inlineToRTF (Math t str) = inlineListToRTF $ readTeXMath' t str
328inlineToRTF (Cite _ lst) = inlineListToRTF lst
328inlineToRTF (Cite _ lst) = inlineListToRTF lst
329inlineToRTF (RawInline f str)
329inlineToRTF (RawInline f str)
330 | f == Format "rtf" = str
330 | f == Format "rtf" = str
tests/writer.docbook+1−1
@@ -1084,7 +1084,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
1084 <listitem>
1084 <listitem>
1085 <para>
1085 <para>
1086 Here’s some display math:
1086 Here’s some display math:
1087− $\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$
1087+ $$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$$
1088 </para>
1088 </para>
1089 </listitem>
1089 </listitem>
1090 <listitem>
1090 <listitem>
tests/writer.html+1−1
@@ -439,7 +439,7 @@ Blah
439<li><span class="math"><em>α</em> ∧ <em>ω</em></span></li>
439<li><span class="math"><em>α</em> ∧ <em>ω</em></span></li>
440<li><span class="math">223</span></li>
440<li><span class="math">223</span></li>
441<li><span class="math"><em>p</em></span>-Tree</li>
441<li><span class="math"><em>p</em></span>-Tree</li>
442−<li>Here’s some display math: <br /><span class="math">$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</span><br /></li>
442+<li>Here’s some display math: <br /><span class="math">$$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$$</span><br /></li>
443<li>Here’s one that has a line break in it: <span class="math"><em>α</em> + <em>ω</em> × <em>x</em><sup>2</sup></span>.</li>
443<li>Here’s one that has a line break in it: <span class="math"><em>α</em> + <em>ω</em> × <em>x</em><sup>2</sup></span>.</li>
444</ul>
444</ul>
445<p>These shouldn’t be math:</p>
445<p>These shouldn’t be math:</p>
tests/writer.man+1−1
@@ -572,7 +572,7 @@ Ellipses\&...and\&...and\&....
572.IP \[bu] 2
572.IP \[bu] 2
573Here's some display math:
573Here's some display math:
574.RS
574.RS
575−$\\frac{d}{dx}f(x)=\\lim_{h\\to 0}\\frac{f(x+h)\-f(x)}{h}$
575+$$\\frac{d}{dx}f(x)=\\lim_{h\\to 0}\\frac{f(x+h)\-f(x)}{h}$$
576.RE
576.RE
577.IP \[bu] 2
577.IP \[bu] 2
578Here's one that has a line break in it:
578Here's one that has a line break in it:
tests/writer.opendocument+1−1
@@ -1418,7 +1418,7 @@ five.</text:p>
1418 </text:list-item>
1418 </text:list-item>
1419 <text:list-item>
1419 <text:list-item>
1420 <text:p text:style-name="P51">Here’s some display math:
1420 <text:p text:style-name="P51">Here’s some display math:
1421− $\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$</text:p>
1421+ $$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$$</text:p>
1422 </text:list-item>
1422 </text:list-item>
1423 <text:list-item>
1423 <text:list-item>
1424 <text:p text:style-name="P51">Here’s one that has a line break in it:
1424 <text:p text:style-name="P51">Here’s one that has a line break in it:
tests/writer.rtf+1−1
@@ -269,7 +269,7 @@ quoted link
269{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab {\i \u945?}\u8197?\u8743?\u8197?{\i \u969?}\par}
269{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab {\i \u945?}\u8197?\u8743?\u8197?{\i \u969?}\par}
270{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab 223\par}
270{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab 223\par}
271{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab {\i p}-Tree\par}
271{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab {\i p}-Tree\par}
272−{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab Here\u8217's some display math: $\\frac\{d\}\{dx\}f(x)=\\lim_\{h\\to 0\}\\frac\{f(x+h)-f(x)\}\{h\}$\par}
272+{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab Here\u8217's some display math: $$\\frac\{d\}\{dx\}f(x)=\\lim_\{h\\to 0\}\\frac\{f(x+h)-f(x)\}\{h\}$$\par}
273{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab Here\u8217's one that has a line break in it: {\i \u945?}\u8197?+\u8197?{\i \u969?}\u8197?\u215?\u8197?{\i x}{\super 2}.\sa180\par}
273{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab Here\u8217's one that has a line break in it: {\i \u945?}\u8197?+\u8197?{\i \u969?}\u8197?\u215?\u8197?{\i x}{\super 2}.\sa180\par}
274{\pard \ql \f0 \sa180 \li0 \fi0 These shouldn\u8217't be math:\par}
274{\pard \ql \f0 \sa180 \li0 \fi0 These shouldn\u8217't be math:\par}
275{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab To get the famous equation, write {\f1 $e = mc^2$}.\par}
275{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab To get the famous equation, write {\f1 $e = mc^2$}.\par}