git.iko.soy/typeable/pandoc
on master help sign in
Allow creation of pdf via groff ms and pdfroff.

pandoc -t ms -o output.pdf input.txt

commitf0abbe7533db3e2c14066bddbb5d52ade1ef0685 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 23 Mar 2017, 21:24 (10 years ago) parentffd6993
5 files changed+56−35
MANUAL.txt+8−6 pandoc.cabal+5−4 src/Text/Pandoc/App.hs+8−4 src/Text/Pandoc/PDF.hs+32−1 src/Text/Pandoc/Writers/Ms.hs+3−20
MANUAL.txt+8−6
@@ -21,11 +21,11 @@ write plain text, [Markdown], [CommonMark], [PHP Markdown Extra],
2121[HTML5], [LaTeX] \(including [`beamer`] slide shows\), [ConTeXt], [RTF], [OPML],
2222[DocBook], [OpenDocument], [ODT], [Word docx], [GNU Texinfo], [MediaWiki
2323markup], [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],
2525[Emacs Org mode], [AsciiDoc], [InDesign ICML], [TEI Simple], and [Slidy],
2626[Slideous], [DZSlides], [reveal.js] or [S5] HTML slide shows. It can also
27−produce [PDF] output on systems where LaTeX, ConTeXt, or `wkhtmltopdf` is
28−installed.
27+produce [PDF] output on systems where LaTeX, ConTeXt, `pdfroff`,
28+or `wkhtmltopdf` is installed.
2929
3030Pandoc's enhanced version of Markdown includes syntax for [footnotes],
3131[tables], flexible [ordered lists], [definition lists], [fenced code blocks],
@@ -83,6 +83,7 @@ Markdown can be expected to be lossy.
8383[TWiki markup]: http://twiki.org/cgi-bin/view/TWiki/TextFormattingRules
8484[Haddock markup]: https://www.haskell.org/haddock/doc/html/ch03s08.html
8585[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
8687[Haskell]: https://www.haskell.org
8788[GNU Texinfo]: http://www.gnu.org/software/texinfo/
8889[Emacs Org mode]: http://orgmode.org
@@ -201,9 +202,10 @@ if added to the template or included in any header file. The
201202optionally be used for [citation rendering]. These are included
202203with all recent versions of [TeX Live].
203204
204−Alternatively, pandoc can use ConTeXt or `wkhtmltopdf` to create a PDF.
205−To do this, specify an output file with a `.pdf` extension,
206−as before, but add `-t context` or `-t html5` to the command line.
205+Alternatively, pandoc can use ConTeXt, `wkhtmltopdf`, or
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
208+html5`, or `-t ms` to the command line.
207209
208210PDF output can be controlled using [variables for LaTeX] (if
209211LaTeX 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
2222 it can write Markdown, reStructuredText, XHTML, HTML 5,
2323 LaTeX, ConTeXt, DocBook, OPML, TEI, OpenDocument, ODT,
2424 Word docx, RTF, MediaWiki, DokuWiki, ZimWiki, Textile,
25− groff man pages, plain text, Emacs Org-Mode, AsciiDoc,
26− Haddock markup, EPUB (v2 and v3), FictionBook2, InDesign ICML,
27− Muse, and several kinds of HTML/javascript slide shows (S5, Slidy,
28− Slideous, DZSlides, reveal.js).
25+ groff man, groff ms, plain text, Emacs Org-Mode, AsciiDoc,
26+ Haddock markup, EPUB (v2 and v3), FictionBook2,
27+ InDesign ICML, Muse, and several kinds of
28+ HTML/javascript slide shows (S5, Slidy, Slideous,
29+ DZSlides, reveal.js).
2930 .
3031 In contrast to most existing tools for converting Markdown
3132 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
164164 let laTeXOutput = format `elem` ["latex", "beamer"]
165165 let conTeXtOutput = format == "context"
166166 let html5Output = format == "html5" || format == "html"
167+ let msOutput = format == "ms"
167168
168169 -- disabling the custom writer for now
169170 writer <- if ".lua" `isSuffixOf` format
@@ -398,15 +399,18 @@ convertWithOpts opts = do
398399 ByteStringWriter f -> f writerOptions doc' >>= writeFnBinary outputFile
399400 StringWriter f
400401 | pdfOutput -> do
401− -- make sure writer is latex or beamer or context or html5
402− unless (laTeXOutput || conTeXtOutput || html5Output) $
402+ -- make sure writer is latex, beamer, context, html5 or ms
403+ unless (laTeXOutput || conTeXtOutput || html5Output ||
404+ msOutput) $
403405 err 47 $ "cannot produce pdf output with " ++ format ++
404406 " writer"
405407
406408 let pdfprog = case () of
407409 _ | conTeXtOutput -> "context"
408− _ | html5Output -> "wkhtmltopdf"
409− _ -> optLaTeXEngine opts
410+ | html5Output -> "wkhtmltopdf"
411+ | html5Output -> "wkhtmltopdf"
412+ | msOutput -> "pdfroff"
413+ | otherwise -> optLaTeXEngine opts
410414 -- check for pdf creating program
411415 mbPdfProg <- liftIO $ findExecutable pdfprog
412416 when (isNothing mbPdfProg) $
src/Text/Pandoc/PDF.hs+32−1
@@ -74,7 +74,7 @@ changePathSeparators = intercalate "/" . splitDirectories
7474
7575makePDF :: MonadIO m
7676 => String -- ^ pdf creator (pdflatex, lualatex,
77− -- xelatex, context, wkhtmltopdf)
77+ -- xelatex, context, wkhtmltopdf, pdfroff)
7878 -> (WriterOptions -> Pandoc -> PandocIO String) -- ^ writer
7979 -> WriterOptions -- ^ options
8080 -> Verbosity -- ^ verbosity level
@@ -106,6 +106,12 @@ makePDF "wkhtmltopdf" writer opts verbosity _ doc@(Pandoc meta _) = liftIO $ do
106106 setVerbosity verbosity
107107 writer opts doc
108108 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
109115makePDF program writer opts verbosity mediabag doc = do
110116 let withTemp = if takeBaseName program == "context"
111117 then withTempDirectory "."
@@ -295,6 +301,31 @@ runTeXProgram verbosity program args runNumber numRuns tmpDir source = do
295301 else return Nothing
296302 return (exit, out, pdf)
297303
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+
298329html2pdf :: Verbosity -- ^ Verbosity level
299330 -> [String] -- ^ Args to wkhtmltopdf
300331 -> String -- ^ HTML5 source
src/Text/Pandoc/Writers/Ms.hs+3−20
@@ -37,28 +37,11 @@ TODO:
3737[ ] tight/loose list distinction
3838[ ] internal hyperlinks (this seems to be possible since
3939 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?
6040[ ] better template, with configurable page number, table of contents,
6141 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.
6245-}
6346
6447module Text.Pandoc.Writers.Ms ( writeMs ) where