3 # pic2graph -- compile PIC image descriptions to bitmap images
5 # by Eric S. Raymond <esr@thyrsus.com>, July 2002
7 # In Unixland, the magic is in knowing what to string together...
9 # Take a pic/eqn diagram on stdin, emit cropped bitmap on stdout.
10 # The pic markup should *not* be wrapped in .PS/.PE, this script will do that.
11 # An -unsafe option on the command line enables gpic/groff "unsafe" mode.
12 # A -format FOO option changes the image output format to any format
13 # supported by convert(1). An -eqn option changes the eqn delimiters.
14 # All other options are passed to convert(1). The default format in PNG.
16 # Requires the groff suite and the ImageMagick tools. Both are open source.
17 # This code is released to the public domain.
19 # Here are the assumptions behind the option processing:
21 # 1. Only the -U option of gpic(1) is relevant. -C doesn't matter because
22 # we're generating our own .PS/.PE, -[ntcz] are irrelevant because we're
23 # generating Postscript.
25 # 2. Ditto for groff(1), though it's a longer and more tedious demonstration.
27 # 3. Many options of convert(1) are potentially relevant (especially
28 # -density, -interlace, -transparency, -border, and -comment).
30 # Thus, we pass -U to gpic and groff, and everything else to convert(1).
32 # We don't have complete option coverage on eqn because this is primarily
33 # intended as a pic translator; we can live with eqn defaults.
55 echo "GNU pic2graph (groff) version @VERSION@"
58 echo "usage: pic2graph [ option ...] < in > out"
61 convert_opts
="$convert_opts $1";;
68 eqndelim
="delim $eqndelim"
72 # 1. Wrap the input in dummy .PS/PE macros (and add possibly null .EQ/.EN)
73 # 2. Process through eqn and pic to emit troff markup.
74 # 3. Process through groff to emit Postscript.
75 # 4. Use convert(1) to crop the PostScript and turn it into a bitmap.
76 tmp
=/usr
/tmp
/pic2graph-$$
77 trap "rm ${tmp}.*" 0 2 15
78 (echo ".EQ"; echo $eqndelim; echo ".EN"; echo ".PS"; cat; echo ".PE") | \
79 groff -e -p $groffpic_opts -Tps >${tmp}.ps \
80 && convert
-crop 0x0 $convert_opts ${tmp}.ps ${tmp}.${format} \
81 && cat ${tmp}.
${format}