[tex-live] [patch] More consistent paper handling in texconfig

Frank Küster frank at kuesterei.ch
Sat Feb 13 22:01:17 CET 2010


Dear TeX Live folks,

currently texconfig(-sys) handles the setting of the default papersize
differently for each executable involved.  The result is that "texconfig
paper" only accepts a4 and letter, although most of the individual
executables can handle many more.

Attached is a patch that addresses this issue.  I'll explain it a bit,
and below is a general remark which might be interesting even for those
who don't care about papers (look for "reimplement").  I would be glad
if you could apply it, or make suggestions what needs to be improved.

1. The patch handles default paper settings for pdftex, dvips, xdvi,
   dvipdfmx and also dvipdfm (I know the latter is just a symlink, but the
   code is still there in texconfig, so I "fixed" it).

2. First it adds a function to read and show the current default paper
   setting.  And while I was at it, I added calls to these functions to
   the output of "texconfig confall".

3. Then, I use the papersize information from config.ps to get the
   information for the functions SizeToPaper and PaperToSize.  It might
   be better to add a separate file containing this information for the
   purposes of texconfig, but I didn't do this yet.

4. Now pdftex can be configured to use any default paper that dvips
   knows about, by querying the dimensions using PaperToSize.  Most of
   them will never be used, but it's hard to draw a line.

5. I've updated the list of papers that xdvi knows about from its
   source.  There's also a function I used for that.  It lists which
   papers are known to xdvi only, to dvips only, and to both - but that
   is not meant for users and hence commented.

6. Thus, the intersection of sizes accepted by "texconfig paper" is now

   a0 a1 a10 a2 a3 a4 a5 a6 a7 a8 a9 b0 b1 b2 b3 b4 b5 b6 c5 ledger legal letter tabloid


While I was working on texconfig, I found it hard to navigate in the
file, and keep a feeling where I was.  In case this will be
reimplemented in lua (or perl or whatever), I suggest that someone
should clean it up a bit.  I suggest to, and have already followed this:

In tcBatch, there shouldn only be 2 directly nested case statements, and
no real code in there.  Instead, the main commandline parsing should
only look for the first and second word, and then call a function to do
all the rest. The functions should be in different sections of the file,
one group containing those directly called from the tcBatch $@ parsing,
the other (already existing) group with functions that are re-used all
over the program.

Regards, Frank


-- 
Dr. Frank Küster
Debian Developer (TeXLive)
VCD Aschaffenburg-Miltenberg, ADFC Miltenberg
B90/Grüne KV Miltenberg

-------------- next part --------------
---
 texk/tetex/texconfig |  347 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 302 insertions(+), 45 deletions(-)


Index: texlive-bin-2009/texk/tetex/texconfig
===================================================================
--- texlive-bin-2009.orig/texk/tetex/texconfig	2010-02-11 14:17:41.000000000 +0100
+++ texlive-bin-2009/texk/tetex/texconfig	2010-02-13 21:39:15.000000000 +0100
@@ -25,7 +25,9 @@
 progname=texconfig
 
 # the version string
-version=20080708.1050
+version=20080708.1050plus_paperconf
+# paperconf additions by Frank Küster ©2010, Public Domain:
+# You may freely copy, distribute and/or modify any part of the patch
 
 envVars="
   AFMFONTS BIBINPUTS BSTINPUTS CMAPFONTS CWEBINPUTS ENCFONTS GFFONTS
@@ -333,6 +335,18 @@
 }
 
 ###############################################################################
+# fmgrConfigShowPaper (file regex)
+#   shows the paper setting in file, according to regex
+#
+fmgrConfigShow()
+{
+  fmgrConfigShowFile=`tcfmgr --cmd find --file $1`
+  fmgrConfigShowRegex=$2
+
+  sed -n "$fmgrConfigShowRegex" $fmgrConfigShowFile
+}
+
+###############################################################################
 # fmgrConfigReplace (file regex value)
 #   replaces line matching regex by value in file
 #
@@ -546,6 +560,177 @@
 
 # 
 ###############################################################################
