Added OX='n' -W-='n' case to gen_NFPA.sh
[chemdb.git] / docs / mp / gen_NFPA.sh
1 #!/bin/bash
2 #
3 # Generate NFPA.mp for given hazard levels
4
5 HEALTH=$1
6 FIRE=$2
7 REACT=$3
8 OX=$4
9 W=$5
10
11 REDIRECT=0 # if != 0, then print directly to OFILE
12 OFILE="NFPA.mp"
13
14 # stdout redirection from Advanced Bash Scripting Guide
15 # http://tldp.org/LDP/abs/html/x16355.html#REASSIGNSTDOUT
16 if [ $REDIRECT -ne 0 ]
17 then
18     exec 6>&1  # Link file descriptor #6 with stdout.
19                # Saves stdout.
20     # stdout replaced with file "logfile.txt".
21     exec > $OFILE
22 fi
23
24 echo "verbatimtex
25
26 \font\bigfont=cmss17 at 50pt
27 \font\medfont=cmss17 at 25pt
28 \font\smfont=cmss17 at 20pt
29 \bigfont
30
31 % center two hboxes (containing e.g. \OX and \W)
32 \def\vert#1#2{\vbox{\halign{\hfil##\hfil\cr
33 \hbox{#1}\cr
34 \hbox{#2}\cr}}}
35
36 % strikethrough (or strikeout) from Chapter 21 of the TeXbook
37 % the height of the strikeout has been raised from 0.8 to 0.9ex
38 % to make it look nicer when escaping a purely capital letter (W).
39 \def\sout#1{{%
40   \setbox0=\hbox{#1}%
41   \dimen0 0.9ex\dimen1\dimen0\advance\dimen1 by 0.4pt
42   \rlap{\leaders\hrule height \dimen1 depth -\dimen0\hskip\wd0}%
43   \box0
44 }}
45
46 \def\OX{{OX}}
47 \def\W{{\sout{W}}}
48
49 etex
50
51 %% NFPA values :
52 % set in the call to mpost, e.g.
53 % $ mpost 'input NFPA.mp; input NFPA_c.mp'
54 picture h,f,r,o;
55 h := btex $HEALTH etex;
56 f := btex $FIRE etex;
57 r := btex $REACT etex;"
58
59 if [ "$OX" == "y" ] && [ "$W" == "y" ]
60 then
61     echo "o := btex {\smfont \vert{\OX}{\W}} etex;"
62 elif [ "$OX" == "y" ]
63 then
64     echo "o := btex {\medfont \OX} etex;"
65 elif [ "$W" == "y" ]
66 then
67     echo "o := btex {\medfont \W} etex;"
68 else # both are "n"
69     echo "o := btex etex"
70 fi
71
72 if [ $REDIRECT -ne 0 ]
73 then
74     # Restore stdout and close file descriptor #6.
75     exec 1>&6 6>&-
76 fi
77
78 exit 0