[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#225833: 225833: letter vs A4 in TeX



Ross Boylan <ross@biostat.ucsf.edu> wrote:

> Anyway, the BOTTOM LINE with the current Debian setup seems to be that
> if you want to specify page size explicitly, and have that respected
> by all post-processing tools, you need to use
> \usepackage[dvips,xxxx]{geometry}, where xxx is the papersize.
> Apparently xxx can either be "paper=letterpaper" or just
> "letterpaper".

Even if this works _now_, I think advising users to pass the "dvips"
option no matter which driver they are using is 1) ugly 2) bound to lead
to problems later. I'd rather tell them to specify the driver they are
actually using.

And if you want your documents to be ready for both dvips, pdftex and
whatnot, well, you can use a Makefile. I'm attaching a standard Makefile
of mine for this purpose, with the accompanying little script, to be put
somewhere in $PATH (can be replaced with a sed command, except that I
wouldn't know how to implement the --maxrepl option in sed, and not
limiting the number of replacements to 1 in this context is too ugly for
my taste).

To be usable with these Makefiles, my documents start like that:

  \documentclass[a4paper,<otheroptions>,*FloTeXDriver*]{article}
  \usepackage{lmodern}
  \usepackage[T1]{fontenc}
  \usepackage[latin1]{inputenc}
  \usepackage{textcomp}
  \usepackage[nohead,left=2.5cm,right=2.5cm,top=2.3cm,bottom=2cm]{geometry}

As I wrote in a previous mail, the option specifying the paper size
needs to be there only once, since \documentclass options are passed to
packages. Same thing with the driver option, which appears in place of
the "*FloTeXDriver*" string after the automatic replacement is done
(both geometry and hyperref can benefit from the driver setting).
all: pdf # ps

# LATEX_ARGS    := --src-specials \\nonstopmode
LATEX_ARGS    := \\nonstopmode
PDFLATEX_ARGS := \\nonstopmode
TEX_RUNS      := 1

SRC_BASE_NAME := basename_of_your_tex_file
SRC           := $(SRC_BASE_NAME).tex

SRC_PDF_BASE_NAME := $(SRC_BASE_NAME)_pdf
SRC_PDF           := $(SRC_PDF_BASE_NAME).tex
SRC_PS_BASE_NAME  := $(SRC_BASE_NAME)_ps
SRC_PS            := $(SRC_PS_BASE_NAME).tex

DVI               := $(SRC_PS_BASE_NAME).dvi

pdf: $(SRC_PDF)
	for i in `seq 1 $(TEX_RUNS)`; do \
           pdflatex $(PDFLATEX_ARGS)'\input{$<}'; \
        done
	@if [ ! -e '$(SRC_BASE_NAME).pdf' ]; then \
           ln -s '$(SRC_PDF_BASE_NAME).pdf' '$(SRC_BASE_NAME).pdf'; \
        fi

ps: $(DVI)
	dvips -o '$(SRC_BASE_NAME).ps' '$<'

dvi: $(DVI)

$(DVI): $(SRC_PS)
	for i in `seq 1 $(TEX_RUNS)`; do \
           latex $(LATEX_ARGS)'\input{$<}'; \
        done
	@if [ ! -e '$(SRC_BASE_NAME).dvi' ]; then \
           ln -s '$(SRC_PS_BASE_NAME).dvi' '$(SRC_BASE_NAME).dvi'; \
        fi

$(SRC_PS): $(SRC)
	replace-in-file.py --from="*FloTeXDriver*" --to=dvips --maxrepl=1 \
          '--output=$@' '$<'

$(SRC_PDF): $(SRC)
	replace-in-file.py --from="*FloTeXDriver*" --to=pdftex --maxrepl=1 \
          '--output=$@' '$<'

clean:
	rm -f '$(SRC_PDF)' '$(SRC_PS)' '$(DVI)' '$(SRC_PDF_BASE_NAME).pdf' \
          missfont.log
	for ext in dvi ps pdf; do \
          rm -f '$(SRC_BASE_NAME).'"$$ext"; \
        done
	for basename in '$(SRC_PS_BASE_NAME)' '$(SRC_PDF_BASE_NAME)'; do \
          for ext in aux log ind toc; do \
            rm -f "$${basename}.$${ext}"; \
          done; \
        done

.PHONY: all clean pdf dvi ps
#! /usr/bin/env python

# replace-in-file.py --- Replace a string with another one in a given file
# Copyright (c) 2003 Florent Rougon
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 dated June, 1991.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to the
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA  02110-1301 USA.

import sys, getopt, string

usage = """Usage: %s [options] [input_file]
Write a file from a template, substituting a given string.

  -f, --from           string to replace with "to" (defaults to
                       "*FloTeXDriver*")
  -t, --to             string to substitute to occurrences of "from"
  -m, --maxrepl        maximum number of occurrences to replace (no
                       maximum by default)
  -o, --output         output file (default: standard output)
      --help           display usage information and exit""" % sys.argv[0]


def main():
    try:
        # Options processing
        opts, args = getopt.getopt(sys.argv[1:], "f:t:m:o:",
                                   ["from=",
                                    "help",
                                    "to=",
                                    "maxrepl=",
                                    "output="])
    except getopt.GetoptError, message:
        sys.exit(usage)

    if len(args) == 1:
        ift = "named"
        ifn = args[0]
    elif len(args) == 0:
        ift = "stdin"
    else:
        sys.exit(usage)

    # Default values
    tos = None
    froms = "*FloTeXDriver*"
    maxrepl = None
    ofn = None
    
    # Read command-line options
    for option, value in opts:
        if option == "--help":
            print usage
            sys.exit(0)
        elif option in ("-t", "--to"):
            tos = value
        elif option in ("-f", "--from"):
            froms = value
        elif option in ("-m", "--maxrepl"):
            try:
                maxrepl = int(value)
            except ValueError:
                sys.exit("Error:\n\ninvalid maxrepl value. Should be an "
                         "integer.")
        elif option in ("-o", "--output"):
            ofn = value
        else:
            sys.exit(usage)

    if tos is None:
        sys.exit("Replacement string not specified")

    try:
        if ift == "named":
            ifile = open(ifn, "rb")
        else:
            ifile = sys.stdin

        ifc = ifile.read()
        ifile.close()

        if ofn is None:
            of = sys.stdout
        else:
            of = open(ofn, "wb")

        of.write(string.replace(ifc, froms, tos, maxrepl))
        of.close()
    except IOError, v:
        sys.exit("I/O error: %s" % v)

    sys.exit(0)

if __name__ == "__main__": main()
-- 
Florent

Reply to: