Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make page break before sections configurable #74

Closed
mojavelinux opened this issue Dec 12, 2014 · 16 comments
Closed

Make page break before sections configurable #74

mojavelinux opened this issue Dec 12, 2014 · 16 comments
Assignees
Milestone

Comments

@mojavelinux
Copy link
Member

Make the page break behavior before sections configurable via the theme. The theme should be able to dictate which headings trigger an automatic page break.

@mojavelinux
Copy link
Member Author

Currently, page breaks occur before level-1 sections (chapters) when the doctype is book. However, they do not occur for level-0 sections (parts).

When the doctype is article, page breaks do not occur at all.

We'll need to think about how to express this.

@cascer1
Copy link

cascer1 commented Sep 2, 2016

I would love to be able to specify in my theme where breaks should and shouldn't go. Something like:

page:
  heading-1:
    break:
      before: true
      after: false

@mojavelinux
Copy link
Member Author

I'm aiming to make the theme as faithful to and familiar as CSS as possible. Therefore, I'd like to draw on the properties defined in the CSS page spec.

See https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Pages

So it might be something like:

heading:
  h1:
    page_break_after: always
    page_break_before: auto

One problem we have is with identifying terminology. Right now we use "heading" and "h1", but not "chapter". In AsciiDoc, an h2 isn't always a chapter and an h1 isn't always a part. So we'll probably need to add those keywords to compliment h1, h2, etc, which are the general "bridge heading" case.

@cascer1
Copy link

cascer1 commented Sep 2, 2016

Hmm, that format does make more sense. Will it still be possible to define the breaking behavior of any heading type (h1, h2..) as well as things such as chapter and heading?

I use a tool that automatically generates an asciidoc based on another input and I can't modify it to use "header" or "chapter" tags, so I'd love to see both implemented.

@mojavelinux
Copy link
Member Author

Yes, my suggestion is additive. My point is that there's no way to target chapters and parts just by heading level. These are inherent structures in AsciiDoc and we need to have a way to refer to them.

@Omnipresent
Copy link

If I have a asciidoc like this

== Section 1
Some text
== Section 2
Some text
== Section 3
Some text

Is there any way to add page break between each section so that each section starts on a new page in a PDF?

@jstrickler
Copy link

jstrickler commented May 23, 2017 via email

@Omnipresent
Copy link

Thanks!

@mojavelinux
Copy link
Member Author

👍

@RazrFalcon
Copy link

Will be very useful.

@mojavelinux
Copy link
Member Author

mojavelinux commented Aug 14, 2019

Currently, there are two page breaks. One before a part and one before a chapter. I think the simplest thing to do here is to be able to control them. Let's use the following two theme keys:

  • heading_part_break_before
  • heading_chapter_break_before

A value of "auto" will disable the forced break (letting it break naturally, if the end of the page has been reached). The default value is "always" (which essentially mean force).

Here's an example of how to disable the page break before chapters (but leave the one for parts):

heading:
  chapter_break_before: auto

Since the page break before a chapter can be configured, we should also allow the page break after a part to be configured (essentially the break between the part title / intro and chapter).

  • heading_part_break_after

By default, this one will be auto. It can be set to always.

mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Aug 14, 2019
mojavelinux added a commit to mojavelinux/asciidoctor-pdf that referenced this issue Aug 16, 2019
@mojavelinux
Copy link
Member Author

Setting the before breaks to auto will disable the calls to start_new_chapter and start_new_part, respectively. The sole purpose of these methods is to create the page break, so they are only relevant when that's enabled.

@VannTen
Copy link

VannTen commented Sep 10, 2021

I'm aiming to make the theme as faithful to and familiar as CSS as possible. Therefore, I'd like to draw on the properties defined in the CSS page spec.

See https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Pages

So it might be something like:

heading:
  h1:
    page_break_after: always
    page_break_before: auto

One problem we have is with identifying terminology. Right now we use "heading" and "h1", but not "chapter". In AsciiDoc, an h2 isn't always a chapter and an h1 isn't always a part. So we'll probably need to add those keywords to compliment h1, h2, etc, which are the general "bridge heading" case.

Is that syntax still envisaged ? As far as I can tell I can't configure a page break for a h3, can I ? I'm not quite sure what the relation are between this and the part and chapter terminology.

@Johan1974
Copy link

This function works fine and i can set a page break allways before a h2 title. No problem there.
What i do see is the h3 title does not break when it near the last line. I do not want a forced break for every h3 as some are higher in the page and does not need a break. Is there a way i can say break only when under a certain limit of the page?
So for example when text reaches the last quarter of the page?

Johan

@cod3licious
Copy link

I have a theme with:

extends: base
page:
  layout: portrait
  margin: [2cm, 2.5cm, 2cm, 2.5cm]
  size: A4
heading:
  chapter-break-before: always
  part-break-before: always

but I don't get any page breaks between chapters or anything... am I missing something?

@gregorko
Copy link

gregorko commented Nov 23, 2021

It seems the break settings only works for doctype book...

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

No branches or pull requests

9 participants