+# Main functions,
+#   called from tcBatch with original positional parameters shifted by 1
+###############################################################################
+
+###############################################################################
+# SizeToPaper
+#   Convert paper dimensions to a unique paper name
+###############################################################################
+SizeToPaper()
+{
+  UsageSizeToPaper="Usage: texconfig size-to-paper height width"
+  case $1 in
+    "")
+      echo $UsageSizeToPaper >&2
+      ;;
+    *)
+      AskedHeight=$1
+      AskedWidth=$2
+      locateConfigPsFile
+      papername=$(listDvipsPapers | \
+	grep "$AskedWidth[[:space:]]*$AskedHeight" | \
+	sed 's/[[:space:]].*//' \
+	)
+      if [ ! -n "$papername" ] || [ "$papername" = "unknown" ] || [ "$papername" = "nopaper" ]; then
+	echo "No paper known with height $AskedHeight and width $AskedWidth"  >&2
+	echo "Known units are mm and in, decimal separator is \`.'"
+	echo "Maybe height and width have been exchanged?" >&2
+	cleanup 1
+      else
+	if [ $(echo $papername | wc -w) -gt 1 ]; then
+	  # filter out duplicates.  This command line shows duplicates in the current config.ps:
+	  # ./texconfig dvips paper-list | \
+	  #     sed 's/\([[:alnum:]]*\)[[:space:]]\(.*\)/\2 \1/' | \
+	  #     sort | \
+	  #     sed 's/\(.*\)[[:space:]]\([[:alnum:]]*\)/\2 \1/' | \
+	  #     uniq -D -f 1
+	  papernameList=$papername
+	  papername=$(echo $papername | \
+	    sed 's/11x17//;s/statement//;s/a4size//;s/letterSize//;s/flse//;s/[[:space:]]//g' \
+	    )
+	  echo $papername
+	fi
+	:
+      fi
+      ;;
+  esac
+}
+
+###############################################################################
+# PaperToSize
+#   Convert paper name to dimensions, values taken from config.ps
+###############################################################################
+PaperToSize()
+{
+  UsagePaperToSize="Usage: texconfig paper-to-size [-m|--machine-readable] papername"
+  sparseOutput=0
+  case $1 in
+    -m|--machine-readable)
+      sparseOutput=1
+      shift
+      ;;
+  esac
+  case $1 in
+    "")
+      echo $UsagePaperToSize >&2
+      ;;
+    *)
+      AskedPaper=$1
+      locateConfigPsFile
+      paperline=$(listDvipsPapers | grep "^$AskedPaper[[:space:]]")
+      if [ ! -n "$paperline" ]; then
+	echo "unknown paper size: $AskedPaper" >&2
+	cleanup 1
+      fi
+      allowedUnitLetters="min"
+      width=$(echo $paperline | sed \
+	"s/.*['\'']\([[:digit:].]*[$allowedUnitLetters][$allowedUnitLetters]\).*/\1/" \
+	)
+      height=$(echo $paperline | sed \
+	"s/.*[[:space:]]\([[:digit:].]*[$allowedUnitLetters][$allowedUnitLetters]\).$/\1/" \
+	)
+      if [ $sparseOutput = 1 ]; then
+	echo $height $width
+      else
+	echo "Paper $AskedPaper has height $height and width $width"
+      fi
+      ;;
+  esac
+
+}
+
+###############################################################################
+# pdftexSetPaper
+#   set paper for pdftex
+###############################################################################
+pdftexSetPaper()
+{
+  pdfPaperHelp="Usage: $progname pdftex paper PAPER"
+
+  pdfPaperName="$1"
+
+  if [ -z $pdfPaperName ]; then
+    echo "$help" >&2
+    rc=1
+    return $rc
+  fi
+
+  pdfPaperDims=$(PaperToSize -m $pdfPaperName)
+  PaperHeight=$(echo $pdfPaperDims | sed 's/ .*//') # keep value before blank
+  PaperWidth=$( echo $pdfPaperDims | sed 's/.* //') # keep value after blank
+
+  pdfPaperHeight=$(echo $PaperHeight | sed 's/mm/ true mm/;s/in/ true in/')
+  pdfPaperWidth=$( echo $PaperWidth  | sed 's/mm/ true mm/;s/in/ true in/')
+
+  setupTmpDir
+  fmgrConfigReplace pdftexconfig.tex pdfpagewidth '\pdfpagewidth='"$pdfPaperWidth"
+  wChanged=$fmgrConfigReplaceChanged
+  fmgrConfigReplace pdftexconfig.tex pdfpageheight '\pdfpageheight='"$pdfPaperHeight"
+  if $wChanged || $fmgrConfigReplaceChanged; then
+    echo "pdftex paper size has changed, refreshing formats"
+    fmtutil --refresh
+  fi
+}
+
+###############################################################################
+# pdftexPaperConf
+#   get paper for pdftex
+###############################################################################
+pdftexPaperConf(){
+  pdftexconfig=`tcfmgr --cmd find --file pdftexconfig.tex`
+  pdftexPaperWidth=$(sed -n '/^\\pdfpagewidth/ {s/^\\pdfpagewidth=//;s/ true //;p}' $pdftexconfig)
+  pdftexPaperHeight=$(sed -n '/^\\pdfpageheight/ {s/^\\pdfpageheight=//;s/ true //;p}' $pdftexconfig)
+
+  SizeToPaper $pdftexPaperHeight $pdftexPaperWidth
+}
+
+###############################################################################
+# dvipdfmPaperConf
+#   get paper for dvipdfm
+###############################################################################
+dvipdfmPaperConf(){
+  fmgrConfigShow config '/^p/ {s/^p //;p}'
+}
+
+###############################################################################
+# dvipdfmxPaperConf
+#   get paper for dvipdfmx
+###############################################################################
+dvipdfmxPaperConf(){
+  fmgrConfigShow dvipdfmx.cfg '/^p/ {s/^p //;p}'
+}
+
+###############################################################################
+# dvipsPaperConf
+#   get paper for dvips
+###############################################################################
+dvipsPaperConf(){
+  locateConfigPsFile
+  fmgrConfigShow config.ps '/^@ / {s/^@ \([^[:space:]]*\).*/\1/;p;q}'
+}
+
+###############################################################################
+# XDviPaperConf
+#   get paper for XDvi
+###############################################################################
+XDviPaperConf(){
+  fmgrConfigShow XDvi '/^\*paper:/ {s/^\*paper: \([^[:space:]]*\).*/\1/;p;q}'
+}
+
+# 
+###############################################################################
 # tcBatch(args)
 #   handle batch mode
 ###############################################################################
