문제

I'm trying to implement the Haskell solution by John MacFarlane here, which should allow me to convert HTML files with MathJax (latex) input to .tex while preserving the math. The script is:

import Text.Pandoc

main = toJsonFilter fixmath

fixmath :: Block -> Block
fixmath = bottomUp fixmathBlock . bottomUp fixmathInline

fixmathInline :: Inline -> Inline
fixmathInline (RawInline "html" ('<':'!':'-':'-':'M':'A':'T':'H':xs)) =
  RawInline "tex" $ take (length xs - 3) xs
fixmathInline x = x

fixmathBlock :: Block -> Block
fixmathBlock (RawBlock "html" ('<':'!':'-':'-':'M':'A':'T':'H':xs)) =
  RawBlock "tex" $ take (length xs - 3) xs
fixmathBlock x = x

I installed the 64-bit OSX version of Haskell, and also gave the command cabal install pandoc to get the pandoc functions. However, upon executing

ghc --make fixmath.hs

I get the following error:

[1 of 1] Compiling Main             ( fixmath.hs, fixmath.o )

fixmath.hs:9:26:
    Couldn't match expected type `Format' with actual type `[Char]'
    In the pattern: "html"
    In the pattern:
      RawInline "html"
                ('<' : '!' : '-' : '-' : 'M' : 'A' : 'T' : 'H' : xs)
    In an equation for `fixmathInline':
        fixmathInline
          (RawInline "html"
                     ('<' : '!' : '-' : '-' : 'M' : 'A' : 'T' : 'H' : xs))
          = RawInline "tex" $ take (length xs - 3) xs

fixmath.hs:10:13:
    Couldn't match expected type `Format' with actual type `[Char]'
    In the first argument of `RawInline', namely `"tex"'
    In the expression: RawInline "tex"
    In the expression: RawInline "tex" $ take (length xs - 3) xs

fixmath.hs:14:24:
    Couldn't match expected type `Format' with actual type `[Char]'
    In the pattern: "html"
    In the pattern:
      RawBlock "html"
               ('<' : '!' : '-' : '-' : 'M' : 'A' : 'T' : 'H' : xs)
    In an equation for `fixmathBlock':
        fixmathBlock
          (RawBlock "html"
                    ('<' : '!' : '-' : '-' : 'M' : 'A' : 'T' : 'H' : xs))
          = RawBlock "tex" $ take (length xs - 3) xs

fixmath.hs:15:12:
    Couldn't match expected type `Format' with actual type `[Char]'
    In the first argument of `RawBlock', namely `"tex"'
    In the expression: RawBlock "tex"
    In the expression: RawBlock "tex" $ take (length xs - 3) xs

What's gone wrong and what can I do?

도움이 되었습니까?

해결책

Recent versions of pandoc changed the type of the "format" for RawBlock and RawInline. If you replace "html" and "tex" with (Format "html") and (Format "tex"), you should be okay. (Assuming there aren't other problems besides the one the compiler flagged.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top