mbutterick/quad

how to select page size?

odanoburu opened this issue · 8 comments

I can see that page size is selected in

quad/quadwriter/core.rkt

Lines 596 to 598 in 28a80a6

(define default-page-size (case (current-locale)
[(us) "letter"]
[else "a4"]))

however I can't seem to be able to produce anything that is not letter size.

I trying running racket as LC_ALL=en_GB racket doc.quad.md, I tried parameterizing current-locale in a call: (parameterize ([current-locale "jp"]) (render-pdf doc "~/untitled.pdf" #:replace #t)), and I tried shadowing the value of default-page-size: (let ((default-page-size "a4")) (render-pdf doc "~/untitled.pdf" #:replace #t)).

of course, this is just me showing how rusty my racket is; I guess the second attempt would not work because default-page-size would have already been set, and the latter attempt wouldn't work because the default-page-size used by render-pdf would be the one private to the quadwriter/core module.

I'm checking the page size information like this:

[odanoburu ~]$ pdfinfo untitled.pdf                                                                                                                                                                         
Creator:        PITFALL
Producer:       PITFALL
Tagged:         no
UserProperties: no
Suspects:       no
Form:           none
JavaScript:     no
Pages:          2
Encrypted:      no
Page size:      612 x 792 pts (letter)
Page rot:       0
File size:      26774 bytes
Optimized:      no
PDF version:    1.3

I don't mind not having a way of doing it from the source file yet, but specifying it from the render-pdf function would be nice; would that be ok to have implemented?

for it to be in the source file in the case where the user is writing in markdown would complicate matters, right? you were thinking something like this?

#lang quadwriter/markdown
#:page-size a4

--- document begins after first blank line not starting with a #
# lorem ipsum

The render-pdf function looks for a page-size key in doc, which you can add if it doesn’t exist by wrapping it with a little extra markup:

`(q ((page-size "a4")) ,doc)

I’m not averse to considering a keyword argument, but 1) does that mean every possible markup key should also be duplicated as a keyword argument? 2) if the keyword argument and the markup disagree, which takes precedence?

Simplest working example:

#lang racket
(require quadwriter/core)
(render-pdf '(q ((page-size "a4")) "Hello world") "foo.pdf")

I guess if the user will have the trouble of using render-pdf they can make doc suit their needs, so I'd say no keyword necessary! (although having a way of specifying things like this in the source file will be convenient when quad gets more production ready)

thanks for the MWE, I've been able to have my document have an A4 page size now!

should we close this?

thanks for the MWE, I've been able to have my document have an A4 page size now!

now that I've taken another look I think that that might not have worked as well as I thought it did; I had a sizeable doc from a markdown document, then simply mutated it to have a (page-size "a4") element in the attribute list, and ran render-pdf. However I think that might have kept things like text width smaller than they should have been; is my impression right?

and I have a doubt: how is the page size chosen? I thought it depended on (current-locale), but mine seems to be an empty string, which should've yield an A4 size. (but that's actually the default page size, right?)

However I think that might have kept things like text width smaller than they should have been

Well, when you choose a bigger page size, the text will not change its point size, so it may look comparatively smaller in the preview. Or do you mean something different?

how is the page size chosen? I thought it depended on (current-locale)

No, nothing depends on (current-locale) (I think I probably shouldn’t use it, because it would make quad source files render differently when moved across national borders). For now it’s just the page-size attribute.

BTW I just pushed a change that lets you specify a page size directly in the quadwriter/markdown source, like so:

#lang quadwriter/markdown

#:page-size A4

Hello world

The #:page-size A4 (and any other keyword / value pairs) will be interpreted as an attribute that wraps the whole document (and this will show up in the doc for that source file)

Or do you mean something different?

I thought that horizontal margins were selected according to page-size, but empirically it doesn't seem to be the case!

(I think I probably shouldn’t use it, because it would make quad source files render differently when moved across national borders).

yes, that makes sense!

BTW I just pushed a change that lets you specify a page size directly in the quadwriter/markdown source

thanks, that works great!