1 % nfpa_704.sty, a package for generating NFPA fire diamonds.
4 % Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
6 % This file is part of ChemDB.
8 % ChemDB is free software: you can redistribute it and/or modify it
9 % under the terms of the GNU General Public License as published by the
10 % Free Software Foundation, either version 3 of the License, or (at your
11 % option) any later version.
13 % ChemDB is distributed in the hope that it will be useful,
14 % but WITHOUT ANY WARRANTY; without even the implied warranty of
15 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 % GNU General Public License for more details.
18 % You should have received a copy of the GNU General Public License
19 % along with ChemDB. If not, see <http://www.gnu.org/licenses/>.
22 % http://en.wikipedia.org/wiki/NFPA_704
23 % for more information on the NFPA 704 "fire diamond".
25 \NeedsTeXFormat{LaTeX2e}[1995/12/01]
26 \ProvidesPackage{nfpa_704}
27 [2010/08/24 v0.1 NFPA flammability diamond]
29 \RequirePackage{forloop} % program flow control
30 \RequirePackage{tikz} % graphics
31 \RequirePackage{ulem} % strikethrough (or strikeout)
32 \RequirePackage{xkeyval} % handling x=y-type options
33 \normalem % use the standard \em, not ulem's version
35 % Raise \ulem's \sout height a bit to look nicer striking out capital
37 \def\nfpa@caps@sout{\bgroup \ULdepth=-1ex \ULset}
39 \newcommand{\nowater}{\nfpa@caps@sout{W}}
40 \newcommand{\oxidizer}{OXY}
41 \newcommand{\asphixiant}{SA}
43 \newcommand{\nfpa@firediamond@radius}{}
44 \newcommand{\nfpa@firediamond@health}{}
45 \newcommand{\nfpa@firediamond@flammability}{}
46 \newcommand{\nfpa@firediamond@reactivity}{}
47 \newcommand{\nfpa@firediamond@extraspecial}{}
49 \define@key{firediamond}{radius}{\def\nfpa@firediamond@radius{#1}}
50 \define@key{firediamond}{health}{\def\nfpa@firediamond@health{#1}}
51 \define@key{firediamond}{flammability}{\def\nfpa@firediamond@flammability{#1}}
52 \define@key{firediamond}{reactivity}{\def\nfpa@firediamond@reactivity{#1}}
53 \define@boolkey{firediamond}{nowater}[true]{}
54 \define@boolkey{firediamond}{oxidizer}[true]{}
55 \define@boolkey{firediamond}{asphixiant}[true]{}
56 \define@key{firediamond}{special}{\def\nfpa@firediamond@extraspecial{#1}}
57 \presetkeys{firediamond}{% set default values
59 health=0,flammability=0,reactivity=0,
60 nowater=false,oxidizer=false,asphixiant=false,
62 {}% post-process input parameters
64 \newcounter{nfpa@firediamond@ispecial}
65 \newcounter{nfpa@firediamond@jspecial}
66 \newcommand{\nfpa@firediamond@clearspecial}{%
67 \setcounter{nfpa@firediamond@ispecial}{0}%
70 % Add a special string (e.g. \nowater, \oxidizer, ...).
71 \newcommand{\nfpa@firediamond@addspecial}[1]{%
72 \addtocounter{nfpa@firediamond@ispecial}{1}%
73 \expandafter\gdef\csname nfpa@firediamond@special@\alph{nfpa@firediamond@ispecial}\endcsname{#1}%
76 % Add a special string, evaluating the value of #1 immediately. This
77 % is important in the case of \nfpa@firediamond@makespecial's \@ii, as
78 % it will be set to \@nil after looping. However, it will fail for some
79 % macros. For example, \nfpa@firediamond@xaddspecial{\nowater} raises
80 % ! Undefined control sequence.
81 % \ULset ...ce \ULdepth .4\p@ \fi \def \UL@leadtype
82 % {\leaders \hrule \@height ...
83 \newcommand{\nfpa@firediamond@xaddspecial}[1]{%
84 \addtocounter{nfpa@firediamond@ispecial}{1}%
85 \expandafter\xdef\csname nfpa@firediamond@special@\alph{nfpa@firediamond@ispecial}\endcsname{#1}%
88 \newcommand{\nfpa@firediamond@getspecial}[1]{%
89 \csname nfpa@firediamond@special@\alph{#1}\endcsname%
92 % Print the contents of the special quadrant and beyond.
94 % From http://www.nfpa.org/assets/files/PDF/ROP/704-A2006-ROP.pdf
96 % 704-4 Log #CP4 Final Action: Accept
97 % (8.2.3 and Figures 9.1(a) and (c))
99 % SUBSTANTIATION: The committee expressed concern that for the
100 % relatively few chemicals requiring both an "OX" and "W" symbols in
101 % the special hazards quadrant, there wouldn’t be enough room for
102 % both to appear in the prescribed sizes for clear visibility. The
103 % committee believed the "W" is the primary hazard and should be
104 % displayed inside the quadrant, with the "OX" outside the
105 % quadrant. It was reported that many large companies have adopted
106 % this practice successfully already. The figures were enhanced for
108 \newcommand{\nfpa@firediamond@makespecial}{%
109 \nfpa@firediamond@clearspecial{}%
110 \ifKV@firediamond@nowater\nfpa@firediamond@addspecial{\nowater}\fi%
111 \ifKV@firediamond@oxidizer\nfpa@firediamond@addspecial{\oxidizer}\fi%
112 \ifKV@firediamond@asphixiant\nfpa@firediamond@addspecial{\asphixiant}\fi%
114 % http://www.tex.ac.uk/ctan/macros/latex/base/ltcntrl.dtx
115 % for details on LaTeX program control macros.
116 \@for\@ii:=\nfpa@firediamond@extraspecial\do{%
117 \nfpa@firediamond@xaddspecial{\@ii}}%
120 % Print the contents of the special quadrant.
121 \newcommand{\nfpa@firediamond@special}{%
122 \ifnum\value{nfpa@firediamond@ispecial}>0%
123 \setcounter{nfpa@firediamond@jspecial}{1}%
124 \nfpa@firediamond@getspecial{nfpa@firediamond@jspecial}%
128 % Print special contents to be printed below the special quadrant.
129 \newcommand{\nfpa@firediamond@underspecial}{%
131 \setlength{\parskip}{0pt}%
132 \setlength{\parindent}{0pt}%
133 \addtocounter{nfpa@firediamond@ispecial}{1}%
134 \forloop{nfpa@firediamond@jspecial}% counter
136 {\value{nfpa@firediamond@jspecial} < \value{nfpa@firediamond@ispecial}}% condition
137 {\nfpa@firediamond@getspecial{nfpa@firediamond@jspecial}\\}% code
138 \addtocounter{nfpa@firediamond@ispecial}{-1}%
142 \newcommand{\firediamond}[1]{%
143 \setkeys{firediamond}{#1}%
144 \nfpa@firediamond@makespecial{}%
145 % Simple text output for debugging xkeyval parameter setup.
146 %Health: \nfpa@firediamond@health \\
147 %Flammability: \nfpa@firediamond@flammability \\
148 %Reactivity: \nfpa@firediamond@reactivity \\
149 %Special: \par\nfpa@firediamond@special\par
151 % Draw the NFPA diamond
152 \begin{tikzpicture}[x=\nfpa@firediamond@radius, y=\nfpa@firediamond@radius]
153 % draw the background colors
154 \fill[blue] (0,0) -- (-0.5,-0.5) -- (-1,0) -- (-0.5,0.5) -- cycle;
155 \fill[red] (0,0) -- (-0.5,0.5) -- (0,1) -- (0.5,0.5) -- cycle;
156 \fill[yellow] (0,0) -- (0.5,0.5) -- (1,0) -- (0.5,-0.5) -- cycle;
157 \fill[white] (0,0) -- (0.5,-0.5) -- (0,-1) -- (-0.5,-0.5) -- cycle;
160 \draw (-0.5,-0.5) -- (0.5,0.5);
161 \draw (-0.5,0.5) -- (0.5,-0.5);
162 \draw (-1,0) -- (0,1) -- (1,0) -- (0,-1) -- cycle;
165 \draw (-0.5,0) node { \nfpa@firediamond@health};
166 \draw (0,0.5) node { \nfpa@firediamond@flammability};
167 \draw (0.5,0) node { \nfpa@firediamond@reactivity};
168 \draw (0,-0.5) node[text width=\nfpa@firediamond@radius, text centered]
169 { \nfpa@firediamond@special};
170 \draw (0,-1) node[text width=\nfpa@firediamond@radius, text centered,
172 { \nfpa@firediamond@underspecial};