@@ -615,6 +800,18 @@
       echo
       echo '==== kpathsea variables from environment only (ok if no output here) ===='
       echoShowVariable $envVars
+      echo
+      echo '========================== default paper sizes =========================='
+      echo -n "dvipdfm: "
+      dvipdfmPaperConf
+      echo -n "dvipdfmx: "
+      dvipdfmxPaperConf
+      echo -n "dvips: "
+      dvipsPaperConf
+      echo -n "pdftex: "
+      pdftexPaperConf
+      echo -n "XDvi: "
+      XDviPaperConf
       ;;
 
     # texconfig dvipdfm
@@ -638,6 +835,9 @@
              echo "$progname: try \`$progname dvipdfm paper' for help" >&2
              rc=1 ;;
           esac ;;
+	paperconf)
+	  dvipdfmPaperConf
+	  ;;
         # texconfig dvipdfm ""
         "")
           echo "$help" >&2; rc=1 ;;
@@ -672,6 +872,9 @@
              rc=1 ;;
           esac ;;
         # texconfig dvipdfmx ""
+	paperconf)
+	  dvipdfmxPaperConf
+	  ;;
         "")
           echo "$help" >&2; rc=1 ;;
         # texconfig dvipdfmx <unknown>
@@ -689,6 +892,7 @@
       help="Usage: $progname dvips add PRINTER
        $progname dvips del PRINTER
        $progname dvips paper PAPER
+       $progname dvips paper-list
        $progname dvips [-P PRINTER] mode MODE
        $progname dvips [-P PRINTER] offset OFFSET
        $progname dvips [-P PRINTER] printcmd CMD"
