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

Support non US-letter paper #24

Closed
eddelbuettel opened this Issue Sep 17, 2017 · 13 comments

Comments

Projects
None yet
3 participants
@eddelbuettel
Copy link
Owner

eddelbuettel commented Sep 17, 2017

PNAS being the Academy of the US, the layout assumes 8.5in by 11in paper. Which is not the standard in the rest of the world.

The code uses the very powerful LaTeX package geometry so there is no reason why a switch could not be added to support, say, a4 paper size. But someone with access to a printer with a4 needs to drive this.

@saghirb

This comment has been minimized.

Copy link
Contributor

saghirb commented Jun 8, 2018

I can try to help out as I have a printer with a4. I had a quick look at the code and see that the paper size is defined in the rmarkdown/templates/pdf/skeleton/pinp.cls as:

\RequirePackage[twoside,%
				letterpaper,includeheadfoot,%
				layoutsize={8.125in,10.875in},%
                layouthoffset=0.1875in,%
                layoutvoffset=0.0625in,%
                left=38.5pt,%
                right=43pt,%
                top=43pt,% 10pt provided by headsep
                bottom=32pt,%
                headheight=0pt,% No Header
                headsep=10pt,%
                footskip=25pt]{geometry}

I assumed that intent to make the paper size selection via the yaml header meaning that the pdf/resources/template.tex would need to be modified. Is there anything else that I should consider?

@eddelbuettel

This comment has been minimized.

Copy link
Owner Author

eddelbuettel commented Jun 8, 2018

Thanks for offering to help! If you know a little bit R, you should be able to follow the (sometimes a little byzantine) path from something declared in the YAML header, to possibly being processed by R, to eventually being used as variables in the template.tex (or class file).

You can look at one or two of the other variables in the YAML header and see what happens. If should be possible to set it in YAML, and then maybe have it called in template overriding the existing setting in pinp.cls.

@rstub

This comment has been minimized.

Copy link

rstub commented Jun 9, 2018

@saghirb See https://stackoverflow.com/a/50763865/8416610 for further pointers how other templates handle this.

@eddelbuettel

This comment has been minimized.

Copy link
Owner Author

eddelbuettel commented Jun 9, 2018

Or in pinp itself, the first line of template.tex is full of if/else:

\documentclass[$if(fontsize)$$fontsize$,$else$9pt,$endif$$if(one_column)$$if(lineno)$lineno,$endif$$else$twocolumn,$endif$$if(one_sided)$$else$twoside,$endif$printwatermark=$if(watermark)$$watermark$$else$false$endif$]{pinp}

Some values get intermediated by rmarkdown / boodown R code. I find that a little cleaner than R's direct setting.

@saghirb

This comment has been minimized.

Copy link
Contributor

saghirb commented Jun 11, 2018

Thanks @rstub & @eddelbuettel .

I've implemented something based on what you both wrote. Now papersize can be declared in the YAML header and it will be automatically processed as part of the documentclass options (i.e. removed from the LaTeX geometry package options in the pinp.cls file).

Any valid paper name can be used but there is an issue with the page layouts as they still are based on letterpaper settings. I tried to conditionally adjust the settings for a4paper but with the current implementation via papersize it is not possible due to, I believe, pandoc not handling conditional selections (see this link).

I think that a quick fix could be to define letterpaper in the YAML header and as TRUE for letter paper and FALSE A4 paper. I don't like this option as it moves away from users are used with setting papersize.

I have not sent a pull request (I can do should you wish) but you can see the changes that I have made at my fork repository:

Any comments, suggestions or pointers?

@eddelbuettel

This comment has been minimized.

Copy link
Owner Author

eddelbuettel commented Jun 11, 2018

I'm lost, what are you trying to say with that StackOverflow link? That is just a question, ie conjecture, with a downvoted answer.

Having a boolean which can select usletter (default) and a4paper is better than just usletter.

@rstub

This comment has been minimized.

Copy link

rstub commented Jun 11, 2018

I would prefer

papersize: letter/a4

over

papersize: letterpaper/a4paper

in the YAML headers, just like it is with the standard template. In the template that would mean:

$if(papersize)$$papersize$paper,$endif$

I have also removed the $else$ since letterpaper is the default for extarticle.cls anyway.

Concerning layout a first step would be to make them relative to the selected papersize, i.e.:

\RequirePackage[twoside,%
		includeheadfoot,%
		layoutsize={0.95588\paperwidth,0.98864\paperheight},%
                layouthoffset=0.02206\paperwidth,%
                layoutvoffset=0.00568\paperheight,%
                left=38.5pt,%
                right=43pt,%
                top=43pt,% 10pt provided by headsep
                bottom=32pt,%
                headheight=0pt,% No Header
                headsep=10pt,%
footskip=25pt]{geometry}

For letterpaper this should not change the layout. How good this looks with a4paper needs testing.

@saghirb

This comment has been minimized.

Copy link
Contributor

saghirb commented Jun 11, 2018

@eddelbuettel sorry I missed the downvote (force of habit of filtering out likes, etc which I should not do on SO).

@saghirb

This comment has been minimized.

Copy link
Contributor

saghirb commented Jun 11, 2018

@rstub thanks for your comment. Indeed it I should be working with "relative" layout values. You can set:

papersize: letter/a4

The geometrylayout options have to be set in template.tex. I did not find a way to do it in pinp.cls.

My forked version is up to date. I will issues a pull request.

The a4 paper version looks fine to me. Although using the pinp vignette might not be the best due to the graph that starts the second page.
pinp-a4paper.pdf

@eddelbuettel

This comment has been minimized.

Copy link
Owner Author

eddelbuettel commented Jun 11, 2018

Yes, I gave found the pinp.cls to be pretty demanding on the content to make the white space look good so not surprised the a4 pdf looks the way it does. Thanks for posting that by the way.

PR looks good too at a first glance.

@rstub

This comment has been minimized.

Copy link

rstub commented Jun 11, 2018

I think the A4 layout looks fine.

Concerning the placement of \geometry{...}: Did you try putting it in pinp.cls after the \RequirePackage[...]{geometry}?

@eddelbuettel

This comment has been minimized.

Copy link
Owner Author

eddelbuettel commented Jun 12, 2018

Fixed in #54

@saghirb

This comment has been minimized.

Copy link
Contributor

saghirb commented Jun 12, 2018

@rstub Yes that is what I tried first (and just double checked) and the layout reverts to letter paper setting. I followed it up further and opted for this "quicker" fix. I would prefer it to be part of pinp.clstoo and I will look into it again when I try to make the rest of the layout settings relative to paper size. I'll issue that as a separate pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.