asciidoctor / asciidoctor-pdf

:page_with_curl: Asciidoctor PDF: A native PDF converter for AsciiDoc based on Asciidoctor and Prawn, written entirely in Ruby.
https://docs.asciidoctor.org/pdf-converter/latest/
MIT License
1.15k stars 500 forks source link

Margin for inner binding (recto/verso margins) #383

Closed rasusmilch closed 8 years ago

rasusmilch commented 8 years ago

Looking around through the theming website and bug tracker, I do not see a way to set an inner binding offset. I see a margin property that states it is the same as CSS, (eg, left, right, top and bottom.) I do see that the default book theme, asciidoctor-pdf -d book, alternates page numbers like a book, but the margins are still the same.

This is useful for books, or even reports, where some of the inner margin is lost due to the binding process (such as those report covers with the plastic rail, you easily lose a quarter inch or more.)

mojavelinux commented 8 years ago

Could you describe more specifically where the inner margin would be applied? A reference to a similar feature in another system is sufficient.

rasusmilch commented 8 years ago

In latex, specifically in the KOMA script , page 30-31, for BCOR option, (and other classes I believe, but I would need to look) you can set an additional offset for the inner margin. (I believe KOMA script is incorrect when they state "left" margin for BCOR and it really means "inside" margin. All my KOMA documents apply the BCOR to all pages correctly. The English documentation is translated from German, so there may be a misunderstanding.) The inner margin is where a spine is in a book. So if you are reading aright hand page in a book, the inner margin is on the left and disappears into the gutter, for a left hand page the inner margin is on the right.

Another way of looking at it is that the page numbers in a book (and within asciidoctor-pdf) appear on the outside of the book page, or outside margin. The inner (binding) margin is opposite the page numbers. As it stands now, asciidoctor-pdf applies the page numbers correctly to left and right hand pages, but I cannot adjust the inner margin as far as I can tell.

I believe it would be beneficial to allow an adjustment to this margin, much in the same way that KOMA script gives a class option for a binding correction. As mentioned above some cheap report covers chew up a lot of margin, and it would be beneficial to apply a correction to the inner margin to overcome that, else the page content is uncomfortably close to the binding side (where you have to pry the book apart to read the text.)

I have not looked at the code, but since most books consider the title page a right hand page, perhaps the convention could be to reterm the left and right margins as inside and outside margins. Then depending on the page when processed you apply the appropriate margin opposite the page number. I assume this code is already available since asciidoctor-pdf correctly places the page numbers in the correct margins. For a normally stapled report (left hand corner) or HTML, these margins could simply be set the same.

Understanding Book Layouts and Page Margins Page Margins Illogical Twoside Margins

EDIT: Clarified the page number in the documentation for KOMA script.

mraible commented 8 years ago

In order to print my InfoQ mini-book with Lulu, they need us to add margins to the PDF. They want gutter/inside at least 35mm/1.38in and an outside margin at least 25mm/1in. Is it possible to do this with a PdfExtensions file?

mojavelinux commented 8 years ago

I hadn't yet implemented recto/verso margins because, at the time, we didn't have a theme system and the focus was on desktop viewing (not printing). However, now that we have a theme system, we could easily accommodate this customization using a theme key. I might even be able to make it work with a separate key in the same theme file that is activated using an AsciiDoc attribute (e.g., media-print). That would certainly keep things simple and DRY.

mojavelinux commented 8 years ago

The inner margin is where a spine is in a book.

Aha! That's what I was looking for. So this request is for recto/verso margins for printing. I'll update the title accordingly.

mojavelinux commented 8 years ago

As it stands now, asciidoctor-pdf applies the page numbers correctly to left and right hand pages, but I cannot adjust the inner margin as far as I can tell.

That is correct. That is where we stand right now.

mojavelinux commented 8 years ago

I can't say for sure if this can be accomplished with an extension, but in theory it seems possible. We need to tap into the page create event in Prawn and change the margins on the page. (There's an on_page_create hook, but that might be too late to adjust margins. Another approach is to override the start_new_page method)

The Asciidoctor converter itself will be none the wiser since it doesn't really keep track of the dimensions of the page it's on. It just works with the canvas it has.

As with all things, I'm sure there are caveats we're going to have to address. Experimentation will reveal those challenges.

mojavelinux commented 8 years ago

It's unfortunate that Prawn doesn't provide a nice API handle this requirement. But we can make it happen regardless.

mojavelinux commented 8 years ago

I assume this code is already available since asciidoctor-pdf correctly places the page numbers in the correct margins.

That's a bit different since the running (header/footer) content is done in a separate pass working on pages that have already been laid down (using the repeater API).