@@ -821,6 +1025,9 @@
               ;;
           esac
           ;;
+	paperconf)
+	  dvipsPaperConf
+	  ;;
         mode)
           case $2 in
             "")
@@ -1226,23 +1433,25 @@
       help="Usage: $progname paper PAPER
 
 Valid PAPER settings:
-  letter a4"
+  a0 a1 a10 a2 a3 a4 a5 a6 a7 a8 a9 b0 b1 b2 b3 b4 b5 b6 c5 ledger legal letter tabloid"
 
-      p=$2; pXdvi=$2; pDvips=$2
+      p=$2
       case $2 in
-        letter)
-          pXdvi=us;;
-        a4)
-          pXdvi=a4;;
+	a0|a1|a10|a2|a3|a4|a5|a6|a7|a8|a9|b0|b1|b2|b3|b4|b5|b6|c5|ledger|legal|letter|tabloid)
+	  # handled by xdvi and dvips (and hence all others)
+	  :
+	  ;;
         "") echo "$help" >&2; rc=1; return;;
         *)
-          echo "$progname: unknown PAPER \`$2' given as argument for \`$progname paper'" >&2
+          echo "$progname: PAPER \`$2' is not understood by all programs." >&2
           echo "$progname: try \`$progname paper' for help" >&2
+	  echo "           or use \`$progname PROGNAME paper $2' instead " >&2
+	  echo "           for the programs you need." >&2
           rc=1
           return;;
       esac
       if checkForBinary dvips >/dev/null && tcfmgr --cmd find --file config.ps >/dev/null 2>&1; then
-        tcBatch dvips paper $pDvips
+        tcBatch dvips paper $p
       fi
       if checkForBinary dvipdfm >/dev/null && tcfmgr --cmd find --file config >/dev/null 2>&1; then
         tcBatch dvipdfm paper $p
@@ -1251,7 +1460,7 @@
         tcBatch dvipdfmx paper $p
       fi
       if checkForBinary xdvi >/dev/null && tcfmgr --cmd find --file XDvi >/dev/null 2>&1; then
-        tcBatch xdvi paper $pXdvi
+        tcBatch xdvi paper $p
       fi
       if checkForBinary pdftex >/dev/null && tcfmgr --cmd find --file pdftexconfig.tex >/dev/null 2>&1; then
         tcBatch pdftex paper $p
@@ -1259,10 +1468,16 @@
       ;;
 
     pdftex)
-      help="Usage: $progname pdftex paper PAPER
+      help="Usage:
+       $progname pdftex paper PAPER
 
-Valid PAPER settings:
-  a4 letter"
+          Valid PAPER settings: Same as for dvips, use
+            $progname dvips paper-list
+          to get a list of valid PAPER values.
+
+       $progname pdftex paperconf
+       $progname pdftex mode MODE
+"
       case $2 in
 
         mode)
@@ -1290,32 +1505,12 @@
           ;;
 
         paper)
-          case $3 in
-            letter)
-              w="8.5 true in"; h="11 true in"
-              setupTmpDir
-              fmgrConfigReplace pdftexconfig.tex pdfpagewidth '\pdfpagewidth='"$w"
-              wChanged=$fmgrConfigReplaceChanged
-              fmgrConfigReplace pdftexconfig.tex pdfpageheight '\pdfpageheight='"$h"
-              if $wChanged || $fmgrConfigReplaceChanged; then
-                fmtutil --refresh
-              fi
-              ;;
-            a4)
-              w="210 true mm"; h="297 true mm"
-              fmgrConfigReplace pdftexconfig.tex pdfpagewidth '\pdfpagewidth='"$w"
-              wChanged=$fmgrConfigReplaceChanged
-              fmgrConfigReplace pdftexconfig.tex pdfpageheight '\pdfpageheight='"$h"
-              if $wChanged || $fmgrConfigReplaceChanged; then
-                fmtutil --refresh
-              fi
-              ;;
-            "") echo "$help" >&2; rc=1;;
-            *)
-             echo "$progname: unknown PAPER \`$3' given as argument for \`$progname pdftex paper'" >&2
-             echo "$progname: try \`$progname pdftex paper' for help" >&2
-             rc=1 ;;
-          esac ;;
+	  shift; shift
+	  pdftexSetPaper $@
+	  ;;
+	paperconf)
+	  pdftexPaperConf
+	  ;;
         "")
           echo "$help" >&2; rc=1;;
         *)
