Skip to content

Commit

Permalink
Use libpaper 2 instead of non-portable locale call to get default pap…
Browse files Browse the repository at this point in the history
…er size

libpaper also allows the user to configure the default paper size.

Since libpaper supports sizes unknown to the geometry package, always supply
the dimensions rather than trying to use the name, but print the name in
--help.

This fixes issue #48.
  • Loading branch information
rrthomas committed Jun 15, 2023
1 parent d9fa860 commit b615592
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ For those scripts and for more information on them, please now see
- A working, up-to-date installation of LaTeX (including at least one of
`pdflatex`, `lualatex` or `xelatex`)
- A working installation of the LaTeX package
[**pdfpages**](http://www.ctan.org/tex-archive/macros/latex/contrib/pdfpages)
[**pdfpages**](https://www.ctan.org/tex-archive/macros/latex/contrib/pdfpages)
(version 0.4f or later)
and
[**geometry**](http://www.ctan.org/tex-archive/macros/latex/contrib/geometry).
[**geometry**](https://www.ctan.org/tex-archive/macros/latex/contrib/geometry).

With [libpaper](https://github.com/rrthomas/libpaper) version 2 or later installed, `pdfjam` will be able to find your default paper size, which you can configure if desired.

For some years now, **pdfjam** has been included in the _TeX Live_ distribution,
which includes all the necessary programs and packages to make `pdfjam` run smoothly.
Expand Down
29 changes: 13 additions & 16 deletions bin/pdfjam
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,19 @@ suffix='pdfjam' ## Default filename suffix to be used when
##
preamble='' ## Default LaTeX preamble string.
##
## Guess default paper size from locale if possible, otherwise A4
##
if command -v locale >/dev/null ; then
paperheight=$(locale -k LC_PAPER | sed -e '1!d' -e 's/.*=//') ;
case $paperheight in
297)
paper='a4paper' ;
;;
279)
paper='letterpaper' ;
;;
*)
paper='a4paper' ;
;;
esac
else paper='a4paper' ; ## fallback paper size is ISO A4
## Get default paper size from libpaper >= 2 if possible, otherwise guess A4
##
if command -v paper >/dev/null ; then
paperspec=$(paper)
paperdimensions=$(echo "$paperspec" | cut -f 2 -d " ")
paperunit=$(echo "$paperspec" | cut -f 3 -d " ")
if test "$paperunit" = "pt"; then paperunit=bp; fi
paperwidth=$(echo "$paperdimensions" | cut -f 1 -d "x")
paperheight=$(echo "$paperdimensions" | cut -f 2 -d "x")
papersize="papersize={$paperheight$paperunit,$paperwidth$paperunit}"
paper='' ## We might not have a LaTeX-compatible name
else
paper='a4paper' ## fallback paper size is ISO A4
fi
##
## END OF SETTINGS MADE DIRECTLY WITHIN THE SCRIPT
Expand Down

0 comments on commit b615592

Please sign in to comment.