max-heller / mdbook-pandoc

A mdbook backend powered by Pandoc.
Apache License 2.0
98 stars 7 forks source link

Remove chapter heading #32

Closed nimo-labs closed 9 months ago

nimo-labs commented 9 months ago

Hi, I've just started experimenting with mdbook, mdbook-pandoc is fantastic compared to the other PDF renderers. However, I wondered if there was a way to remove the Chapter headings (highlighted in the attached image)?

After a some googling, it appears that it is possible to do so directly in Latex, however I'm not sure how I would implement this via mdbook-pandoc?

Ref 1 Ref 2

Thanks, Nick

mdbook-pandoc

max-heller commented 9 months ago

Hi Nick,

Pandoc has an option for this: --number-sections. Setting it to false should remove the chapter headings. You can set this in your configuration like so:

[output.pandoc.profile.pdf]
number-sections = false

This will remove section numbers everywhere else as well (e.g., the table of contents) -- if you don't want this, and just want to remove the headings from the start of each chapter, you can insert latex into the document header using Pandoc's header-includes variable. You can set this in your configuration like so (using the snippet from your second reference):

[output.pandoc.profile.pdf.variables]
header-includes = [
    '''
\usepackage{titlesec}

\titleformat{\chapter}[display]
  {\normalfont\bfseries}{}{0pt}{\Huge}
    '''
]

I'm happy to hear you're liking it!

nimo-labs commented 9 months ago

That's fantastic number-sections=false worked perfectly, thank you very much. It's also interesting to see an example of latex being directly injected via the [output.pandoc.profile.pdf.variables] section, that will be interesting to explore.

So far, I like it a lot. To the point that I spun up a quick Dockerfile to encapsulate it along with latex etc. https://github.com/nimo-labs/mdbook-pandoc-docker Thank you for creating it.

nimo-labs commented 9 months ago

Sorry to re-open the issue, but I've just tried the header-includes variant for completeness and pandoc quits with an error.

book.toml

[book]
authors = ["Nick"]
language = "en"
multilingual = false
src = "src"
title = "My First Book"

[output.pandoc.profile.pdf]
output = "output.pdf"
to = "latex"
header-includes = [
    '''
\usepackage{titlesec}

\titleformat{\chapter}[display]
  {\normalfont\bfseries}{}{0pt}{\Huge}
    '''
]

Error:

2023-12-22 17:43:22 [INFO] (mdbook::book): Book building has started
2023-12-22 17:43:22 [INFO] (mdbook::book): Running the pandoc backend
2023-12-22 17:43:22 [INFO] (mdbook::renderer): Invoking the "pandoc" renderer
Unknown option --header-includes.
Try pandoc --help for more information.
pandoc exited unsuccessfully
2023-12-22 17:43:22 [ERROR] (mdbook::renderer): Renderer exited with non-zero return code.
2023-12-22 17:43:22 [ERROR] (mdbook::utils): Error: Rendering failed
2023-12-22 17:43:22 [ERROR] (mdbook::utils):    Caused By: The "pandoc" renderer failed

This post https://stackoverflow.com/questions/57234214/pandoc-fails-to-embed-metadata-from-the-supplied-yaml-file appears to suggest that header-includes isn't available until V2.3, however, I'm using V3.0.1

max-heller commented 9 months ago

Sorry to re-open the issue, but I've just tried the header-includes variant for completeness and pandoc quits with an error.

header-includes is a variable, not an option, so it needs to be nested in a variables table. Try:

[output.pandoc.profile.pdf]
output = "output.pdf"
to = "latex"

[output.pandoc.profile.pdf.variables]
header-includes = [
    '''
\usepackage{titlesec}

\titleformat{\chapter}[display]
  {\normalfont\bfseries}{}{0pt}{\Huge}
    '''
]
nimo-labs commented 9 months ago

So it is, my apologies for not seeing what was right in front of me.