@@ -1340,10 +1535,17 @@
 
     # handle "xdvi paper PAPER"
     xdvi)
+      # 20100125: added paper sizes found in xdvi.c, version.h says 22.84.16 in TeXLive 2010
       tcBatchXdviPapers='us           "8.5x11"
+letter       "8.5x11"
 usr          "11x8.5"
+ledger       "17x11"
+tabloid      "11x17"
 legal        "8.5x14"
+legalr       "14x8.5"
 foolscap     "13.5x17.0"
+foolscap     "17.0x13.5"
+a0           "84.1x118.9cm"
 a1           "59.4x84.0cm"
 a2           "42.0x59.4cm"
 a3           "29.7x42.0cm"
@@ -1351,6 +1553,10 @@
 a5           "14.85x21.0cm"
 a6           "10.5x14.85cm"
 a7           "7.42x10.5cm"
+a8           "5.2x7.4cm"
+a9           "3.7x5.2cm"
+a10          "2.6x3.7cm"
+a0r          "118.9x84.1cm"
 a1r          "84.0x59.4cm"
 a2r          "59.4x42.0cm"
 a3r          "42.0x29.7cm"
@@ -1358,6 +1564,10 @@
 a5r          "21.0x14.85cm"
 a6r          "14.85x10.5cm"
 a7r          "10.5x7.42cm"
+a8r          "7.4x5.2cm"
+a9r          "5.2x3.7cm"
+a10r         "3.7x2.6cm"
+b0           "1000.0x141.4cm"
 b1           "70.6x100.0cm"
 b2           "50.0x70.6cm"
 b3           "35.3x50.0cm"
@@ -1365,6 +1575,10 @@
 b5           "17.6x25.0cm"
 b6           "13.5x17.6cm"
 b7           "8.8x13.5cm"
+b8           "6.2x8.8cm"
+b9           "4.4x6.2cm"
+b10          "3.1x4.4cm"
+b0           "141.4x100cm"
 b1r          "100.0x70.6cm"
 b2r          "70.6x50.0cm"
 b3r          "50.0x35.3cm"
@@ -1372,6 +1586,10 @@
 b5r          "25.0x17.6cm"
 b6r          "17.6x13.5cm"
 b7r          "13.5x8.8cm"
+b8r          "8.8x6.2cm"
+b9r          "6.2x4.4cm"
+b10r         "4.4x3.1cm"
+c0           "91.7x129.7cm"
 c1           "64.8x91.6cm"
 c2           "45.8x64.8cm"
 c3           "32.4x45.8cm"
@@ -1379,27 +1597,35 @@
 c5           "16.2x22.9cm"
 c6           "11.46x16.2cm"
 c7           "8.1x11.46cm"
+c8           "5.7x8.1cm"
+c9           "4.0x5.7cm"
+c10          "2.8x4.0cm"
+c0r          "129.7x91.7cm"
 c1r          "91.6x64.8cm"
 c2r          "64.8x45.8cm"
 c3r          "45.8x32.4cm"
 c4r          "32.4x22.9cm"
 c5r          "22.9x16.2cm"
 c6r          "16.2x11.46cm"
-c7r          "11.46x8.1cm"'
+c7r          "11.46x8.1cm"
+c8r          "8.1x5.7cm"
+c9r          "5.7x4.0cm"
+c10r         "4.0x2.8cm"'
       help="Usage: $progname xdvi paper PAPER
 
 Valid PAPER settings:
