summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2024-05-09 19:24:35 +0000
committerKarl Berry <karl@freefriends.org>2024-05-09 19:24:35 +0000
commitd169edd133559570bfd9f10d0d0d0a19f7740761 (patch)
treecc435a303bfb5a7865af7c05b2d3869a89ce5453 /Master/texmf-dist/scripts
parent7004bab657376cab30c93b8bce0946c1b820ba98 (diff)
pdfjam (9may24)
git-svn-id: svn://tug.org/texlive/trunk@71219 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts')
-rwxr-xr-xMaster/texmf-dist/scripts/pdfjam/pdfjam498
1 files changed, 264 insertions, 234 deletions
diff --git a/Master/texmf-dist/scripts/pdfjam/pdfjam b/Master/texmf-dist/scripts/pdfjam/pdfjam
index 6f9da93d383..814da495996 100755
--- a/Master/texmf-dist/scripts/pdfjam/pdfjam
+++ b/Master/texmf-dist/scripts/pdfjam/pdfjam
@@ -1,11 +1,11 @@
#!/bin/sh
-version=3.10
+version=3.11
#########################################################################
## ##
## pdfjam: A shell-script interface to the "pdfpages" LaTeX package ##
## ------ ##
## ##
-## Author: David Firth (http://warwick.ac.uk/dfirth) ##
+## Author: David Firth (https://warwick.ac.uk/dfirth) ##
## ##
## Usage: see https://github.com/rrthomas/pdfjam ##
## or "pdfjam --help" ##
@@ -27,13 +27,255 @@ version=3.10
## ##
#########################################################################
##
+## PRELIMINARIES
+##
+## First determine:
+## --- whether verbose commentary should be provided (not if --quiet
+# or --configpath was specified);
+## --- whether this call to pdfjam is a "batch" call;
+## --- whether just the help text is required;
+## --- or whether all configuration files should be ignored.
+##
+verbose=true
+for arg
+do
+ case $arg in
+ --quiet | -q | --configpath)
+ verbose=false ;
+ ;;
+ --version | -V)
+ echo "$version"
+ exit 0 ;
+ ;;
+ --batch)
+ batch=true ;
+ ;;
+ --vanilla)
+ vanilla=true ;
+ ;;
+ *)
+ ;;
+ esac
+done
+##
+## Check to see whether this is a "secondary" call to pdfjam:
+##
+if test -z "$PDFJAM_CALL_NUMBER" ## not a secondary call
+then
+ PDFJAM_CALL_NUMBER=0
+fi
+##
+## Keep a copy of the internal file separator, so we can change it safely
+##
+OIFS="$IFS"
+##
+## Record the full filename of the current working diractory
+##
+pwd=$(pwd)
+##
+## Trap interrupts so that they kill everything:
+##
+trap 'IFS=$OIFS; exit 1' 1 2 15
+##
+## The following will be useful for readability of the script:
+##
+newline='
+'
+##
+## Define a function to escape tricky characters in file names etc:
+##
+escape_chars () {
+ (printf "%s" "${1}" | sed 's/[^a-zA-Z0-9._/\-]/\\&/g')
+}
+##
+## Define a function to output verbose comments:
+##
+prattle () { ## second argument here is non-null for continuation lines
+ if test $verbose = true; then
+ prefix1=" pdfjam:" ;
+ prefix2=$(printf "%s" "$prefix1" | sed 's/pdfjam:/ /') ;
+ indent="" ;
+ if test "$PDFJAM_CALL_NUMBER" -gt 0 &&
+ test "$batch" != true
+ then
+ indent=" "
+ fi
+ IFS="$newline" ;
+ lineCounter=0 ;
+ for line in ${1}
+ do
+ lineCounter=$((lineCounter + 1)) ;
+ if test $lineCounter -eq 1 && test ! -n "${2}" ;
+ then
+ if test -w "$PDFJAM_MESSAGES_FILE"
+ then printf "$prefix1$indent %s\n" "$line" >> \
+ "$PDFJAM_MESSAGES_FILE"
+ else messages="$messages$prefix1$indent $line$newline"
+ ## msg file not made yet
+ fi
+ else
+ if test -w "$PDFJAM_MESSAGES_FILE"
+ then printf "$prefix2$indent %s\n" "$line" >> \
+ "$PDFJAM_MESSAGES_FILE"
+ else messages="$messages$prefix2$indent $line$newline"
+ ## msg file not made yet
+ fi
+ fi ;
+ done ;
+ IFS="$OIFS" ;
+ fi ;
+ return ;
+}
+##
+## And here's the first piece of verbose commentary:
+##
+prattle "----" 1
+prattle "This is pdfjam version ${version}."
+##
+#########################################################################
+##
+## CONFIGURATION
+##
+## THESE SETTINGS WILL BE OVERRIDDEN by any found in configuration
+## files. By default such files are found at any or all of
+## /etc/pdfjam.conf
+## /usr/share/etc/pdfjam.conf
+## /usr/local/share/pdfjam.conf
+## /usr/local/etc/pdfjam.conf
+## $HOME/.pdfjam.conf
+## (And they are read in that order; if a setting is made more than
+## once, the last instance prevails.)
+##
+## An example configuration file can be found at
+## https://github.com/rrthomas/pdfjam
+##
+## The path searched for site-wide configuration files can be changed
+## by editing the variable 'configpath' at the top of this file.
+##
+##
+## First get the full path (if it exists) to pdflatex:
+##
+latex=$(command -v pdflatex)
+if [ -z "$latex" ] ; then latex="not found" ; fi
+##
+## Likewise for the pdfinfo and iconv (only needed for `--keepinfo'):
+##
+pdfinfo=$(command -v pdfinfo)
+if [ -z "$pdfinfo" ] ; then pdfinfo="not found"; fi
+iconv=$(command -v iconv)
+if [ -z "$iconv" ] ; then iconv="not found"; fi
+##
+##
+## Next a permitted location for temporary files on your system:
+##
+tempfileDir=${TMPDIR:-'/tmp'} ## /tmp is standard on most unix systems
+##
+##
+## Default for the output file location:
+##
+outFile="$pwd" ## Output to the current working directory
+##
+##
+## A few more default settings for pdfjam:
+##
+shortedge='true' ## Default paper is rotated shortedge when doing book
+##
+runs=1 ## Run latex just once
+##
+tidy='true' ## Delete all temporary files at the end
+##
+keepinfo='false' ## Don't try to preserve "pdfinfo" data
+##
+checkfiles='false' ## Don't use the Unix 'file -Lb' utility to
+## identify PDF files from their contents;
+## rely on the .pdf or .PDF extension instead.
+##
+suffix='pdfjam' ## Default filename suffix to be used when
+## --outfile is either (a) a directory, or (b)
+## not specified in a --batch call.
+##
+preamble='' ## Default LaTeX preamble string.
+##
+## END OF SETTINGS MADE DIRECTLY WITHIN THE SCRIPT
+##
+## Now read the site's or user's configuration file(s) if such exist,
+## unless '--vanilla' was specified.
+##
+if test "$vanilla" != true
+then
+ if test "$PDFJAM_CALL_NUMBER" = 0 ## not a secondary call to pdfjam
+ then
+ configFiles=$(printf "%s" "$configpath" | \
+ sed 's/:/\/pdfjam.conf:/g; s/$/\/pdfjam.conf/')
+ configFiles="${configFiles}:$HOME/.pdfjam.conf"
+ PDFJAM_CONFIG=""
+ prattle "Reading any site-wide or user-specific defaults..."
+ IFS=':'
+ for d in $configFiles
+ do
+ if test -f "$d"; then
+ change=$(sed '/^ *#.*/d ; s/ *#.*//; s/^ *//' "$d")
+ comment="## ${newline}## From ${d}: ${newline}##"
+ PDFJAM_CONFIG="$PDFJAM_CONFIG$comment$newline$change$newline"
+ fi
+ done
+ IFS="$OIFS"
+ PDFJAM_CONFIG=$(printf "%s" "$PDFJAM_CONFIG" | sed 's/^/ /')
+ if test "$batch" = true ; then export PDFJAM_CONFIG ; fi
+ if test -z "$PDFJAM_CONFIG"
+ then
+ prattle "(none found)" 1
+ else
+ prattle "$PDFJAM_CONFIG" 1
+ fi
+ fi
+ if test -n "$PDFJAM_CONFIG" ; then eval "$PDFJAM_CONFIG" ; fi
+else
+ if test $PDFJAM_CALL_NUMBER -eq 0
+ then
+ prattle "Called with '--vanilla': no user or site configuration"
+ prattle "files will be read." 1
+ fi
+fi
+## For backwards compatibility, check here for a $pdflatex setting in the config file
+if [ -n "${pdflatex:-}" ] ; then latex="$pdflatex" ; fi
+##
+## If paper size is not set, get default paper size from libpaper >= 2 if
+## possible, otherwise guess A4.
+##
+paperspec=
+if test -z "$paper"; then
+ if command -v paper >/dev/null ; then
+ paperspec=$(paper)
+ if echo "$paperspec" | grep -q '^.*: '; then
+ 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={$paperwidth$paperunit,$paperheight$paperunit}"
+ paper='' ## We might not have a LaTeX-compatible name
+ else
+ echo "The 'paper' program seems not to be working; not using it"
+ fi
+ fi
+ if test -z "$paperspec"; then
+ paper='a4paper' ## fallback paper size is ISO A4
+ papersize='' ## clear papersize
+ fi
+fi
+##
+## END OF CONFIGURATION BLOCK
+##
+#########################################################################
+##
## HELP TEXT
##
## Defines the output of 'pdfjam --help'
##
helptext="
-pdfjam is a shell-script front end to the LaTeX 'pdfpages' package (for
-which, see http://www.ctan.org/tex-archive/macros/latex/contrib/pdfpages).
+pdfjam is a shell-script front end to the LaTeX 'pdfpages' package; see
+https://www.ctan.org/tex-archive/macros/latex/contrib/pdfpages
Usage: pdfjam [OPTIONS] [--] [FILE1 [SEL1]] [FILE2 [SEL2]]...
where
@@ -118,8 +360,8 @@ where
LaTeX packages and/or to set global options. If '--preamble'
is used more than once in the call, the supplied preamble
strings are simply concatenated. For a note on avoiding
- clashes, see the PDFjam-README file (also available at
- http://www.pdfjam.net).
+ clashes, see the README file, also available at
+ https://github.com/rrthomas/pdfjam
--keepinfo
--no-keepinfo
Preserve (or not) Title, Author, Subject and Keywords
@@ -155,11 +397,14 @@ where
A wide range of paper sizes is available thanks to the
LaTeX 'geometry' package. For details see documentation
for LaTeX and/or the 'geometry' package.
+ If no default value is set and libpaper is not available,
+ A4 is used.
[Default for you at this site: paper=$paper]
--papersize '{WIDTH,HEIGHT}'
Specify a custom paper size, e.g.,
--papersize '{10in,18cm}'
(Note the braces, and the comma!)
+ [Libpaper default: $papersize]
--pagecolor RGBSPEC
Specify a background colour for the output pages. The
RGBSPEC must be a comma-separated trio of integers
@@ -182,8 +427,7 @@ where
Run latex N times, for each output document made.
[Default for you at this site: runs=$runs]
--vanilla
- Suppress the reading of any site-wide or user-specific
- configuration files.
+ Suppress the reading of any pdfjam configuration files.
--enc
Specify a command-line encoding
[Default for you at this site: enc=$enc]
@@ -217,7 +461,7 @@ where
only the content will be rotated.)
etc., etc. For more information see the manual for
the 'pdfpages' package, at
- http://www.ctan.org/tex-archive/macros/latex/contrib/pdfpages
+ https://www.ctan.org/tex-archive/macros/latex/contrib/pdfpages
* '--' can be used to signal that there are no more options to come.
Defaults for the options '--suffix', '--keepinfo', '--paper', '--outfile',
@@ -238,241 +482,21 @@ https://github.com/rrthomas/pdfjam.
## END OF HELP TEXT
##
#########################################################################
-##
-## PRELIMINARIES
-##
-## First determine:
-## --- whether verbose commentary should be provided (not if --quiet
-# or --configpath was specified);
-## --- whether this call to pdfjam is a "batch" call;
-## --- whether just the help text is required;
-## --- or whether all configuration files should be ignored.
-##
-verbose=true
+#
+# If --help is given, print help and exit. We do this here so that the
+# configuration files have already been read, and default values can be
+# shown in the help
for arg
do
case $arg in
- --quiet | -q | --configpath)
- verbose=false ;
- ;;
- --version | -V)
- echo "$version"
- exit 0 ;
- ;;
- --batch)
- batch=true ;
- ;;
--help | -u | -h)
printf "%s\n" "$helptext" ;
exit 0 ;
;;
- --vanilla)
- vanilla=true ;
- ;;
*)
;;
esac
done
-##
-## Check to see whether this is a "secondary" call to pdfjam:
-##
-if test -z "$PDFJAM_CALL_NUMBER" ## not a secondary call
-then
- PDFJAM_CALL_NUMBER=0
-fi
-##
-## Keep a copy of the internal file separator, so we can change it safely
-##
-OIFS="$IFS"
-##
-## Record the full filename of the current working diractory
-##
-pwd=$(pwd)
-##
-## Trap interrupts so that they kill everything:
-##
-trap 'IFS=$OIFS; exit 1' 1 2 15
-##
-## The following will be useful for readability of the script:
-##
-newline='
-'
-##
-## Define a function to escape tricky characters in file names etc:
-##
-escape_chars () {
- (printf "%s" "${1}" | sed 's/[^a-zA-Z0-9._/\-]/\\&/g')
-}
-##
-## Define a function to output verbose comments:
-##
-prattle () { ## second argument here is non-null for continuation lines
- if test $verbose = true; then
- prefix1=" pdfjam:" ;
- prefix2=$(printf "%s" "$prefix1" | sed 's/pdfjam:/ /') ;
- indent="" ;
- if test "$PDFJAM_CALL_NUMBER" -gt 0 &&
- test "$batch" != true
- then
- indent=" "
- fi
- IFS="$newline" ;
- lineCounter=0 ;
- for line in ${1}
- do
- lineCounter=$((lineCounter + 1)) ;
- if test $lineCounter -eq 1 && test ! -n "${2}" ;
- then
- if test -w "$PDFJAM_MESSAGES_FILE"
- then printf "$prefix1$indent %s\n" "$line" >> \
- "$PDFJAM_MESSAGES_FILE"
- else messages="$messages$prefix1$indent $line$newline"
- ## msg file not made yet
- fi
- else
- if test -w "$PDFJAM_MESSAGES_FILE"
- then printf "$prefix2$indent %s\n" "$line" >> \
- "$PDFJAM_MESSAGES_FILE"
- else messages="$messages$prefix2$indent $line$newline"
- ## msg file not made yet
- fi
- fi ;
- done ;
- IFS="$OIFS" ;
- fi ;
- return ;
-}
-##
-## And here's the first piece of verbose commentary:
-##
-prattle "----" 1
-prattle "This is pdfjam version ${version}."
-##
-#########################################################################
-##
-## CONFIGURATION
-##
-## THESE SETTINGS WILL BE OVER-RIDDEN by any found in configuration
-## files. By default such files are found at any or all of
-## /etc/pdfjam.conf
-## /usr/share/etc/pdfjam.conf
-## /usr/local/share/pdfjam.conf
-## /usr/local/etc/pdfjam.conf
-## $HOME/.pdfjam.conf
-## (And they are read in that order; if a setting is made more than
-## once, the last instance prevails.)
-##
-## An example configuration file can be found at
-## https://github.com/rrthomas/pdfjam
-##
-## The path searched for site-wide configuration files can be changed
-## by editing the variable 'configpath' at the top of this file.
-##
-##
-## First get the full path (if it exists) to pdflatex:
-##
-latex=$(command -v pdflatex)
-if [ -z "$latex" ] ; then latex="not found" ; fi
-##
-## Likewise for the pdfinfo and iconv (only needed for `--keepinfo'):
-##
-pdfinfo=$(command -v pdfinfo)
-if [ -z "$pdfinfo" ] ; then pdfinfo="not found"; fi
-iconv=$(command -v iconv)
-if [ -z "$iconv" ] ; then iconv="not found"; fi
-##
-##
-## Next a permitted location for temporary files on your system:
-##
-tempfileDir=${TMPDIR:-'/tmp'} ## /tmp is standard on most unix systems
-##
-##
-## Default for the output file location:
-##
-outFile="$pwd" ## Output to the current working directory
-##
-##
-## A few more default settings for pdfjam:
-##
-shortedge='true' ## Default paper is rotated shortedge when doing book
-##
-runs=1 ## Run latex just once
-##
-tidy='true' ## Delete all temporary files at the end
-##
-keepinfo='false' ## Don't try to preserve "pdfinfo" data
-##
-checkfiles='false' ## Don't use the Unix 'file -Lb' utility to
-## identify PDF files from their contents;
-## rely on the .pdf or .PDF extension instead.
-##
-suffix='pdfjam' ## Default filename suffix to be used when
-## --outfile is either (a) a directory, or (b)
-## not specified in a --batch call.
-##
-preamble='' ## Default LaTeX preamble string.
-##
-## 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={$paperwidth$paperunit,$paperheight$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
-##
-## Now read the site's or user's configuration file(s) if such exist,
-## unless '--vanilla' was specified.
-##
-if test "$vanilla" != true
-then
- if test "$PDFJAM_CALL_NUMBER" = 0 ## not a secondary call to pdfjam
- then
- configFiles=$(printf "%s" "$configpath" | \
- sed 's/:/\/pdfjam.conf:/g; s/$/\/pdfjam.conf/')
- configFiles="${configFiles}:$HOME/.pdfjam.conf"
- PDFJAM_CONFIG=""
- prattle "Reading any site-wide or user-specific defaults..."
- IFS=':'
- for d in $configFiles
- do
- if test -f "$d"; then
- change=$(sed '/^ *#.*/d ; s/ *#.*//; s/^ *//' "$d")
- comment="## ${newline}## From ${d}: ${newline}##"
- PDFJAM_CONFIG="$PDFJAM_CONFIG$comment$newline$change$newline"
- fi
- done
- IFS="$OIFS"
- PDFJAM_CONFIG=$(printf "%s" "$PDFJAM_CONFIG" | sed 's/^/ /')
- if test "$batch" = true ; then export PDFJAM_CONFIG ; fi
- if test -z "$PDFJAM_CONFIG"
- then
- prattle "(none found)" 1
- else
- prattle "$PDFJAM_CONFIG" 1
- fi
- fi
- if test -n "$PDFJAM_CONFIG" ; then eval "$PDFJAM_CONFIG" ; fi
-else
- if test $PDFJAM_CALL_NUMBER -eq 0
- then
- prattle "Called with '--vanilla': no user or site configuration"
- prattle "files will be read." 1
- fi
-fi
-## For backwards compatibility, check here for a $pdflatex setting in the config file
-if [ -n "${pdflatex:-}" ] ; then latex="$pdflatex" ; fi
-##
-## END OF CONFIGURATION BLOCK
-##
#########################################################################
##
## ERROR CODES
@@ -660,6 +684,7 @@ while test -n "${1}${2}"; do
shift ;;
--paper)
paper="${2}"
+ papersize='' ## clear papersize
callOptions="$callOptions ${1} ${2}" ;
shift ;;
--pagecolor)
@@ -677,9 +702,11 @@ while test -n "${1}${2}"; do
--ansidpaper | --ansiepaper | \
--letterpaper | --legalpaper | --executivepaper)
paper=$(printf "%s" "${1}" | sed 's/^--//') ;
+ papersize='' ## clear papersize
callOptions="$callOptions ${1}" ;
;;
--papersize)
+ paper='' ## clear paper
papersize="papersize=${2}" ;
callOptions="$callOptions ${1} '${2}'" ;
shift ;;
@@ -832,7 +859,10 @@ callOptions=$(printf "%s" "$callOptions" | sed 's/^ //')
##
case $landscape in
true)
- orientation=landscape ;;
+ orientation=landscape
+ if test -n "$papersize"; then
+ papersize="papersize={$paperheight$paperunit,$paperwidth$paperunit}"
+ fi ;;
*)
orientation="" ;;
esac