summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/bpchem/bpchem.sty
blob: cb06644f293bfcc1d2db4bc4c82347cd352fe7b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
%%
%% This is file `bpchem.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% bpchem.dtx  (with options: `bpchem')
%% 
%% IMPORTANT NOTICE:
%% 
%% For the copyright see the source file.
%% 
%% Any modified versions of this file must be renamed
%% with new filenames distinct from bpchem.sty.
%% 
%% For distribution of the original source see the terms
%% for copying and modification in the file bpchem.dtx.
%% 
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
%% File: bpchem.dtx Copyright (C) 2001-2017
%%                 Bjoern Pedersen <Bjoern.Pedersen@ch.tum.de>
%% This file may be distributed and used freely under
%% the LaTeX Project Public License
%%
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bpchem}[2004/08/21 v1.1 Chemical input helper]
\RequirePackage{xspace}
 %\IUPAC{Tetra\|cyclo[2.2.2.1\^{1,4}]\-

\newif\ifusecbgreek%
\usecbgreekfalse%
\DeclareOption{cbgreek}{\PackageInfo{bpchem}{cbgreek selected}\usecbgreektrue}
\ProcessOptions\relax
%% Define a  textsubscript corresponing to textsuperscript.
%% This is now also available as the package textsubscript by
%% D.Arsenau or as part of KOMA-Script2 by M. Kohm.
%%
%%
\providecommand*\textsubscript[1]{%
  \@textsubscript{\selectfont#1}}
\def\@textsubscript#1{%
  {\m@th\ensuremath{_{\mbox{\fontsize\sf@size\z@#1}}}}}
%% a register to save the length to backspace
%% two registers needed to get back to correct
%% working position if one is longer than the other.
\newlength{\BPClensub}
\newlength{\BPClensuper}
\newlength{\BPCdelta}
%% we are in subscript and maybe  the superscript was longer
\DeclareRobustCommand{\BPCadjustsub}{%
  \setlength\BPCdelta{\BPClensuper}\addtolength\BPCdelta{-\BPClensub}%
  \ifdim\BPCdelta>0pt{\kern\BPCdelta}\else\relax\fi%
  \setlength{\BPClensub}{0pt}% reset
  \setlength{\BPClensuper}{0pt}% reset
}%
%% we are in superscript and maybe  the subscript was longer
\DeclareRobustCommand{\BPCadjustsuper}{%
  \setlength\BPCdelta{\BPClensub}\addtolength\BPCdelta{-\BPClensuper}%
  \ifdim\BPCdelta>0pt{\kern\BPCdelta}\else\relax\fi%
  \setlength{\BPClensub}{0pt}% reset
  \setlength{\BPClensuper}{0pt}% reset
}%
%% make a subscript and remember length in BPClen
\DeclareRobustCommand{\BPCsub}[1]{%
  \ifmmode_{#1}\settowidth\BPClensub{_{#1}}%
  \else\textsubscript{#1}\settowidth\BPClensub{\textsubscript{#1}}\fi%
  \futurelet\next\lookforsuper%
}%
%% make a superscript and remember length in BPClen
%% raise by 0.15 em, else e.g. + collides with subscript
\DeclareRobustCommand{\BPCsuper}[1]{%
  \ifmmode^{#1}\settowidth\BPClensuper{^{#1}}%
  \else\raisebox{0.15em}{\textsuperscript{#1}}%
  \settowidth\BPClensuper{\textsuperscript{#1}}\fi%
  \futurelet\next\lookforsub%
}%
%% see if next token is BPCsuper,
\DeclareRobustCommand\lookforsuper{%
  \ifx\next\BPCsuper\let\next=\BPCsuperbs%
  \else\let\next=\BPCadjustsub\fi\next%
}%
%% see if next token is BPCsub
\DeclareRobustCommand\lookforsub{%
  \ifx\next\BPCsub\let\next=\BPCsubbs%
  \else\let\next=\BPCadjustsuper\fi\next%
}%
%%  backspace BPClen and make superscript
%%  eats the old \verb|\^|
\DeclareRobustCommand{\BPCsuperbs}[1]{\kern-\BPClensub\BPCsuper}%
%% backspace and make subscript
%% eats the old \_
\DeclareRobustCommand{\BPCsubbs}[1]{\kern-\BPClensuper\BPCsub}%
%% needed to get catcodes right
\DeclareRobustCommand{\DoBPChem}{}%
\def\DoBPChem#1{%
  #1\endgroup%
}%
\DeclareRobustCommand{\BPCSetupCat}{}
\def\BPCSetupCat{%
  %\catcode`^=\active%
  %\catcode`\_=\active%
  \BPCSetup%
}%
\DeclareRobustCommand{\BPCSetup}{}
\def\BPCSetup{%
 \let\_=\BPCsub%
 \let\^=\BPCsuper%
}%end BPCSetup
%% setup for chemical formula
\DeclareRobustCommand\BPChem{%
  \begingroup% endgroup in DoBPChem
  \BPCSetupCat%
  \DoBPChem%
}
%% these are taken from german.sty and allow more than one break
%% or breaks and hyphens in a word. Very useful for chemical names,
%% as they tend to grow rather long. Two short versions are also defined
\DeclareRobustCommand{\allowhyphens}{\penalty\@M \hskip\z@skip}
\DeclareRobustCommand{\BreakHyph}{\penalty\@M -\allowhyphens}
\DeclareRobustCommand{\MultiBreak}%
  {\penalty\@M\discretionary{-}{}{\kern.03em}%
   \allowhyphens}
\let\MB=\MultiBreak \let\BH=\BreakHyph
\DeclareRobustCommand{\DoIUPAC}[1]{%
  #1\endgroup}
\def\Prep{%
  \let\-=\BreakHyph%
  \let\|=\MultiBreak%
  \DoIUPAC%
}
\DeclareRobustCommand*{\IUPAC}{%
  \begingroup\BPCSetup\ignorespaces%
  \Prep}%
\expandafter\DeclareRobustCommand\expandafter\|\expandafter{\|}
%% Trick by David Kastrup <David.Kastrup@t-online.de> to make
%% non-fragile. Otherwise \verb+\|+ would become \verb+\delimiter"026B30D+ in
%% e.g. the toc
%% Recent \LaTeX{} releases (starting with <2017-04-15>) define \cs{-} robust.
%% This resulted in a infinite loop with older version of bpchem. We could use
%% \cs{IncludeInRelease}, but it might be easier to just use the definition
%% from the latest \LaTeX{} releases.
\DeclareRobustCommand{\-}{%
  \discretionary{%
    \char \ifnum\hyphenchar\font<\z@%
            \defaulthyphenchar%
          \else%
            \hyphenchar\font%
          \fi%
  }{}{}%
}%    \end{macrocode}
%% counters for numbering of chemical substances
\newcounter{BPCno}
\renewcommand{\theBPCno}{\textbf{\arabic{BPCno}}}
\newcounter{BPCnoa}[BPCno]
\renewcommand{\theBPCnoa}{\textbf{\arabic{BPCno}\alph{BPCnoa}}}
%% helper functions to mark first definition
\newcommand{\newchems@b}[2]{
\expandafter\gdef\csname cna@#1#2\endcsname{#2}%
}
%% reference a CNlabel (useful for section titles, captions etc.)
\DeclareRobustCommand*{\CNref}[1]{%
  \ref{cn:#1}%
}
%% reference a CNlabel/sublabel
\DeclareRobustCommand*{\CNrefsub}[2]{%
  \ref{cn:#1#2}
%%\textbf{\csname cna@#1#2\endcsname}%
}
%% label a substance and insert the number
\DeclareRobustCommand*{\CNlabel}[1]{%
  \CNlabelnoref{#1}%
  \CNref{#1}%
}
\DeclareRobustCommand*{\CNlabelnoref}[1]{%
  \expandafter\ifx\csname cnd@#1\endcsname\relax%
  {\refstepcounter{BPCno}\label{cn:#1}}%
  \expandafter\gdef\csname cnd@#1\endcsname{x}%
  \fi%
}
\DeclareRobustCommand*{\CNlabelsub}[2]{%
  \CNlabelsubnoref{#1}{#2}%
  \CNrefsub{#1}{#2}%
}
\DeclareRobustCommand*{\CNlabelsubnoref}[2]{%
  \CNlabelnoref{#1}%
  \expandafter\ifx\csname cna@#1#2\endcsname\relax%
  {\refstepcounter{BPCnoa}\label{cn:#1#2}}%
  \expandafter\gdef\csname cna@#1#2\endcsname{x}%
%% \newchems@b{#1}{#2}%
%%   \write\@auxout{\string\newchems@b{#1}{#2}}%
  \fi%
}
%% more helper mcors
\DeclareRobustCommand{\HNMR}{\IUPAC{\^{1}H-NMR}: $\delta$\xspace}
\DeclareRobustCommand{\CNMR}{\IUPAC{\^{13}C-NMR}: $\delta$\xspace}
\DeclareRobustCommand{\cis}{\textit{cis}\xspace}
\DeclareRobustCommand{\trans}{\textit{trans}\xspace}
%%%%%%%%%%%%%%%%%%%%%
\ifusecbgreek% code with roman greek
  \PackageInfo{bpchem}{using upright greek fonts from cbgreek}
  \input{lgrenc.def}
  \DeclareRobustCommand{\rm@greekletter}[1]{{\fontencoding{LGR}\selectfont%
    \def\encodingdefault{LGR}#1}}%
  \DeclareRobustCommand{\bpalpha}{\rm@greekletter{a}}
  \DeclareRobustCommand{\bpbeta}{\rm@greekletter{b}}
  \DeclareRobustCommand{\bpDelta}{\rm@greekletter{D}}
  \DeclareRobustCommand{\hapto}[1]{\rm@greekletter{h}\^{#1}}
\else
  \PackageInfo{bpchem}{using default math greek fonts}
  \DeclareRobustCommand{\bpalpha}{\ensuremath{\alpha}\xspace}
  \DeclareRobustCommand{\bpbeta}{\ensuremath{\beta}\xspace}
  \DeclareRobustCommand{\bpDelta}{\ensuremath{\Delta}\xspace}
  \DeclareRobustCommand{\hapto}[1]{\ensuremath{\eta^{#1}}}
\fi%
\let\talpha\bpalpha
\let\tbeta\bpbeta
%%%%%%
\DeclareRobustCommand*{\dreh}[1]%
  {$\lbrack \alpha \rbrack _{\mathrm D}^{#1}$}
\endinput
%%
%% End of file `bpchem.sty'.