-  a1 a1r a2 a2r a3 a3r a4 a4r a5 a5r a6 a6r a7 a7r
-  b1 b1r b2 b2r b3 b3r b4 b4r b5 b5r b6 b6r b7 b7r
-  c1 c1r c2 c2r c3 c3r c4 c4r c5 c5r c6 c6r c7 c7r
-  foolscap legal us usr"
+  a0 a0r a1 a1r a2 a2r a3 a3r a4 a4r a5 a5r a6 a6r a7 a7r a8 a8r a9 a9r a10 a10r
+  b0 b0r b1 b1r b2 b2r b3 b3r b4 b4r b5 b5r b6 b6r b7 b7r b8 b8r b9 b9r b10 b10r
+  c0 c0r c1 c1r c2 c2r c3 c3r c4 c4r c5 c5r c6 c6r c7 c7r c8 c8r c9 c9r c10 c10r
+  foolscap foolscapr legal legalr us|letter usr ledger tabloid"
       case $2 in
         paper-list)
           echo "$tcBatchXdviPapers"
           ;;
         paper)
           case $3 in
-            a1|a1r|a2|a2r|a3|a3r|a4|a4r|a5|a5r|a6|a6r|a7|a7r|b1|b1r|b2|b2r|b3|b3r|b4|b4r|b5|b5r|b6|b6r|b7|b7r|c1|c1r|c2|c2r|c3|c3r|c4|c4r|c5|c5r|c6|c6r|c7|c7r|foolscap|legal|us|usr)
+	    # 20100125: added paper sizes found in xdvi.c, version.h says 22.84.16 in TeXLive 2010
+            a0|a1|a1r|a2|a2r|a3|a3r|a4|a4r|a5|a5r|a6|a6r|a7|a7r|a8|a8r|a9|a9r|a10|a10r|b0|b0r|b1|b1r|b2|b2r|b3|b3r|b4|b4r|b5|b5r|b6|b6r|b7|b7r|b8|b8r|b9|b9r|b10|b10r|c0|c0r|c1|c1r|c2|c2r|c3|c3r|c4|c4r|c5|c5r|c6|c6r|c7|c7r|c8|c8r|c9|c9r|c10|c10r|foolscap|foolscapr|legal|legalr|us|usr|letter|ledger|tabloid)
               fmgrConfigReplace XDvi paper: "*paper: $3"
               ;;
             "") echo "$help" >&2; rc=1;;
@@ -1408,6 +1634,9 @@
              echo "$progname: try \`$progname xdvi paper' for help" >&2
              rc=1 ;;
           esac ;;
+	paperconf)
+	  XDviPaperConf
+	  ;;
         "")
           echo "$help" >&2; rc=1;;
         *)
@@ -1417,6 +1646,34 @@
           ;;
       esac
       ;;
+    paper-to-size)
+      shift
+      PaperToSize $@
+      ;;
+    size-to-paper)
+      shift
+      SizeToPaper $@
+      ;;
+    # compare-papers)
+    #   # this option is not meant to be used by users; therefore I don't care for insecure tempfiles
+    #   tcBatch xdvi paper-list | cut -d " " -f 1 | sort -u > ${TMPDIR:-/tmp}/xdvi.list
+    #   tcBatch dvips paper-list | cut -d " " -f 1 | sort -u > ${TMPDIR:-/tmp}/dvips.list
+    #   xdviOnly=$(comm -2 -3 ${TMPDIR:-/tmp}/xdvi.list ${TMPDIR:-/tmp}/dvips.list)
+    #   dvipsOnly=$(comm -1 -3 ${TMPDIR:-/tmp}/xdvi.list ${TMPDIR:-/tmp}/dvips.list)
+    #   knownToBoth=$(comm -1 -2 ${TMPDIR:-/tmp}/xdvi.list ${TMPDIR:-/tmp}/dvips.list)
+    #   echo "xdvi only:"
+    #   eval echo $xdviOnly
+    #   echo
+    #   echo
+    #   echo "dvips only:"
+    #   eval echo $dvipsOnly
+    #   echo
+    #   echo
+    #   echo "known to both:"
+    #   eval echo $knownToBoth
+    #   rm ${TMPDIR:-/tmp}/dvips.list
+    #   rm ${TMPDIR:-/tmp}/xdvi.list
+    #   ;;
     *)
       echo "$progname: unknown option \`$1' given as argument for \`$progname'" >&2
       echo "$progname: try \`$progname help' for help" >&2


More information about the tex-live mailing list