Debian Codegraph @

texmf-dist/source/latex/bpchem/bpchem.dtx

raw
1 % \iffalse
2 %% File: bpchem.dtx Copyright (C) 2001-2017
3 %% Bjoern Pedersen <[email protected]>
4 %% This file may be distributed and used freely under
5 %% the LaTeX Project Public License
6 %%
7 %%
8 %
9 %<*dtx>
10 \ProvidesFile{bpchem.dtx}[2017/08/23 v1.1 Chemical input helper]
11 %</dtx>
12 %<bpchem>\NeedsTeXFormat{LaTeX2e}
13 %<bpchem>\ProvidesPackage{bpchem}[2004/08/21 v1.1 Chemical input helper]
14 %<bpchem>\RequirePackage{xspace}
15 %<driver>\ProvidesFile{bpchem.drv}
16 % \fi
17 %\iffalse
18 %<*driver>
19 \documentclass{ltxdoc}
20 \usepackage[latin1]{inputenc}
21 \usepackage[T1]{fontenc}
22 \usepackage{bpchem}
23 \RecordChanges
24 \begin{document}
25 \DocInput{bpchem.dtx}
26 \end{document}
27 %</driver>
28 %\fi
29 % \changes{v1.1}{2017/08/23}{
30 % Resolved conflict with recent \LaTeX{} releases (thanks to Ulrike Fischer
31 % and Martin Sievers)
32 % }
33 %
34 % \changes{v1.05}{2004/11/06}{
35 % changed email
36 % }
37 % \changes{v1.03}{2002/11/01}{
38 % re-added lost email-address
39 % }
40 % \GetFileInfo{bpchem.dtx}
41 % \title{The \textsf{bpchem} package\thanks{This file
42 % has version number \fileversion, last
43 % revised \filedate.}}
44 % \author{Bj{\o}rn Pedersen\\ \texttt{[email protected]}}
45 % \date{\filedate}
46 % \maketitle
47 % \section{Introduction}
48 % This package has been written to alleviate the task of writing
49 % publications containing lots of chemistry. It provides methods for
50 % typesetting chemical names, sum formulae and isotopes. It provides the
51 % possibility to break very long names even over several lines.
52 %
53 % This package also provides a way to automatically enumerate your
54 % chemical compounds, allowing for one-level subgrouping.
55 %
56 % What this package does not provide: Methods to draw chemical
57 % compounds. Although there exist some packages,which where designed for
58 % this purpose (e.g. xymtex, PPChTex) they are quite limited once you
59 % get to complex organic, or metal organic compounds. I recommend using
60 % an external drawing program, possibly in conjunction with psfrag, in
61 % these cases.
62 %
63 %\section{Package options}
64 % Currently this package supports only one option:
65 %
66 % \verb|cbgreek|
67 %
68 % this option causes the definitions of some macros to be changed to
69 % use the cbgreek fonts. As they are not available on all systems,
70 % and only in mf format, the default is to use the math fonts for
71 % greek symbols.
72 %
73 %\section{User commands in this package}
74 %\subsection{Setting chemical sum formulae: BPChem{<chemical formula>}}
75 %\DescribeMacro{\BPChem}
76 %Within this macro you can use \verb|\_| and \verb|\^| for correct
77 %chemical sub- and superscripts.
78 %Example:
79 %\begin{verbatim}
80 %\BPChem{C\_2H\_5OH} or \BPChem{SO\_4\^{2-}}
81 %\end{verbatim}
82 %\begin{minipage}{10cm}
83 %\BPChem{C\_2H\_5OH} or \BPChem{SO\_4\^{2-}}
84 %\end{minipage}
85 %\subsection{Setting long chemical names: IUPAC{<formula or name>}}
86 %\DescribeMacro{\IUPAC}
87 %in addition to sub/superscripts as above, \verb|\-| is a hyphen which
88 %allows further breakpoints,\verb!\|! is an (invisible) Multibreakpoint.
89 %
90 %This environment is especially useful for your long IUPAC-compound names.
91 %
92 %Example:
93 %\begin{verbatim}
94 %\IUPAC{Tetra\|cyclo[2.2.2.1\^{1,4}]\-
95 %un\|decane-2\-dodecyl\-5\-(hepta\|decyl\|iso\|dodecyl\|thio\|ester)}
96 %\end{verbatim}
97 %\begin{minipage}{15em}
98 %\IUPAC{Tetra\|cyclo[2.2.2.1\^{1,4}]\-^^A
99 %un\|decane-2\-dodecyl\-5\-(hepta\|decyl\|iso\|dodecyl\|thio\|ester)}
100 %\end{minipage}
101 %
102 %\subsection{Enumerating and referencing chemical compounds: CNlabel\{<label>\}, CNlabelnoref\{<label>\}, CNref\{<label>\}}
103 %\DescribeMacro{\CNlabel}\DescribeMacro{\CNlabelnoref}\DescribeMacro{\CNref}
104 %\verb|CNlabel| defines and use \verb|#1| (via \verb|ref|) as label for
105 %numbering of chemical compounds. If the label has not yet been
106 %defined, it is created, otherwise it is just referenced. if you just
107 %want to define the label, use \verb|\CNlabelnoref| instead.
108 %
109 %If you want to get just the reference, use \verb|\CNref|. This comes
110 %handy for figure captions or section titles, as you would get
111 %dissorder in the numbering due to the moving argument otherwise.
112 %
113 %The default style is: \verb|\textbf{\arabic{\counter}}|
114 %
115 %To change, use something like \begin{verbatim}
116 %\renewcommand{\theBPCno}{\textbf{\arabic{BPCno}}}
117 %\end{verbatim}
118
119 %Example:
120 %\begin{verbatim}
121 %Alkohol \CNlabel{al} is converted to aldehyd \CNlabel{ad}. \CNref{al}
122 %can also be used otherwise, while \CNref{ad} cannot.
123 %\end{verbatim}
124 %\begin{minipage}{20em}
125 %Alkohol \CNlabel{al} is converted to aldehyd \CNlabel{ad}. \CNref{al}
126 %can also be used otherwise, while \CNref{ad} cannot.
127 %\end{minipage}
128 %
129 %
130 %\subsection{Using sub-labels for classes of compounds: CNlabelsub\{<label>\}\{<sublabel>\},
131 %\\CNlabelsubnoref\{<label>\}\{<sublabel>\},\\CNrefsub\{<label>\}\{<sublabel>\}}
132 %\DescribeMacro{\CNlabelsub}\DescribeMacro{\CNlabelsubnoref}\DescribeMacro{\CNrefsub}
133 %These commands are the same as above, with additional sub identifier
134 %\verb|#2| added. If the primary identifier is not yet used, it will be
135 %created and can also be referenced via the normal commands.
136 %
137 %The default style is:\verb|\textbf{\arabic{BPCno}\alph{BPCnoa}}}|
138 %
139 %To change, use something like \begin{verbatim}
140 %\renewcommand{\theBPCnoa}{\textbf{\arabic{BPCno}\alph{BPCnoa}}}
141 %\end{verbatim}
142 %
143 %\begin{verbatim}
144 %To demonstrate the use of sublabels, methanol \CNlabelsub{alk}{a} and
145 %ethanol \CNlabelsub{alk}{b} are both natural products. The acohols \CNref{alk}
146 %can synthezied bio-chemically. \CNrebsub{alk}{a} is toxic, while
147 %\CNrefsub{alk}{b} is only mildly toxic.
148 %\end{verbatim}
149 %\begin{minipage}{20em}
150 %To demonstrate the use of sublabels, methanol \CNlabelsub{alk}{a} and
151 %ethanol \CNlabelsub{alk}{b} are both natural products. The alcohols \CNref{alk}
152 %can synthezied bio-chemically. \CNrefsub{alk}{a} is toxic, while
153 %\CNrefsub{alk}{b} is only mildly toxic.
154 %\end{minipage}
155 %
156 %\subsection{Shortcuts for common idioms in chemical literature}
157 %
158 %
159 %\begin{description}
160 %\item[\HNMR] \verb|\HNMR|
161 %\item[\CNMR] \verb|\CNMR|
162 %\item[\cis] \verb|\cis|
163 %\item[\trans] \verb|\trans|
164 %\item[\bpalpha] \verb|\bpalpha|
165 %\item[\bpbeta] \verb|\bpbeta|
166 %\item[\bpDelta] \verb|\bpdelta|
167 %\item[\IUPAC{\hapto{<nummer>}}] \verb|\hapto{<number>}|
168 %\end{description}
169 %\textbf{Note:} Some of these macros are influenced by the
170 %\verb|cbgreek| option! Use is only recommended with the
171 %\verb|\BPChem| and \verb|\IUPAC| commands. Some will not even work
172 %outside those commands.
173 %
174 %\section{Example}
175 %\begin{verbatim}
176 %\begin{minipage}[b]{15em}
177 %some normal text and math: $A*2=B$
178 %
179 %Test \BPChem{ C\_{2}H\_{4}\^{+}}
180 %or using math in superscript \BPChem{ C\_{2}H\_{4}\^{$+$}}
181 %
182 %\BPChem{Example\_{longer subscript}\^{superscript}}
183 %
184 %Isotope: \BPChem{\_{A}\^{B}X\^{C}\_{D}}
185 %
186 %\IUPAC{Tetra\|cyclo[2.2.2.1\^{1,4}]\-^^A
187 %un\|decane-2\-dodecyl-5-(heptadecyl\|iso\|dodecyl\|thio\|ester)}
188 %\end{minipage}
189 %\end{verbatim}
190 % and the resulting output:
191 %
192 %\begin{minipage}[b]{15em}
193 %some normal text and math: $A*2=B$, just to show it.
194 %
195 %Test \BPChem{ C\_{2}H\_{4}\^{+}}
196 %or using math in superscript \BPChem{ C\_{2}H\_{4}\^{$+$}}
197 %
198 %\BPChem{Example\_{longer subscript}\^{superscript}} And normal Text again
199 %
200 %Isotope: \BPChem{\_{A}\^{B}X\^{C}\_{D}}
201 %
202 %
203 %\IUPAC{Tetra\|cyclo[2.2.2.1\^{1,4}]\-^^A
204 %un\|decane-2\-dodecyl\-5\-(hepta\|decyl\|iso\|dodecyl\|thio\|ester)}
205 %\end{minipage}
206 %
207 %\StopEventually
208 %
209 %\section{The code}
210 %<*bpchem>^^J
211 % first comes some option setup
212 % \begin{macrocode}
213 \newif\ifusecbgreek%
214 \usecbgreekfalse%
215 \DeclareOption{cbgreek}{\PackageInfo{bpchem}{cbgreek selected}\usecbgreektrue}
216 \ProcessOptions\relax
217 % \end{macrocode}
218 %\begin{macro}{\textsubscript}
219 %% Define a textsubscript corresponing to textsuperscript.
220 %% This is now also available as the package textsubscript by
221 %% D.Arsenau or as part of KOMA-Script2 by M. Kohm.
222 %%
223 %%
224 % \begin{macrocode}
225 \providecommand*\textsubscript[1]{%
226 \@textsubscript{\selectfont#1}}
227 \def\@textsubscript#1{%
228 {\m@th\ensuremath{_{\mbox{\fontsize\sf@size\z@#1}}}}}
229 % \end{macrocode}
230 %\end{macro}
231 %% a register to save the length to backspace
232 %% two registers needed to get back to correct
233 %% working position if one is longer than the other.
234 % \begin{macrocode}
235 \newlength{\BPClensub}
236 \newlength{\BPClensuper}
237 \newlength{\BPCdelta}
238 % \end{macrocode}
239 %% we are in subscript and maybe the superscript was longer
240 % \begin{macrocode}
241 \DeclareRobustCommand{\BPCadjustsub}{%
242 \setlength\BPCdelta{\BPClensuper}\addtolength\BPCdelta{-\BPClensub}%
243 \ifdim\BPCdelta>0pt{\kern\BPCdelta}\else\relax\fi%
244 \setlength{\BPClensub}{0pt}% reset
245 \setlength{\BPClensuper}{0pt}% reset
246 }%
247 % \end{macrocode}
248 %% we are in superscript and maybe the subscript was longer
249 % \begin{macrocode}
250 \DeclareRobustCommand{\BPCadjustsuper}{%
251 \setlength\BPCdelta{\BPClensub}\addtolength\BPCdelta{-\BPClensuper}%
252 \ifdim\BPCdelta>0pt{\kern\BPCdelta}\else\relax\fi%
253 \setlength{\BPClensub}{0pt}% reset
254 \setlength{\BPClensuper}{0pt}% reset
255 }%
256 % \end{macrocode}
257 %% make a subscript and remember length in BPClen
258 % \begin{macrocode}
259 \DeclareRobustCommand{\BPCsub}[1]{%
260 \ifmmode_{#1}\settowidth\BPClensub{_{#1}}%
261 \else\textsubscript{#1}\settowidth\BPClensub{\textsubscript{#1}}\fi%
262 \futurelet\next\lookforsuper%
263 }%
264 % \end{macrocode}
265 %% make a superscript and remember length in BPClen
266 %% raise by 0.15 em, else e.g. + collides with subscript
267 % \begin{macrocode}
268 \DeclareRobustCommand{\BPCsuper}[1]{%
269 \ifmmode^{#1}\settowidth\BPClensuper{^{#1}}%
270 \else\raisebox{0.15em}{\textsuperscript{#1}}%
271 \settowidth\BPClensuper{\textsuperscript{#1}}\fi%
272 \futurelet\next\lookforsub%
273 }%
274 % \end{macrocode}
275 %% see if next token is BPCsuper,
276 % \begin{macrocode}
277 \DeclareRobustCommand\lookforsuper{%
278 \ifx\next\BPCsuper\let\next=\BPCsuperbs%
279 \else\let\next=\BPCadjustsub\fi\next%
280 }%
281 % \end{macrocode}
282 %% see if next token is BPCsub
283 % \begin{macrocode}
284 \DeclareRobustCommand\lookforsub{%
285 \ifx\next\BPCsub\let\next=\BPCsubbs%
286 \else\let\next=\BPCadjustsuper\fi\next%
287 }%
288 % \end{macrocode}
289 %% backspace BPClen and make superscript
290 %% eats the old \verb|\^|
291 % \begin{macrocode}
292 \DeclareRobustCommand{\BPCsuperbs}[1]{\kern-\BPClensub\BPCsuper}%
293 % \end{macrocode}
294 %% backspace and make subscript
295 %% eats the old \_
296 % \begin{macrocode}
297 \DeclareRobustCommand{\BPCsubbs}[1]{\kern-\BPClensuper\BPCsub}%
298 % \end{macrocode}
299 %% needed to get catcodes right
300 % \begin{macrocode}
301 \DeclareRobustCommand{\DoBPChem}{}%
302 \def\DoBPChem#1{%
303 #1\endgroup%
304 }%
305 \DeclareRobustCommand{\BPCSetupCat}{}
306 \def\BPCSetupCat{%
307 %\catcode`^=\active%
308 %\catcode`\_=\active%
309 \BPCSetup%
310 }%
311 \DeclareRobustCommand{\BPCSetup}{}
312 \def\BPCSetup{%
313 \let\_=\BPCsub%
314 \let\^=\BPCsuper%
315 }%end BPCSetup
316 % \end{macrocode}
317 %% setup for chemical formula
318 % \begin{macrocode}
319 \DeclareRobustCommand\BPChem{%
320 \begingroup% endgroup in DoBPChem
321 \BPCSetupCat%
322 \DoBPChem%
323 }
324 % \end{macrocode}
325 %% these are taken from german.sty and allow more than one break
326 %% or breaks and hyphens in a word. Very useful for chemical names,
327 %% as they tend to grow rather long. Two short versions are also defined
328 % \changes{v1.05}{2004/11/06}{
329 % fixed whitespace bug in \cs{DoIUPAC}
330 % }
331 % \begin{macrocode}
332 \DeclareRobustCommand{\allowhyphens}{\penalty\@M \hskip\z@skip}
333 \DeclareRobustCommand{\BreakHyph}{\penalty\@M -\allowhyphens}
334 \DeclareRobustCommand{\MultiBreak}%
335 {\penalty\@M\discretionary{-}{}{\kern.03em}%
336 \allowhyphens}
337 \let\MB=\MultiBreak \let\BH=\BreakHyph
338 \DeclareRobustCommand{\DoIUPAC}[1]{%
339 #1\endgroup}
340 \def\Prep{%
341 \let\-=\BreakHyph%
342 \let\|=\MultiBreak%
343 \DoIUPAC%
344 }
345 \DeclareRobustCommand*{\IUPAC}{%
346 \begingroup\BPCSetup\ignorespaces%
347 \Prep}%
348 % \end{macrocode}
349 % \changes{v1.03}{2002/11/01}{%
350 % fixed bug in \cs{IUPAC}, \texttt{\textbackslash$\vert$} is not getting
351 % translated to \cs{delimiter} during \cs{write} anymore
352 % }
353 % \begin{macrocode}
354 \expandafter\DeclareRobustCommand\expandafter\|\expandafter{\|}
355 % \end{macrocode}
356 % \changes{v1.04}{2002/12/14}{also \cs{-} was affected, fixed}
357 %% Trick by David Kastrup <[email protected]> to make
358 %% non-fragile. Otherwise \verb+\|+ would become \verb+\delimiter"026B30D+ in
359 %% e.g. the toc
360 % \changes{v1.1}{2017/08/23}{%
361 % Recent \LaTeX{} releases make \cs{-} robust as
362 % well. This results in an infinite loop.
363 % }
364 %% Recent \LaTeX{} releases (starting with <2017-04-15>) define \cs{-} robust.
365 %% This resulted in a infinite loop with older version of bpchem. We could use
366 %% \cs{IncludeInRelease}, but it might be easier to just use the definition
367 %% from the latest \LaTeX{} releases.
368 % \begin{macrocode}
369 \DeclareRobustCommand{\-}{%
370 \discretionary{%
371 \char \ifnum\hyphenchar\font<\z@%
372 \defaulthyphenchar%
373 \else%
374 \hyphenchar\font%
375 \fi%
376 }{}{}%
377 }% \end{macrocode}
378 %% counters for numbering of chemical substances
379 % \begin{macrocode}
380 \newcounter{BPCno}
381 \renewcommand{\theBPCno}{\textbf{\arabic{BPCno}}}
382 %
383 \newcounter{BPCnoa}[BPCno]
384 \renewcommand{\theBPCnoa}{\textbf{\arabic{BPCno}\alph{BPCnoa}}}
385 % \end{macrocode}
386 %% helper functions to mark first definition
387 % \begin{macrocode}
388 \newcommand{\newchems@b}[2]{
389 \expandafter\gdef\csname cna@#1#2\endcsname{#2}%
390 }
391 % \end{macrocode}
392 %% reference a CNlabel (useful for section titles, captions etc.)
393 % \begin{macrocode}
394 \DeclareRobustCommand*{\CNref}[1]{%
395 \ref{cn:#1}%
396 }
397 % \end{macrocode}
398 %% reference a CNlabel/sublabel
399 % \begin{macrocode}
400 \DeclareRobustCommand*{\CNrefsub}[2]{%
401 \ref{cn:#1#2}
402 %%\textbf{\csname cna@#1#2\endcsname}%
403 }
404 % \end{macrocode}
405 %% label a substance and insert the number
406 % \changes{v1.06}{2004/11/25}{
407 % fixed whitespace bug in CNlabel
408 % }
409 % \begin{macrocode}
410 \DeclareRobustCommand*{\CNlabel}[1]{%
411 \CNlabelnoref{#1}%
412 \CNref{#1}%
413 }
414 % \end{macrocode}
415 % \begin{macrocode}
416 \DeclareRobustCommand*{\CNlabelnoref}[1]{%
417 \expandafter\ifx\csname cnd@#1\endcsname\relax%
418 {\refstepcounter{BPCno}\label{cn:#1}}%
419 \expandafter\gdef\csname cnd@#1\endcsname{x}%
420 \fi%
421 }
422 % \end{macrocode}
423 % \begin{macrocode}
424 \DeclareRobustCommand*{\CNlabelsub}[2]{%
425 \CNlabelsubnoref{#1}{#2}%
426 \CNrefsub{#1}{#2}%
427 }
428 \DeclareRobustCommand*{\CNlabelsubnoref}[2]{%
429 \CNlabelnoref{#1}%
430 \expandafter\ifx\csname cna@#1#2\endcsname\relax%
431 {\refstepcounter{BPCnoa}\label{cn:#1#2}}%
432 \expandafter\gdef\csname cna@#1#2\endcsname{x}%
433 %% \newchems@b{#1}{#2}%
434 %% \write\@auxout{\string\newchems@b{#1}{#2}}%
435 \fi%
436 }
437 % \end{macrocode}
438 %% more helper mcors
439 % special symbols and macros for math-symbols without math-mode
440 % \changes{v1.03}{2002/11/01}{added cbgreek option for using upright
441 % greek and fixed namespace, old names will still work}
442 % \begin{macrocode}
443 \DeclareRobustCommand{\HNMR}{\IUPAC{\^{1}H-NMR}: $\delta$\xspace}
444 \DeclareRobustCommand{\CNMR}{\IUPAC{\^{13}C-NMR}: $\delta$\xspace}
445 \DeclareRobustCommand{\cis}{\textit{cis}\xspace}
446 \DeclareRobustCommand{\trans}{\textit{trans}\xspace}
447 %\DeclareRobustCommand{\R}{\textit{R}}
448 %\DeclareRobustCommand{\S}{\textit{S}}
449 %%%%%%%%%%%%%%%%%%%%%
450 \ifusecbgreek% code with roman greek
451 \PackageInfo{bpchem}{using upright greek fonts from cbgreek}
452 \input{lgrenc.def}
453 \DeclareRobustCommand{\rm@greekletter}[1]{{\fontencoding{LGR}\selectfont%
454 \def\encodingdefault{LGR}#1}}%
455 % some examples
456 \DeclareRobustCommand{\bpalpha}{\rm@greekletter{a}}
457 \DeclareRobustCommand{\bpbeta}{\rm@greekletter{b}}
458 \DeclareRobustCommand{\bpDelta}{\rm@greekletter{D}}
459 \DeclareRobustCommand{\hapto}[1]{\rm@greekletter{h}\^{#1}}
460 \else
461 % code with standard math greek
462 \PackageInfo{bpchem}{using default math greek fonts}
463 \DeclareRobustCommand{\bpalpha}{\ensuremath{\alpha}\xspace}
464 \DeclareRobustCommand{\bpbeta}{\ensuremath{\beta}\xspace}
465 \DeclareRobustCommand{\bpDelta}{\ensuremath{\Delta}\xspace}
466 \DeclareRobustCommand{\hapto}[1]{\ensuremath{\eta^{#1}}}
467 \fi%
468 \let\talpha\bpalpha
469 \let\tbeta\bpbeta
470 %%%%%%
471 \DeclareRobustCommand*{\dreh}[1]%
472 {$\lbrack \alpha \rbrack _{\mathrm D}^{#1}$}
473 % \end{macrocode}
474 %</bpchem>
475 % \PrintChanges
476 % \CheckSum{372}
477 % \Finale