#!/bin/bash # # Syntax: dvi2pdf [-s] [-n] [-x] [-l] [-r] [-b] [-t papersize] [-h] # [-d dir1:dir2:...] filename [...] # # Purpose: Transforms .dvi files into .pdf files using dvips with the # option -Ppdf -G0 and ps2pdf. # Use the -s flag to reduce the intermediate output printed to the # screen while running the script. # Use the -n flag to prevent compression of images (note: this # will in general increase the size of the file). # Use the -x flag to prevent selecting the prepress option. # Use the -l flag to select letter paper. # Use the -r flag to pass the option -t landscape to dvips # (sometimes required if page size is set manually to landscape # in the latex file). # Use the -b flag for beamer on A4 landscape. # Use the -t flag to specify the paper format (currently recognized # formats are a4 (default), letter, a0, and other ghostscript # formats). Is it also possible to specify the paper format none # (required e.g. for beamer-based presentations). # Use the -d flag to specify extra directories to be added to # TEXINPUTS. # The -h flag shows the help info for this command. # # See also: dvips # # Note: You may have to include a line like # alias dvi2pdf=~/your_bin_dir/dvi2pdf # in your login files (e.g., .bashrc) in order to be able to use # this command. # # Note: If you use -x to prevent selecting the prepress option, base 14 # may not be embedded, resulting in a smaller file, but some # characters may not print or display properly (e.g., \bar{\mu} # in combination with the mathptmx package). # # Note: If you use beamer with the resize to A4 option, specify -x -t none. # # Created: Mar 3, 2000 by Bart De Schutter # Last revised: Dec 23, 2015 by Bart De Schutter # # See http://www.deschutter.info/util/scripts.html for the latest version of # this script. # Status: public # Category: pdf, latex dvips_option="" prepress_option="-dPDFSETTINGS=/prepress" # # Note: In ghostscript 9.05 the following options are apparently # already active by default; however, we just keep them # for robustness. # pdf_option="-dCompatibilityLevel=1.4 -dMAxSubsetPct=100 -dSubsetFonts=true" pdf_option="$pdf_option -dEmbedAllFonts=true" ## -dColorImageResolution=600 pdf_option="-dEncodeColorImages=false" paper_size="a4" extra_dirs="" # # Options taken from www.paperplaza.net # while getopts :hslt:nxrd: option do case "$option" in h) sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1;; s) dvips_option="$dvips_option -q";; l) paper_size="letter";; t) paper_size=$OPTARG;; n) pdf_option="$pdf_option -dAutoFilterColorImages=false \ -dAutoFilterGrayImages=false \ -dColorImageFilter=/FlateEncode \ -dGrayImageFilter=/FlateEncode \ -dMonoImageFilter=/FlateEncode";; x) prepress_option="";; # b) paper_size="";; r) dvips_option="-t landscape $dvips_option";; d) extra_dirs=${OPTARG};; :) echo >&2 echo >&2 "Option -$OPTARG requires an argument." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 echo >&2 exit 1;; \?) echo >&2 echo >&2 "Unknown option: $OPTARG" echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1;; esac done pdf_option="$prepress_option $pdf_option" shift $(($OPTIND-1)) if [ -n "${extra_dirs}" ] then TEXINPUTS="$TEXINPUTS${extra_dirs}:" fi if [[ "$paper_size" != "none" ]] then dvips_option="$dvips_option -t$paper_size" pdf_option="$pdf_option -sPAPERSIZE=$paper_size" fi if [ $# -eq 0 ]; then echo >&2 echo >&2 "ERROR: ${0##*/} requires at least 1 input argument." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi for fname in "$@" do \dvips $dvips_option -Ppdf -j0 \ -G0 "${fname%.dvi}.dvi" -o - | ps2pdf $pdf_option - "${fname%.dvi}.pdf" # -Pdownload35 -u ps2pk.map # -dEncodeColorImages=false done