Skip to content

No table of content when choosing pdfroff as pdf engine. #5553

Closed

Description

@stevenleeS0ht

Pandoc Version: 2.7.2
Groff Version: 1.22.4

Command like that: pandoc --toc -s --pdf-engine=pdfroff hello.md -o hello.pdf.

Pandoc works fine with TeX engine. However, there is no table of content in groff.

Activity

  1. jgm commented on Jun 5, 2019

    @jgm
    Owner

    Looks like the groff ms .TC macro will add one.
    We just need to add something to the default template adding this if toc is set, probably.

  2. jgm commented on Jun 5, 2019

    @jgm
    Owner

    Well wait, it's there:

    $if(toc)$
    .TC
    $endif$
    
  3. jgm commented on Jun 5, 2019

    @jgm
    Owner

    Did you check the end of your document? Following groff custom, we added the .TC macro to the end, not the beginning. Perhaps we could change that.

  4. stevenleeS0ht commented on Jun 6, 2019

    @stevenleeS0ht
    Author

    Is there special requirement to my input markdown document? According to philosophy of Pandoc, every valid inputs are supposed to be generated to a no error output.

  5. mb21 commented on Jun 6, 2019

    @mb21
    Collaborator

    What was the input? A small test case (just a few lines) is ideal. If your input is large, try to whittle it down to a minimum working example.

    Finally, ask questions on pandoc-discuss and read the User's Guide.

  6. jgm commented on Jun 6, 2019

    @jgm
    Owner

    Again, let me ask: did you check the end of your document? the toc should be there.

  7. stevenleeS0ht commented on Jun 7, 2019

    @stevenleeS0ht
    Author

    @jgm Yes, there it is. But at the beginning I only see the few page in the front.

    In addition, the entry of "Table of content" didn't appear in the left entries bar. It would be nice I can rapidly goto table of content page by clicking the entry in the side bar.

  8. mb21 commented on Jun 7, 2019

    @mb21
    Collaborator

    For me, the following gives a table of contents on the second page:

    echo '# test' | pandoc --toc -s --pdf-engine=pdfroff -o out.pdf
    

    on macOS with:

    ~ pdfroff -v
    GNU pdfroff (groff) version 1.22.3
    
  9. jgm commented on Jun 7, 2019

    @jgm
    Owner

    So, if I understand correctly:

    • you do, in fact, get a table of contents
    • it is at the end of the document and you'd prefer it to be at the beginning (easily managed by using a custom template)
    • you'd like it to be included in the PDF's contents ("left entries bar"), along with the section headings, and it isn't.

    Is that all correct?

  10. stevenleeS0ht commented on Jun 8, 2019

    @stevenleeS0ht
    Author

    @jgm ,Yes, but for the toc left bar entry. It would be better to be unified with the other engine. The request to put table of content in front is much stronger than adding left side bar entry.

  11. jgm commented on Jun 8, 2019

    @jgm
    Owner

    Groff docs say:

    Macro: .TC [no]
    Prints the table of contents on a new page, setting the page number to i (Roman lowercase numeral > one). You should usually place this macro at the end of the file, since groff is a single-pass formatter > and can only print what has been collected up to the point that the TC macro appears.

    So moving it forward probably won't work (you'll get an empty toc).

  12. jgm commented on Jun 8, 2019

    @jgm
    Owner

    Wait, there's hope.
    This diff gives you both of the things you want:

    diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs
    index 4f232bf4f..5826f9856 100644
    --- a/src/Text/Pandoc/PDF.hs
    +++ b/src/Text/Pandoc/PDF.hs
    @@ -77,8 +77,8 @@ makePDF program pdfargs writer opts doc =
           liftIO $ html2pdf verbosity program pdfargs source
         "pdfroff" -> do
           source <- writer opts doc
    -      let args   = ["-ms", "-mpdfmark", "-e", "-t", "-k", "-KUTF-8", "-i",
    -                    "--no-toc-relocation"] ++ pdfargs
    +      let args   = ["-ms", "-mpdfmark", "-mspdf",
    +                    "-e", "-t", "-k", "-KUTF-8", "-i"] ++ pdfargs
           verbosity <- getVerbosity
           liftIO $ generic2pdf verbosity program args source
         baseProg -> do

    Two potential drawbacks of this change:

    • the TOC will appear at the very beginning of the document, before the title
    • pdfroff will run twice, which takes slightly longer

    I think on the whole it's probably a good change, though.

    With current pandoc, you can try adding

    --pdf-engine-opt=-mspdf
    

    This should give you the PDF bookmark for the table of contents, but it will still appear at the end.

  13. jgm commented on Jun 8, 2019

    @jgm
    Owner

    --no-toc-relocation was added in 0ae448e but the commit doesn't explain why.

  14. stevenleeS0ht commented on Jun 8, 2019

    @stevenleeS0ht
    Author

    @jgm , pdfroff is much faster than the other engine. As a result, speed issue is not problem.

    However, it would be a good idea if we communicate with groff community.

    This is just suggestion, It would be a good idea to absorb other users opinion.

  15. jgm commented on Jun 9, 2019

    @jgm
    Owner

    Not sure what you mean by "the other engine."
    We've always used pdfroff for conversion via ms.

    Anyway, as you may have noticed, I've made a change that gives you both the things you wanted, relocating the TOC to the beginning (this can be disabled, the manual explains how) and adding it to the PDF bookmarks. I don't see any reason to communicate with the groff community about this.

  16. stevenleeS0ht commented on Jun 11, 2019

    @stevenleeS0ht
    Author

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions