diff options
| author | John MacFarlane <[email protected]> | 2025-03-29 19:31:19 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2025-03-29 19:31:19 -0700 |
| commit | 3adcb4bd8089cdb8408da5f17780cd49513b7cec (patch) | |
| tree | cbdf3f7e85f8414dae29e0754df6a5951f7c15c3 | |
| parent | 5de83a4cc53e6f11b375c498cc827996f42142e0 (diff) | |
Allow `groff` to be used as `--pdf-engine` with `ms`.
When `groff` is used as a PDF engine, the `groff` extension
to `ms` is automatically enabled.
Limitations:
- `groff` currently produces larger PDFs than `pdfroff`.
- With `groff`, a table of contents produced with
`--table-of-contents/--toc` will always be placed at the end of
the document.
- Certain characters (e.g. Greek characters) may be dropped in
the PDF outline.
Closes #10738.
| -rw-r--r-- | MANUAL.txt | 23 | ||||
| -rw-r--r-- | src/Text/Pandoc/App/CommandLineOptions.hs | 1 | ||||
| -rw-r--r-- | src/Text/Pandoc/PDF.hs | 19 |
3 files changed, 35 insertions, 8 deletions
diff --git a/MANUAL.txt b/MANUAL.txt index d03b342b4..fce4a4a0e 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -865,11 +865,14 @@ header when requesting a document from a URL: unless `-s/--standalone` is used, and it has no effect on `man`, `docbook4`, `docbook5`, or `jats` output. - Note that if you are producing a PDF via `ms`, the table + Note that if you are producing a PDF via `ms` and using + (the default) `pdfroff` as a `--pdf-engine`, the table of contents will appear at the beginning of the document, before the title. If you would prefer it to be at the end of the document, use the option - `--pdf-engine-opt=--no-toc-relocation`. + `--pdf-engine-opt=--no-toc-relocation`. If `groff` is + used as the `--pdf-engine`, the table of contents will + always appear at the end of the document. `--toc-depth=`*NUMBER* @@ -1456,11 +1459,11 @@ header when requesting a document from a URL: : Use the specified engine when producing PDF output. Valid values are `pdflatex`, `lualatex`, `xelatex`, `latexmk`, `tectonic`, `wkhtmltopdf`, `weasyprint`, `pagedjs-cli`, - `prince`, `context`, `pdfroff`, and `typst`. If the engine is not in - your PATH, the full path of the engine may be specified here. - If this option is not specified, pandoc uses the following - defaults depending on the output format specified using - `-t/--to`: + `prince`, `context`, `groff`, `pdfroff`, and `typst`. + If the engine is not in your PATH, the full path of the engine + may be specified here. If this option is not specified, + pandoc uses the following defaults depending on the output + format specified using `-t/--to`: - `-t latex` or none: `pdflatex` (other options: `xelatex`, `lualatex`, `tectonic`, `latexmk`) @@ -3854,6 +3857,12 @@ additional markers for paragraphs and alternative markup for emphasized text. The `emphasis-command` template variable is set if the extension is enabled. +### Extension: `groff` ### + +Enabling this extension with `ms` output will cause the `.pdfhref O` +macros to be formatted in the way `groff -Tpdf` likes, instead of +the way `pdfroff` likes. This extension is enabled automatically +when `groff` is used as a `--pdf-engine`. # Pandoc's Markdown diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs index 5e86b6421..e65bb65ae 100644 --- a/src/Text/Pandoc/App/CommandLineOptions.hs +++ b/src/Text/Pandoc/App/CommandLineOptions.hs @@ -222,6 +222,7 @@ engines = map ("html",) htmlEngines ++ map ("latex",) latexEngines ++ map ("beamer",) latexEngines ++ [ ("ms", "pdfroff") + , ("ms", "groff") , ("typst", "typst") , ("context", "context") ] diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs index 5896e2e84..ae6de706b 100644 --- a/src/Text/Pandoc/PDF.hs +++ b/src/Text/Pandoc/PDF.hs @@ -45,7 +45,8 @@ import Text.Pandoc.Definition import Text.Pandoc.Error (PandocError (PandocPDFProgramNotFoundError)) import Text.Pandoc.MIME (getMimeType) import Text.Pandoc.Options (HTMLMathMethod (..), WriterOptions (..)) -import Text.Pandoc.Extensions (disableExtension, Extension(Ext_smart)) +import Text.Pandoc.Extensions (enableExtension, disableExtension, + Extension(Ext_smart, Ext_groff)) import Text.Pandoc.Process (pipeProcess) import System.Process (readProcessWithExitCode) import Text.Pandoc.Shared (inDirectory, stringify, tshow) @@ -111,6 +112,22 @@ makePDF program pdfargs writer opts doc = ["-U" | ".PDFPIC" `T.isInfixOf` source] ++ paperargs ++ pdfargs generic2pdf program args source + "groff" -> do + source <- writer opts{ writerExtensions = + enableExtension Ext_groff + (writerExtensions opts) } doc + let paperargs = + case lookupContext "papersize" (writerVariables opts) of + Just s + | T.takeEnd 1 s == "l" -> ["-P-p" <> + T.unpack (T.dropEnd 1 s), "-P-l"] + | otherwise -> ["-P-p" <> T.unpack s] + Nothing -> [] + let args = ["-ms", "-Tpdf", + "-e", "-t", "-k", "-KUTF-8"] ++ + ["-U" | ".PDFPIC" `T.isInfixOf` source] ++ + paperargs ++ pdfargs + generic2pdf program args source baseProg -> do withTempDir "tex2pdf." $ \tmpdir' -> do #ifdef _WINDOWS |
