2 # original mktexpk -- make a new PK font, because one wasn't found.
4 # (If you change or delete the word `original' on the previous line,
5 # installation won't write this script over yours.)
7 # Originally written by Thomas Esser, Karl Berry, and Olaf Weber.
8 # Report bugs to tex-k@tug.org.
11 version='$Id: mktexpk,v 1.34 2005/06/21 10:49:10 olaf Exp $'
12 progname=`echo $0 | sed 's%.*/%%'`
13 usage="Usage: $progname [OPTIONS] NAME [REDIRECT],
16 --dpi DPI use resolution DPI.
17 --bdpi BDPI use base resolution BDPI.
18 --mag MAG use magnificiation MAG.
19 --mfmode MODE use MODE as the METAFONT mode.
20 --destdir DESTDIR write fonts in DESTDIR.
22 Try to create a PK file for NAME at resolution DPI, with an assumed
23 device base resolution of BDPI, and a Metafont \`mag' of MAG. Use MODE
24 for the METAFONT mode. Use DESTDIR for the root of where to install
25 into, either the absolute directory name to use (if it starts with a
26 /) or relative to the default DESTDIR (if not). REDIRECT, if supplied,
27 is a string of the form '>&n', where n is the number of the file
28 descriptor which is to receive, instead of stdout, the name of the
29 newly created pk file."
31 # Handle non-positional options, except for --version/--help
32 while test $# -gt 0; do
34 --destdir) shift; DEST="$1"; shift ;;
35 --destdir=*) DEST=`echo "$1" | sed 's/--destdir=//'`; shift ;;
36 --dpi) shift; DPI="$1"; shift ;;
37 --dpi=*) DPI=`echo "$1" | sed 's/--dpi=//'`; shift ;;
38 --bdpi) shift; BDPI="$1"; shift ;;
39 --bdpi=*) BDPI=`echo "$1" | sed 's/--bdpi=//'`; shift ;;
40 --mfmode) shift; test "x$1" != "x/" && MODE="$1"; shift ;;
41 --mfmode=*) test "x$1" != "x--mfmode/" \
42 && MODE=`echo "$1" | sed 's/--mfmode=//'`; shift ;;
43 --mag) shift; MAG="$1"; shift;;
44 --mag=*) MAG=`echo "$1" | sed '/s--mag=//'`; shift;;
45 --version|-version) break ;;
46 --help|-help) break ;;
51 if test "x$2" != x; then
52 tail="`echo \"x$2\" | sed 's/^x>&//' | grep '^[0-9]*$'`"
53 if test -z "$tail"; then
54 echo "$progname: argument '$2' ignored - bad file number" >&2
55 elif test "$tail" != 1; then
62 # Common code for all scripts.
63 : ${MT_TEXMFMAIN=`kpsewhich --expand-path='$TEXMFMAIN'`}
64 : ${MT_MKTEX_OPT=`kpsewhich --format='web2c files' mktex.opt`}
65 test -n "$MT_MKTEX_OPT" || MT_MKTEX_OPT="$MT_TEXMFMAIN/web2c/mktex.opt"
66 if test ! -f "$MT_MKTEX_OPT"; then
67 echo "$progname: Cannot find mktex.opt; check your installation." >&2
73 # Where do potential driver files belong?
74 case "$MT_FEATURES" in
76 : ${MT_MFDESTDIR=`pwd`}
80 # Since we want to pass the generated filename and only that filename
81 # back to the caller on standard output, we do some redirections so
82 # regular echo's will end up on stderr, and do an echo >$STDOUT at the end.
83 # Then the contents of $STDOUT will be echoed to stdout by a trap.
85 # start of redirection stdout -> stderr, stdin <- /dev/null
90 if kpsewhich $NAME.mf >/dev/null 2>&1 || mktexmf $NAME >/dev/null 2>&1; then
91 # determine the progname of metafont to use; prefer mf-nowin.
92 if (mf-nowin --version) >/dev/null 2>&1; then
93 MF="mf-nowin -progname=mf"
98 # Check that $BDPI and $MODE are consistent; if not, ignore the mode and
99 # hope we can correctly guess it from bdpi. (People like to specify the
100 # resolution on the command line, not the mode so much.)
101 if test -n "$MODE"; then
103 '\mode:='$MODE';mode_setup;message"BDPI= "&decimal round pixels_per_inch;end.'\
105 | awk '/DPI=/ {print $2}'`
106 if test "x$mf_bdpi" != x$BDPI; then
107 echo "$progname: Mismatched mode $MODE and resolution $BDPI; ignoring mode." >&2
112 # If an explicit mode is not supplied, try to guess. You can get a
113 # list of extant modes from ftp://ftp.tug.org/tex/modes.mf.
114 if test -z "$MODE" || test "x$MODE" = xdefault; then
126 8000) MODE=dpdfezzz;;
127 *) echo "$progname: Can't guess mode for $BDPI dpi devices." >&2
128 echo "$progname: Use a config file or option to specify the mode; see:" >&2
129 echo "$progname: http://tug.org/texinfohtml/kpathsea.html#Unable-to-generate-fonts" >&2
134 # Run Metafont. Always use plain Metafont, since reading cmbase.mf
135 # does not noticeably slow things down.
136 cmd="$MF \mode:=$MODE; mag:=$MAG; nonstopmode; input $NAME"
139 # ps_to_pk is set in mktex.opt
142 if $ps_to_pk -t "$NAME"; then
143 cmd="$ps_to_pk $NAME $DPI"
146 # grep for the font in $PSMAPFILE. These are base font names, such as
147 # rpplr (the original) or pplr0 (an interim step) or pplr8r (current).
148 : ${PSMAPFILE=`kpsewhich --format=map psfonts.map ps2pk.map`}
149 pattern="^$NAME"'([ ]|$)'
150 psline=`egrep "$pattern" $PSMAPFILE | tail -1`
151 if test -n "$psline"; then
152 set x `echo "$psline" | sed 's%[<["]%%g'`
154 encoding=; psname=; slant=; extend=
155 while test ! -z "$1"; do
157 *.enc) encoding="-e $1";;
158 *.pf[ab]) psname="$1";;
159 *SlantFont) slant="-S $lastopt";;
160 *ExtendFont) extend="-E $lastopt";;
165 # Guessing the name of the type1 font file as fallback:
166 ANAME=`echo $NAME | sed 's/8r$/8a/'`
167 for i in $NAME.pfa $NAME.pfb $ANAME.pfa $ANAME.pfb; do
168 if kpsewhich $i >/dev/null 2>&1; then
174 if [ -n "$psname" ]; then
175 cmd="ps2pk -v -X$DPI -R$BDPI $slant $extend $encoding $psname $NAME.${DPI}pk"
177 if gsftopk -t "$NAME"; then
178 echo "$progname: cannot find $NAME.pfa or $NAME.pfb. Trying gsftopk." >&2
179 cmd="gsftopk $NAME $DPI"
185 # unsupported by $ps_to_pk, try other conversions:
186 if test -z "$cmd"; then
187 if (ttf2pk -t -q $NAME) >/dev/null 2>&1; then
188 cmd="ttf2pk -q $NAME $DPI"
189 elif (hbf2gf -t -q $NAME) >/dev/null 2>&1; then
190 cmd="hbf2gf -q -p $NAME $DPI"
192 echo "$progname: don't know how to create bitmap font for $NAME." >&2
199 set x `"$MT_MKTEXNAM" $NAME $DPI $MODE $DEST`; shift
203 PKDESTDIR=`echo "$PKDEST" | sed 's%/[^/][^/]*$%%'` # can't rely on dirname
204 PKNAME=`basename "$PKDEST"`
205 GFNAME=$NAME.${DPI}gf
207 if test -r "$PKDESTDIR/$PKNAME"; then
208 echo "$progname: $PKDESTDIR/$PKNAME already exists." >&2
209 echo "$PKDESTDIR/$PKNAME" >$STDOUT
210 "$MT_MKTEXUPD" "$PKDESTDIR" $PKNAME
214 "$MT_MKTEXDIR" "$PKDESTDIR"
215 if test ! -d "$PKDESTDIR"; then
216 echo "$progname: $MT_MKTEXDIR $PKDESTDIR failed." >&2
220 echo "$progname: Running $cmd"
222 # Don't abort if only "Strange path", "bad pos" or "angle(0,0)"
224 grep '^!' $NAME.log | sort >$$.errs 2>/dev/null
225 grep '^! Strange path' $$.errs >$$.strange 2>/dev/null
226 grep '^! bad pos.' $$.errs >$$.badpos 2>/dev/null
227 grep '^! angle(0,0) is taken as zero.' $$.errs >$$.angle 2>/dev/null
228 cat $$.badpos $$.strange $$.angle | sort > $$.errs_accept
229 if cmp $$.errs $$.errs_accept >/dev/null 2>&1; then
230 test -s $$.strange >/dev/null 2>&1 \
231 && echo "$progname: warning: \`$cmd' caused strange path errors." >&2
232 test -s $$.badpos >/dev/null 2>&1 \
233 && echo "$progname: warning: \`$cmd' caused bad pos errors." >&2
234 test -s $$.angle >/dev/null 2>&1 \
235 && echo "$progname: warning: \`$cmd' caused angle(0,0) errors." >&2
237 echo "$progname: \`$cmd' failed." >&2
238 test -s $NAME.log && mv -f $NAME.log "$KPSE_DOT"
243 test -r $GFNAME && { gftopk ./$GFNAME $PKNAME || exit 1; }
244 test ! -f $PKNAME && test -f $NAME.${DPI}pk && mv $NAME.${DPI}pk $PKNAME
245 if test ! -s $PKNAME; then
246 echo "$progname: \`$cmd' failed to make $PKNAME." >&2
250 # Install the PK file carefully, since others may be working simultaneously.
251 # Use cp when mv fails, since DOS will fail mv for deeply-nested directories.
252 mv $PKNAME "$PKDESTDIR/pk$$.tmp" 2>/dev/null \
253 || cp $PKNAME "$PKDESTDIR/pk$$.tmp" || exit 1
254 cd "$PKDESTDIR" || exit 1
255 chmod `kpsestat -xst,go-w .` pk$$.tmp
256 test -r $PKNAME || mv pk$$.tmp $PKNAME || exit 1
258 # Update ls-R if necessary.
259 "$MT_MKTEXUPD" "$PKDESTDIR" $PKNAME
261 # If this line (or an equivalent) is not present, dvipsk/xdvik/dviljk
262 # will think mktexpk failed. Any other output to stdout will also lose.
263 echo "$PKDESTDIR/$PKNAME" >$STDOUT
264 echo "$progname: $PKDESTDIR/$PKNAME: successfully generated." >&2