Skip to content

Commit

Permalink
feat: Add 'duplex_edge' argument to 'save_pamphlet()'
Browse files Browse the repository at this point in the history
* ``save_pamphlet()`` now supports the argument ``duplex_edge`` (desired two-sided printing edge)
  that controls how the second page is oriented.
  If "short" it is flipped up (the new default, easier to preview on computer)
  and if "long" it is flipped down (common two-sided printer setting).

Closes #74
  • Loading branch information
trevorld committed Jan 28, 2021
1 parent 6e2a62d commit ba77c42
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Encoding: UTF-8
Package: ppgames
Type: Package
Title: Piecepack Games
Version: 0.6.0-9
Version: 0.6.0-10
Author: Trevor L Davis.
Maintainer: Trevor L Davis <trevor.l.davis@gmail.com>
Description: This is an R package designed to make piecepack game diagrams.
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ New features

- "pass the food"

* ``save_pamphlet()`` now supports the argument ``duplex_edge`` (desired two-sided printing edge)
that controls how the second page is oriented.
If "short" it is flipped up (the new default, easier to preview on computer)
and if "long" it is flipped down (common two-sided printer setting) (#74).

Bug fixes and minor improvements
--------------------------------

Expand All @@ -30,6 +35,8 @@ Breaking Changes
* Interpretation of the ``game`` / ``book`` argument in ``save_ruleset``, ``save_pamphlet``, ``save_rulebook`` now
follows similar rules as the ``GameType`` argument in PPN,
in particular now use arguments like ``"American Checkers"`` instead of ``"american-checkers"``.
* By default ``save_pamphlet()`` now orients the second page up instead of down.
To restore prior behaviour (second page flipped down) manually set the argument ``duplex_edge`` to "long".

ppgames 0.5.1
=============
Expand Down
9 changes: 6 additions & 3 deletions R/rules.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ clean_game <- function(game) {
#' If \code{NULL} the function will guess a default.
#' @param size Paper size (either "letter", or "A4")
#' @param quietly Whether to hide document compilation output.
#' @param duplex_edge String specifying the desired duplex printing edge.
#' If "short" match the second page along its short edge (second page flipped up, easier to preview on computer)
#' and if "long" match along its long edge (second page flipped upside down, usual printer default).
#' @rdname save_ruleset
#' @export
save_ruleset <- function(game, gk = game_kit(), output = NULL,
Expand Down Expand Up @@ -82,7 +85,7 @@ save_ruleset <- function(game, gk = game_kit(), output = NULL,
#' @rdname save_ruleset
#' @export
save_pamphlet <- function(game, gk = game_kit(), output = NULL,
quietly = TRUE, size = "letter") {
quietly = TRUE, size = "letter", duplex_edge = "short") {

game <- clean_game(game)
if (is.null(output)) output <- paste0(game, ".pdf")
Expand All @@ -109,7 +112,7 @@ save_pamphlet <- function(game, gk = game_kit(), output = NULL,

game_info <- yaml::yaml.load_file(system.file("extdata", "game_info.yaml", package = "ppgames"))

knit_chapter <- function(game, gk = game_kit(), quietly = TRUE) {
knit_chapter <- function(game, gk = game_kit(), quietly = TRUE, size = "letter") {
output <- paste0(game, "-chapter.tex")

wd <- getwd()
Expand Down Expand Up @@ -150,7 +153,7 @@ save_rulebook <- function(book = "The Historical Piecepacker", gk = game_kit(),
games <- list.files(system.file("games", package = "ppgames"), pattern = ".Rtex")
games <- gsub(".Rtex", "", games)
for (game in games) {
knit_chapter(game, gk, quietly = quietly)
knit_chapter(game, gk, quietly, size)
}

of <- system.file(sprintf("books/%s.Rtex", book), package = "ppgames")
Expand Down
5 changes: 3 additions & 2 deletions inst/extdata/pamphlet.Rtex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
%% begin.rcode documentclass, echo=FALSE, results='asis'
cat(sprintf("\\documentclass[%spaper]{leaflet}\n",
tolower(size)))
tumble <- switch(duplex_edge, short = "notumble", "tumble")
cat(sprintf("\\documentclass[%s,%spaper]{leaflet}\n",
tumble, tolower(size)))
%% end.rcode

\usepackage[colorlinks]{hyperref}
Expand Down
7 changes: 6 additions & 1 deletion man/save_ruleset.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ba77c42

Please sign in to comment.