git.iko.soy/typeable/pandoc
on master help sign in
Allow creation of pdf via groff ms and pdfroff.
f0abbe7John MacFarlane
MANUAL.txt+8−6
@@ -21,11 +21,11 @@ write plain text, [Markdown], [CommonMark], [PHP Markdown Extra],
21[HTML5], [LaTeX] \(including [`beamer`] slide shows\), [ConTeXt], [RTF], [OPML],
21[HTML5], [LaTeX] \(including [`beamer`] slide shows\), [ConTeXt], [RTF], [OPML],
22[DocBook], [OpenDocument], [ODT], [Word docx], [GNU Texinfo], [MediaWiki
22[DocBook], [OpenDocument], [ODT], [Word docx], [GNU Texinfo], [MediaWiki
23markup], [DokuWiki markup], [ZimWiki markup], [Haddock markup],
23markup], [DokuWiki markup], [ZimWiki markup], [Haddock markup],
24−[EPUB] \(v2 or v3\), [FictionBook2], [Textile], [groff man] pages,
24+[EPUB] \(v2 or v3\), [FictionBook2], [Textile], [groff man], [groff ms],
25[Emacs Org mode], [AsciiDoc], [InDesign ICML], [TEI Simple], and [Slidy],
25[Emacs Org mode], [AsciiDoc], [InDesign ICML], [TEI Simple], and [Slidy],
26[Slideous], [DZSlides], [reveal.js] or [S5] HTML slide shows. It can also
26[Slideous], [DZSlides], [reveal.js] or [S5] HTML slide shows. It can also
27−produce [PDF] output on systems where LaTeX, ConTeXt, or `wkhtmltopdf` is
27+produce [PDF] output on systems where LaTeX, ConTeXt, `pdfroff`,
28−installed.
28+or `wkhtmltopdf` is installed.
29
29
30Pandoc's enhanced version of Markdown includes syntax for [footnotes],
30Pandoc's enhanced version of Markdown includes syntax for [footnotes],
31[tables], flexible [ordered lists], [definition lists], [fenced code blocks],
31[tables], flexible [ordered lists], [definition lists], [fenced code blocks],
@@ -83,6 +83,7 @@ Markdown can be expected to be lossy.
83[TWiki markup]: http://twiki.org/cgi-bin/view/TWiki/TextFormattingRules
83[TWiki markup]: http://twiki.org/cgi-bin/view/TWiki/TextFormattingRules
84[Haddock markup]: https://www.haskell.org/haddock/doc/html/ch03s08.html
84[Haddock markup]: https://www.haskell.org/haddock/doc/html/ch03s08.html
85[groff man]: http://man7.org/linux/man-pages/man7/groff_man.7.html
85[groff man]: http://man7.org/linux/man-pages/man7/groff_man.7.html
86+[groff ms]: http://man7.org/linux/man-pages/man7/groff_ms.7.html
86[Haskell]: https://www.haskell.org
87[Haskell]: https://www.haskell.org
87[GNU Texinfo]: http://www.gnu.org/software/texinfo/
88[GNU Texinfo]: http://www.gnu.org/software/texinfo/
88[Emacs Org mode]: http://orgmode.org
89[Emacs Org mode]: http://orgmode.org
@@ -201,9 +202,10 @@ if added to the template or included in any header file. The
201optionally be used for [citation rendering]. These are included
202optionally be used for [citation rendering]. These are included
202with all recent versions of [TeX Live].
203with all recent versions of [TeX Live].
203
204
204−Alternatively, pandoc can use ConTeXt or `wkhtmltopdf` to create a PDF.
205+Alternatively, pandoc can use ConTeXt, `wkhtmltopdf`, or
205−To do this, specify an output file with a `.pdf` extension,
206+`pdfroff` to create a PDF. To do this, specify an output file
207+with a `.pdf` extension, as before, but add `-t context`, `-t
206−as before, but add `-t context` or `-t html5` to the command line.
208+html5`, or `-t ms` to the command line.
207
209
208PDF output can be controlled using [variables for LaTeX] (if
210PDF output can be controlled using [variables for LaTeX] (if
209LaTeX is used) and [variables for ConTeXt] (if ConTeXt is used).
211LaTeX is used) and [variables for ConTeXt] (if ConTeXt is used).
pandoc.cabal+5−4
@@ -22,10 +22,11 @@ Description: Pandoc is a Haskell library for converting from one markup
22 it can write Markdown, reStructuredText, XHTML, HTML 5,
22 it can write Markdown, reStructuredText, XHTML, HTML 5,
23 LaTeX, ConTeXt, DocBook, OPML, TEI, OpenDocument, ODT,
23 LaTeX, ConTeXt, DocBook, OPML, TEI, OpenDocument, ODT,
24 Word docx, RTF, MediaWiki, DokuWiki, ZimWiki, Textile,
24 Word docx, RTF, MediaWiki, DokuWiki, ZimWiki, Textile,
25− groff man pages, plain text, Emacs Org-Mode, AsciiDoc,
25+ groff man, groff ms, plain text, Emacs Org-Mode, AsciiDoc,
26− Haddock markup, EPUB (v2 and v3), FictionBook2, InDesign ICML,
26+ Haddock markup, EPUB (v2 and v3), FictionBook2,
27+ InDesign ICML, Muse, and several kinds of
27− Muse, and several kinds of HTML/javascript slide shows (S5, Slidy,
28+ HTML/javascript slide shows (S5, Slidy, Slideous,
28− Slideous, DZSlides, reveal.js).
29+ DZSlides, reveal.js).
29 .
30 .
30 In contrast to most existing tools for converting Markdown
31 In contrast to most existing tools for converting Markdown
31 to HTML, pandoc has a modular design: it consists of a set of
32 to HTML, pandoc has a modular design: it consists of a set of
src/Text/Pandoc/App.hs+8−4
@@ -164,6 +164,7 @@ convertWithOpts opts = do
164 let laTeXOutput = format `elem` ["latex", "beamer"]
164 let laTeXOutput = format `elem` ["latex", "beamer"]
165 let conTeXtOutput = format == "context"
165 let conTeXtOutput = format == "context"
166 let html5Output = format == "html5" || format == "html"
166 let html5Output = format == "html5" || format == "html"
167+ let msOutput = format == "ms"
167
168
168 -- disabling the custom writer for now
169 -- disabling the custom writer for now
169 writer <- if ".lua" `isSuffixOf` format
170 writer <- if ".lua" `isSuffixOf` format
@@ -398,15 +399,18 @@ convertWithOpts opts = do
398 ByteStringWriter f -> f writerOptions doc' >>= writeFnBinary outputFile
399 ByteStringWriter f -> f writerOptions doc' >>= writeFnBinary outputFile
399 StringWriter f
400 StringWriter f
400 | pdfOutput -> do
401 | pdfOutput -> do
401− -- make sure writer is latex or beamer or context or html5
402+ -- make sure writer is latex, beamer, context, html5 or ms
402− unless (laTeXOutput || conTeXtOutput || html5Output) $
403+ unless (laTeXOutput || conTeXtOutput || html5Output ||
404+ msOutput) $
403 err 47 $ "cannot produce pdf output with " ++ format ++
405 err 47 $ "cannot produce pdf output with " ++ format ++
404 " writer"
406 " writer"
405
407
406 let pdfprog = case () of
408 let pdfprog = case () of
407 _ | conTeXtOutput -> "context"
409 _ | conTeXtOutput -> "context"
410+ | html5Output -> "wkhtmltopdf"
408− _ | html5Output -> "wkhtmltopdf"
411+ | html5Output -> "wkhtmltopdf"
412+ | msOutput -> "pdfroff"
409− _ -> optLaTeXEngine opts
413+ | otherwise -> optLaTeXEngine opts
410 -- check for pdf creating program
414 -- check for pdf creating program
411 mbPdfProg <- liftIO $ findExecutable pdfprog
415 mbPdfProg <- liftIO $ findExecutable pdfprog
412 when (isNothing mbPdfProg) $
416 when (isNothing mbPdfProg) $
src/Text/Pandoc/PDF.hs+32−1
@@ -74,7 +74,7 @@ changePathSeparators = intercalate "/" . splitDirectories
74
74
75makePDF :: MonadIO m
75makePDF :: MonadIO m
76 => String -- ^ pdf creator (pdflatex, lualatex,
76 => String -- ^ pdf creator (pdflatex, lualatex,
77− -- xelatex, context, wkhtmltopdf)
77+ -- xelatex, context, wkhtmltopdf, pdfroff)
78 -> (WriterOptions -> Pandoc -> PandocIO String) -- ^ writer
78 -> (WriterOptions -> Pandoc -> PandocIO String) -- ^ writer
79 -> WriterOptions -- ^ options
79 -> WriterOptions -- ^ options
80 -> Verbosity -- ^ verbosity level
80 -> Verbosity -- ^ verbosity level
@@ -106,6 +106,12 @@ makePDF "wkhtmltopdf" writer opts verbosity _ doc@(Pandoc meta _) = liftIO $ do
106 setVerbosity verbosity
106 setVerbosity verbosity
107 writer opts doc
107 writer opts doc
108 html2pdf verbosity args source
108 html2pdf verbosity args source
109+makePDF "pdfroff" writer opts verbosity _mediabag doc = liftIO $ do
110+ source <- runIOorExplode $ do
111+ setVerbosity verbosity
112+ writer opts doc
113+ let args = ["-ms", "-e", "-k", "-i"]
114+ ms2pdf verbosity args source
109makePDF program writer opts verbosity mediabag doc = do
115makePDF program writer opts verbosity mediabag doc = do
110 let withTemp = if takeBaseName program == "context"
116 let withTemp = if takeBaseName program == "context"
111 then withTempDirectory "."
117 then withTempDirectory "."
@@ -295,6 +301,31 @@ runTeXProgram verbosity program args runNumber numRuns tmpDir source = do
295 else return Nothing
301 else return Nothing
296 return (exit, out, pdf)
302 return (exit, out, pdf)
297
303
304+ms2pdf :: Verbosity
305+ -> [String]
306+ -> String
307+ -> IO (Either ByteString ByteString)
308+ms2pdf verbosity args source = do
309+ env' <- getEnvironment
310+ when (verbosity >= INFO) $ do
311+ putStrLn "[makePDF] Command line:"
312+ putStrLn $ "pdfroff " ++ " " ++ unwords (map show args)
313+ putStr "\n"
314+ putStrLn "[makePDF] Environment:"
315+ mapM_ print env'
316+ putStr "\n"
317+ putStrLn $ "[makePDF] Contents:\n"
318+ putStr source
319+ putStr "\n"
320+ (exit, out) <- pipeProcess (Just env') "pdfroff" args
321+ (UTF8.fromStringLazy source)
322+ when (verbosity >= INFO) $ do
323+ B.hPutStr stdout out
324+ putStr "\n"
325+ return $ case exit of
326+ ExitFailure _ -> Left out
327+ ExitSuccess -> Right out
328+
298html2pdf :: Verbosity -- ^ Verbosity level
329html2pdf :: Verbosity -- ^ Verbosity level
299 -> [String] -- ^ Args to wkhtmltopdf
330 -> [String] -- ^ Args to wkhtmltopdf
300 -> String -- ^ HTML5 source
331 -> String -- ^ HTML5 source
src/Text/Pandoc/Writers/Ms.hs+3−20
@@ -37,28 +37,11 @@ TODO:
37[ ] tight/loose list distinction
37[ ] tight/loose list distinction
38[ ] internal hyperlinks (this seems to be possible since
38[ ] internal hyperlinks (this seems to be possible since
39 they exist in the groff manual PDF version)
39 they exist in the groff manual PDF version)
40−[ ] better handling of accented characters and other non-ascii
41− characters (e.g. curly quotes).
42− Note: recent versions of groff (more recent than standard
43− on many systems) include a -k option which runs preconv.
44− preconv basically converts non-ascii characters
45− to \[uXXXX] entities. Since we can't assume that the local
46− groff has the -k option, we could have any invocation of
47− groff in Text.Pandoc.PDF filter the input through a Haskell
48− function that does what preconv does.
49− On the other hand: only recent groffs have -Tpdf. so
50− if we want compatibility with older groffs, we need to to
51− -Tps and pipe through ps2pdf (can we assume it's available?).
52− A big advantage of gropdf: it supports the tag
53− \X'pdf: pdfpic file alignment width height line-length'
54− and also seems to support bookmarks.
55− See also the pdfroff shell script that comes with more
56− recent versions of groff.
57−[ ] add via groff option to PDF module
58−[ ] better handling of images, perhaps converting to eps when
59− going to PDF?
60[ ] better template, with configurable page number, table of contents,
40[ ] better template, with configurable page number, table of contents,
61 columns, etc.
41 columns, etc.
42+[ ] support for images? gropdf (and maybe pdfroff) supports the tag
43+ \X'pdf: pdfpic file alignment width height line-length'
44+ and also seems to support bookmarks.
62-}
45-}
63
46
64module Text.Pandoc.Writers.Ms ( writeMs ) where
47module Text.Pandoc.Writers.Ms ( writeMs ) where