git.iko.soy/typeable/pandoc
on master help sign in
TexMath: Export readTeXMath', which attends to display/inline.

Deprecate readTeXMath, and use readTeXMath' in all the writers. Require texmath >= 0.6.5.

commit0d95c15e8316eb28128bdd4c9c2f98e29f13f564 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 1 Nov 2013, 14:27 (13 years ago) parentab0ffe6
14 files changed+38−23
pandoc.cabal+1−1 src/Text/Pandoc/Readers/TeXMath.hs+19−5 src/Text/Pandoc/Writers/Docbook.hs+2−2 src/Text/Pandoc/Writers/Docx.hs+1−1 src/Text/Pandoc/Writers/HTML.hs+2−2 src/Text/Pandoc/Writers/Man.hs+3−2 src/Text/Pandoc/Writers/Markdown.hs+3−3 src/Text/Pandoc/Writers/OpenDocument.hs+1−1 src/Text/Pandoc/Writers/RTF.hs+1−1 tests/writer.docbook+1−1 tests/writer.html+1−1 tests/writer.man+1−1 tests/writer.opendocument+1−1 tests/writer.rtf+1−1
pandoc.cabal+1−1
@@ -215,7 +215,7 @@ Library
215215 old-locale >= 1 && < 1.1,
216216 time >= 1.2 && < 1.5,
217217 HTTP >= 4000.0.5 && < 4000.3,
218− texmath >= 0.6.4 && < 0.7,
218+ texmath >= 0.6.5 && < 0.7,
219219 xml >= 1.3.12 && < 1.4,
220220 random >= 1 && < 1.1,
221221 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
2727
2828Conversion of TeX math to a list of 'Pandoc' inline elements.
2929-}
30−module Text.Pandoc.Readers.TeXMath ( readTeXMath ) where
30+module Text.Pandoc.Readers.TeXMath ( readTeXMath, readTeXMath' ) where
3131
3232import Text.Pandoc.Definition
3333import Text.TeXMath
3434
3535-- | 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
3737-- 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.)
3854readTeXMath :: String -- ^ String to parse (assumes @'\n'@ line endings)
3955 -> [Inline]
40−readTeXMath inp = case texMathToPandoc DisplayInline inp of
41− Left _ -> [Str ("$" ++ inp ++ "$")]
42− Right res -> res
56+readTeXMath = readTeXMath' InlineMath
src/Text/Pandoc/Writers/Docbook.hs+2−2
@@ -281,8 +281,8 @@ inlineToDocbook opts (Math t str)
281281 $ fixNS
282282 $ removeAttr r
283283 Left _ -> inlinesToDocbook opts
284− $ readTeXMath str
285− | otherwise = inlinesToDocbook opts $ readTeXMath str
284+ $ readTeXMath' t str
285+ | otherwise = inlinesToDocbook opts $ readTeXMath' t str
286286 where (dt, tagtype) = case t of
287287 InlineMath -> (DisplayInline,"inlineequation")
288288 DisplayMath -> (DisplayBlock,"informalequation")
src/Text/Pandoc/Writers/Docx.hs+1−1
@@ -669,7 +669,7 @@ inlineToOpenXML opts (Math mathType str) = do
669669 else DisplayInline
670670 case texMathToOMML displayType str of
671671 Right r -> return [r]
672− Left _ -> inlinesToOpenXML opts (readTeXMath str)
672+ Left _ -> inlinesToOpenXML opts (readTeXMath' mathType str)
673673inlineToOpenXML opts (Cite _ lst) = inlinesToOpenXML opts lst
674674inlineToOpenXML opts (Code attrs str) =
675675 withTextProp (rStyle "VerbatimChar")
src/Text/Pandoc/Writers/HTML.hs+2−2
@@ -685,14 +685,14 @@ inlineToHtml opts inline =
685685 Right r -> return $ preEscapedString $
686686 ppcElement conf r
687687 Left _ -> inlineListToHtml opts
688− (readTeXMath str) >>= return .
688+ (readTeXMath' t str) >>= return .
689689 (H.span ! A.class_ "math")
690690 MathJax _ -> return $ H.span ! A.class_ "math" $ toHtml $
691691 case t of
692692 InlineMath -> "\\(" ++ str ++ "\\)"
693693 DisplayMath -> "\\[" ++ str ++ "\\]"
694694 PlainMath -> do
695− x <- inlineListToHtml opts (readTeXMath str)
695+ x <- inlineListToHtml opts (readTeXMath' t str)
696696 let m = H.span ! A.class_ "math" $ x
697697 let brtag = if writerHtml5 opts then H5.br else H.br
698698 return $ case t of
src/Text/Pandoc/Writers/Man.hs+3−2
@@ -330,9 +330,10 @@ inlineToMan opts (Cite _ lst) =
330330inlineToMan _ (Code _ str) =
331331 return $ text $ "\\f[C]" ++ escapeCode str ++ "\\f[]"
332332inlineToMan _ (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
334335inlineToMan opts (Math DisplayMath str) = do
335− contents <- inlineListToMan opts $ readTeXMath str
336+ contents <- inlineListToMan opts $ readTeXMath' DisplayMath str
336337 return $ cr <> text ".RS" $$ contents $$ text ".RE"
337338inlineToMan _ (RawInline f str)
338339 | f == Format "man" = return $ text str
src/Text/Pandoc/Writers/Markdown.hs+3−3
@@ -45,7 +45,7 @@ import Text.Pandoc.Pretty
4545import Control.Monad.State
4646import qualified Data.Set as Set
4747import Text.Pandoc.Writers.HTML (writeHtmlString)
48−import Text.Pandoc.Readers.TeXMath (readTeXMath)
48+import Text.Pandoc.Readers.TeXMath (readTeXMath')
4949import Text.HTML.TagSoup (renderTags, parseTags, isTagText, Tag(..))
5050import Network.URI (isURI)
5151import Data.Default
@@ -697,7 +697,7 @@ inlineToMarkdown opts (Math InlineMath str)
697697 return $ "\\(" <> text str <> "\\)"
698698 | isEnabled Ext_tex_math_double_backslash opts =
699699 return $ "\\\\(" <> text str <> "\\\\)"
700− | otherwise = inlineListToMarkdown opts $ readTeXMath str
700+ | otherwise = inlineListToMarkdown opts $ readTeXMath' InlineMath str
701701inlineToMarkdown opts (Math DisplayMath str)
702702 | isEnabled Ext_tex_math_dollars opts =
703703 return $ "$$" <> text str <> "$$"
@@ -706,7 +706,7 @@ inlineToMarkdown opts (Math DisplayMath str)
706706 | isEnabled Ext_tex_math_double_backslash opts =
707707 return $ "\\\\[" <> text str <> "\\\\]"
708708 | otherwise = (\x -> cr <> x <> cr) `fmap`
709− inlineListToMarkdown opts (readTeXMath str)
709+ inlineListToMarkdown opts (readTeXMath' DisplayMath str)
710710inlineToMarkdown opts (RawInline f str)
711711 | f == "html" || f == "markdown" ||
712712 (isEnabled Ext_raw_tex opts && (f == "latex" || f == "tex")) =
src/Text/Pandoc/Writers/OpenDocument.hs+1−1
@@ -374,7 +374,7 @@ inlineToOpenDocument o ils
374374 | SmallCaps l <- ils = withTextStyle SmallC $ inlinesToOpenDocument o l
375375 | Quoted t l <- ils = inQuotes t <$> inlinesToOpenDocument o l
376376 | 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)
378378 | Cite _ l <- ils = inlinesToOpenDocument o l
379379 | RawInline f s <- ils = if f == "opendocument" || f == "html"
380380 then withTextStyle Pre $ inTextStyle $ preformatted s
src/Text/Pandoc/Writers/RTF.hs+1−1
@@ -324,7 +324,7 @@ inlineToRTF (Quoted DoubleQuote lst) =
324324 "\\u8220\"" ++ (inlineListToRTF lst) ++ "\\u8221\""
325325inlineToRTF (Code _ str) = "{\\f1 " ++ (codeStringToRTF str) ++ "}"
326326inlineToRTF (Str str) = stringToRTF str
327−inlineToRTF (Math _ str) = inlineListToRTF $ readTeXMath str
327+inlineToRTF (Math t str) = inlineListToRTF $ readTeXMath' t str
328328inlineToRTF (Cite _ lst) = inlineListToRTF lst
329329inlineToRTF (RawInline f str)
330330 | f == Format "rtf" = str
tests/writer.docbook+1−1
@@ -1084,7 +1084,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
10841084 <listitem>
10851085 <para>
10861086 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}$$
10881088 </para>
10891089 </listitem>
10901090 <listitem>
tests/writer.html+1−1
@@ -439,7 +439,7 @@ Blah
439439<li><span class="math"><em>α</em> ∧ <em>ω</em></span></li>
440440<li><span class="math">223</span></li>
441441<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>
443443<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>
444444</ul>
445445<p>These shouldn’t be math:</p>
tests/writer.man+1−1
@@ -572,7 +572,7 @@ Ellipses\&...and\&...and\&....
572572.IP \[bu] 2
573573Here's some display math:
574574.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}$$
576576.RE
577577.IP \[bu] 2
578578Here's one that has a line break in it:
tests/writer.opendocument+1−1
@@ -1418,7 +1418,7 @@ five.</text:p>
14181418 </text:list-item>
14191419 <text:list-item>
14201420 <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>
14221422 </text:list-item>
14231423 <text:list-item>
14241424 <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
269269{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab {\i \u945?}\u8197?\u8743?\u8197?{\i \u969?}\par}
270270{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab 223\par}
271271{\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}
273273{\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}
274274{\pard \ql \f0 \sa180 \li0 \fi0 These shouldn\u8217't be math:\par}
275275{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab To get the famous equation, write {\f1 $e = mc^2$}.\par}