Using pandoc as a library to create a PDF file

Part of the project I'm working on involves creating a PDF file using Pandoc. I have a part of a program that makes PDF. To figure out how to do this, I am trying to change fuel.hsfrom JGM BayHack 2014 .

However, I have difficulties. I have the following function:

export :: (MonadIO m) => Pandoc -> m (Either BL.ByteString BL.ByteString)
export = liftIO . makePDF "xelatex" writeLaTeX  def { writerStandalone = True } 

In the body of my modified fuel. hs

  pdfbytes <- export letter
  print pdfbytes

I get the following output:

$ stack runghc fuel.hs
Run from outside a project, using implicit global project config
Using resolver: lts-3.7 from implicit global project config file: /home/stevejb/.stack/global/stack.yaml
Left "! Emergency stop.\n<*> /tmp/tex2pdf.8283/input.tex\n                               \nNo pages of output.\nTranscript written on /tmp/tex2pdf.8283/input.log.\n"
"Fail"

However, the referenced log file does not exist. I am not sure how to debug this. I have xelatex installed.


+4
source share
1 answer

#haskell IRC ​​ . LaTeX. , :

export :: (MonadIO m) => String ->  Pandoc -> m (Either BL.ByteString BL.ByteString)
export tmpl pdoc = liftIO $ makePDF "xelatex" writeLaTeX (def { writerStandalone = True, writerTemplate = tmpl}) pdoc

getLetter  = do
  json <- BL.readFile "cng_fuel_chicago.json"
  let letter = case decode json of
                    Just stations -> createLetter [s | s <- stations,
                                        "Voyager" `elem` cardsAccepted s]
                    Nothing       -> error "Could not decode JSON"
  return $ letter


main :: IO ()
main = do
  letter <- getLetter
  temp <- readFile "template.tex"
  let str_should_have_something = writeLaTeX (def {writerStandalone = True, writerTemplate = temp}) letter
  print str_should_have_something
  mybytes <- export temp letter

  case mybytes of Right b -> BL.writeFile "mypdf.pdf" b
                  Left  _ -> putStrLn "Export error"

, Pandoc :

pandoc -D latex > template.tex

, Pandoc, , cabal . , .


gist .

+9

Source: https://habr.com/ru/post/1621903/


All Articles