summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty
blob: c39f55d06148f713abbc17d4a5b92bffd0925aec (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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
% --------------------------------------------------------------------------
% the CHEMMACROS package
%
%   comprehensive support for typesetting chemistry documents
%
% --------------------------------------------------------------------------
% Clemens Niederberger
% --------------------------------------------------------------------------
% https://github.org/cgnieder/chemmacros/
% contact@mychemistry.eu
% --------------------------------------------------------------------------
% If you have any ideas, questions, suggestions or bugs to report, please
% feel free to contact me.
% --------------------------------------------------------------------------
% Copyright 2011-2016 Clemens Niederberger
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Clemens Niederberger.
% --------------------------------------------------------------------------
\RequirePackage{expl3,xparse,l3keys2e}
\ExplSyntaxOn

% --------------------------------------------------------------------------
% package information:
\tl_const:Nn \c_chemmacros_date_tl {2016/05/04}
\tl_const:Nn \c_chemmacros_version_major_number_tl {5}
\tl_const:Nn \c_chemmacros_version_minor_number_tl {6}
\tl_const:Nn \c_chemmacros_version_subrelease_tl   {a}
\tl_const:Nx \c_chemmacros_version_number_tl
  {\c_chemmacros_version_major_number_tl.\c_chemmacros_version_minor_number_tl}
\tl_const:Nx \c_chemmacros_version_tl
  { \c_chemmacros_version_number_tl \c_chemmacros_version_subrelease_tl }
\tl_const:Nn \c_chemmacros_info_tl
  {comprehensive~ support~ for~ typesetting~ chemistry~ documents}

\ProvidesExplPackage
  {chemmacros}
  {\c_chemmacros_date_tl}
  {\c_chemmacros_version_tl}
  {\c_chemmacros_info_tl \c_space_tl (CN)}

% --------------------------------------------------------------------------
% set compatibility
\fp_new:N \l__chemmacros_compatibility_version_fp
\fp_set:Nn \l__chemmacros_compatibility_version_fp {\c_chemmacros_version_number_tl}

\keys_define:nn {chemmacros/compatibility}
  {
    compatibility .code:n =
      \str_case:nnTF {#1}
        {
          {newest} {}
          {latest} {}
        }
        {
          \fp_set:Nn \l__chemmacros_compatibility_version_fp
            { \c_chemmacros_version_number_tl }
        }
        { \fp_set:Nn \l__chemmacros_compatibility_version_fp {#1} } ,
    unknown       .code:n =
      \PassOptionsToPackage{\CurrentOption}{chemmacros4}
      \PassOptionsToPackage{\CurrentOption}{chemmacros5}
  }

\ProcessKeysPackageOptions {chemmacros/compatibility}

% --------------------------------------------------------------------------
% compare version numbers
% #1: number
% #2: relation
% #3: number
% #4: true
% #5: false
\prg_new_conditional:Npnn \chemmacros_if_version:nnn #1#2#3 {p,T,F,TF}
  {
    \fp_compare:nTF { floor(#1) = floor(#3) }
      {
        \fp_compare:nTF
          {
            ( \chemmacros_get_minor_version:f {#1} )
            #2
            ( \chemmacros_get_minor_version:f {#3} )
          }
          { \prg_return_true: }
          { \prg_return_false: }
      }
      {
        \fp_compare:nTF { (#1) #2 (#3) }
          { \prg_return_true: }
          { \prg_return_false: }
      }
  }

\cs_new:Npn \__chemmacros_get_minor_version:w #1.#2.#3 \q_stop
  { \tl_if_blank:nTF {#2} {0} {#2} }
\cs_new:Npn \chemmacros_get_minor_version:n #1
  { \__chemmacros_get_minor_version:w #1.. \q_stop }
\cs_generate_variant:Nn \chemmacros_get_minor_version:n {f}

% check compatibility
% #1: relation
% #2: number
% #3: true
% #4: false
\prg_new_conditional:Npnn \chemmacros_if_compatiblity:nn #1#2 {p,T,F,TF}
  {
    \chemmacros_if_version:nnnTF
      { \fp_to_decimal:N \l__chemmacros_compatibility_version_fp }
      {#1}
      {#2}
      { \prg_return_true: }
      { \prg_return_false: }
  }
\cs_generate_variant:Nn \chemmacros_if_compatiblity:nnT {nV}

% user checks:
\NewDocumentCommand \IfChemCompatibilityTF {mm+m+m}
  { \chemmacros_if_compatiblity:nnTF {#1} {#2} {#3} {#4} }

\NewDocumentCommand \IfChemCompatibilityT {mm+m}
  { \chemmacros_if_compatiblity:nnT {#1} {#2} {#3} }

\NewDocumentCommand \IfChemCompatibilityF {mm+m}
  { \chemmacros_if_compatiblity:nnF {#1} {#2} {#3} }

% --------------------------------------------------------------------------
% compatibility coding:
\cs_new_protected:Npn \ChemCompatibility #1#2 \EndChemCompatibility
  { \chemmacros_if_compatiblity:nnT {=} {#1} {#2} }
  
\cs_new_protected:Npn \ChemCompatibilityFrom #1#2 \EndChemCompatibility
  { \chemmacros_if_compatiblity:nnT {>=} {#1} {#2} }

\cs_new_protected:Npn \ChemCompatibilityTo #1#2 \EndChemCompatibility
  { \chemmacros_if_compatiblity:nnT {<=} {#1} {#2} }

\cs_new_protected:Npn \ChemCompatibilityBetween #1#2#3 \EndChemCompatibility
  {
    \bool_if:nT
      {
        \chemmacros_if_compatiblity_p:nn {>=} {#1} &&
        \chemmacros_if_compatiblity_p:nn {<=} {#2}
      }
      {#3}
  }

% --------------------------------------------------------------------------
% messages:
\msg_new:nnn {chemmacros} {too-low-compatibility}
  {
    Compatibility~ for~ versions~ below~ v4.7~ is~ not~ supported!~ You~
    requested~ version~ v #1.~ Loading~ v4.7~ instead.
  }

\msg_new:nnn {chemmacros} {too-high-compatibility}
  {
    You~ requested~ compatibility~ mode~ v #1~ while~ the~ current~ version~
    of~ chemmacros~ is~ v \c_chemmacros_version_number_tl .~ Falling~ back~
    to~ v \c_chemmacros_version_number_tl !
  }

\msg_new:nnn {chemmacros} {low-compatibility}
  {
    You~ requested~ compatibility~ mode~ v #1~ while~ the~ current~ version~
    of~ chemmacros~ is~ v \c_chemmacros_version_number_tl .~ Not~ all~ features~
    will~ be~ available!
  }

% --------------------------------------------------------------------------
% let's see that the max number is the newest (=current) version
\chemmacros_if_compatiblity:nnT {>} { \c_chemmacros_version_number_tl }
  {
    \fp_set:Nn \l__chemmacros_compatibility_version_fp
      { \c_chemmacros_version_number_tl }
  }

% --------------------------------------------------------------------------
% compatibility too low:
\chemmacros_if_compatiblity:nnT {<} {4.7}
  {
    \msg_warning:nnx {chemmacros} {too-low-compatibility}
      { \fp_to_tl:N \l__chemmacros_compatibility_version_fp }
  }

% not the newest version:
\chemmacros_if_compatiblity:nnT {<} { \c_chemmacros_version_number_tl }
  {
    \msg_warning:nnx {chemmacros} {low-compatibility}
      { \fp_to_tl:N \l__chemmacros_compatibility_version_fp }
  }
  
% --------------------------------------------------------------------------
\chemmacros_if_compatiblity:nnTF {<} {5.0}
  { \RequirePackage{chemmacros4} }
  { \RequirePackage{chemmacros5} }

% --------------------------------------------------------------------------
\tex_endinput:D

% --------------------------------------------------------------------------
Version history
2011/05/15 - version 1.0  - CTAN release
2011/06/22 - version 1.1  - "LaTeXified" whole package for safer usage
                          - less user work required (like loading package
                            after another)
                          - more particle macros
                          - latin phrases
                          - extra units
                          - acid/base commands
                          - \mech
                          - \NMR
                          - \mhName, \setmhName, \newreaction, phases
                          - \renewstate, \setstatesubscript
                          - improved orbitals
                          - simpler package options, option german, bpchem
                          - bug fixes
2011/10/28 - version 2.0  - rewritten in expl3
                          - customization via \chemsetup
                          - new commands \p, \fplus, \fminus, \fpch, \fmch,
                            \fscrp, \fsrcm, \fdelp, \fdelm, \orbital, \chemsetup
                          - various commands have a new syntax
                          - removed: \setmhName, \setredoxdist,
                            \setstatesubscript, \porb, \phorb, \pxorb, \pyorb,
                            \pzorb, \setorbheight, \solid, \liquid
                          - reaction environments work with hyperref and
                            varioref
2011/11/03 - version 2.0a - minor bug fixes
                          - new feature for \Nu
                          - new command \ba
2012/01/28 - version 3.0  - bundled with packages `formula' and `ghs'
                          - new commands \Ka, \Kb, \Kw
                          - commands can detect if font series is bold
                          - new package option "detect-bold"
                          - new package option "method" => choose between
                            `mhchem' and `formula' for internal uses.
                          - new package option "ghs" => load `ghs' or don't
                          - new package option "synchronize"
                          - new package option "strict"
                          - new command \iupac
                          - new command \listofreactions, reaction environments
                            with optional argument
                          - \cis, \trans, \tert without \xspace
2012/01/30 - version 3.0a - bugfix in formula.sty
                          - renamed formula => chemformula
                            and ghs => ghsystem to make the names unique
                            (following a request by Karl Berry for TeXlive)
2012/02/03 - version 3.0b - new command \DeclareChemParticle, updated
                            documentation
2012/02/05 - version 3.0c - renamed pictogram files (following a request by
                            Karl Berry for TeXlive)
                          - new package option "Nu"
2012/02/10 - version 3.0d - several bugfixes in chemformula
                          - bugfixes with \DeclareChemParticle
                          - new command \RenewChemParticle
                          - new option phases / pos
                          - new commands \DeclareChemPhase, \RenewChemPhase,
                            \phase
                          - changed default behaviour of phases
                          - removed optional argument from \sld and \lqd
                          - new arrow type <>
2012/02/19 - version 3.1  - new commands \DeclareChemIUPAC and \RenewChemIUPAC
                          - new option "option/iupac"
                          - deprecated option: "option/EZ"
                          - deprecated commands:
                            \newreaction => \DeclareChemReaction
                            \setnewstate => \DeclareChemState
                            \renewstate  => \RenewChemState
                            \Rcip        => \R
                            \Scip        => \S
                            \Dfi         => \D
                            \Lfi         => \L
                          - new arrow types -/>, </- and <o>
                          - new commands \DeclareChemArrow, \RenewChemArrow and
                            \ShowChemArrow
2012/02/26 - version 3.1a - "operator" p rewritten to follow IUPAC
                            recommendations
                          - new option "acid-base/p-style"
                          - deprecated option: "option/detect-bold"
2012/03/03 - version 3.1b - arrow types are stored in a sequence to automate the
                            search and replace in the right order 
                          - new arrow type ==                                   
                          - IUPAC compliance for stoichiometric factors
                          - new handling of super- and subscripts to correct
                            various flaws: clear distinction between isotope and
                            formula
                          - new option charge-vshift
                          - IUPAC compliance for \Delta and \ox
2012/03/14 - version 3.1c - compatibility with KOMA's global option
                            "version = <value>"
                          - bugfix in the list of reactions
                          - improved arrow labels
2012/03/20 - version 3.2  - new: option input via @{<options>}
                          - improved list of reactions: resetting the "reaction"
                            counter now doesn't cause errors any more
                          - \AddRxnDesc added which allows to add descriptions
                            to each reaction in the "reactions" environment
2012/05/07 - version 3.3  - new environment `experimental' that allows some
                            formatting for the for displaying of measurement
                            results
                          - more greek letters for the \iupac command
                          - \ch now bypasses \ref{}, \label{}, and \intertext{}
                          - small adjustments of the iupac commands \| and \-
                          - bug fix: option `upgreek' is now working and was
                            renamed to `greek'
                          - proper language support
2012/05/13 - version 3.3a - Italian translations of the H, EUH and P statements
                          - \hapto and \bridge
2012/05/18 - version 3.3b - compatibility with MiKTeX
2012/05/18 - version 3.3c - fix in the `ghsystem/language' option
2012/07/24 - version 3.3d - additional picture file type `pdf'
                          - default bond length set to 1.1667ex
                          - bug fix in the bonds
                          - added kerning to cip commands, new option
                            `iupac/cip-kern'
                          - bug fix: messages needed to be defined before the
                            options
2012/08/21 - version 3.3e - new option ox/align=center|right
                          - a new option to \NMR and to \J
2012/09/11 - version 3.4  - cleaned a little, minor bug fixes
                          - switched to internal scratch variables
                          - new command \bond, more bond types
                          - new commands \DeclareChemBond, \DeclareChemBondAlias,
                            \RenewChemBond and \ShowChemBond
                          - radical point thicker, new options `radical-style'
                            and `radical-radius'
2012/10/03 - version 3.4a - bug fix in coupling constant \J
2013/01/04 - version 3.4b - bug fix in the sub- and superscript handling
2013/01/28 - version 3.5  - disallow breaks at bonds
                          - allow breaks after arrows
                          - made some spaces in chemformulas stretch- and
                            shrinkable
                          - various internal code improvements
                          - changed defaults for horizontal spaces that have in
                            set in ex into corresponding values in em.
                          - improvements to the placement of sub- and superscripts
2013/02/19 - version 3.5a - bug fix: `ghsystem' recognizes language again
2013/02/26 - version 3.6  - support for use with the `breqn' package
                          - chemformula: math escaping also via \(\)
                          - chemformula internal: clearer escaping macros
                          - new options: `radical-vshift', `radical-hshift'
                            and `radical-space'
                          - bug fix: `radical-...' options are now correctly set
                          - stoichiometric factors: add leading 0 if missing
                          - new option: `stoich-paren-parse'
                          - internal changes: be way more rigid about protected
                            and expandable macros
                          - internal changes: clearer distinction between
                            private macros and accessable module macros
                          - internal changes: clearer distinction between
                            document commands and module level commands
                          - chemformula's !()() syntax now also works with babel's
                            French
2013/02/27 - version 3.6a - bug fix: escaped text and math stays escaped, i.e.
                            also arrow code like `<=>'
2013/04/19 - version 3.6b - chemformula: new key `arrow-min-length'
                          - bug fix: stoichiometric fractions correctly displayed
                          - changed appearance of \cip to use upright parentheses
2013/07/06 - version 4.0  - `chemformula' doesn't automatically load
                            `chemmacros' any more but can be used stand-alone
                          - option `bpchem' has been dropped
                          - improved detection of bold font series
                          - changed wrongly used \mbox in definition of \Ka,
                            \Kb and \Kw into \ensuremath
                          - adapt \mch and \pch to match `chemformula's
                            charges
                          - dropped option `method=mhchem'
                          - support for `kpfonts' and `newtxmath' upright
                            greek letters added, greek alphabet complete both
                            for uppercase and lowercase; this is handled by
                            the new package in the family: `chemgreek'
                          - \OX and \redox now work in `amsmath's environment
                            by ignoring the measuring phase
                          - language management with the help of the
                            `translations' package =>
                            recognize document language automatically and use
                            it if it a) is known to `chemmacros' and b) has
                            not been overwritten by the `language' option;
                            this also made minor changes to `ghsystem'
                            necessary; additionally this lead to changes in
                            the way phases are defined
                          - status of \Dfi and \Lfi changed from `deprecated'
                            to `dropped'
                          - new option `charges/partial-format'
                          - fixed wrongly written contents to the lor when
                            used together with `hyperref'
                          - new option `reaction/list-heading'
                          - option `charges/append' deprecated
2013/08/07 - version 4.0a - extra pair of braces in definition of
                            \standardstate
                          - added missing \exp_not:n to the definitions of
                            \chemmacros_declare_phase:Nn and kin
2013/08/24 - version 4.1  - changed `0' values in TikZ coordinates into `0pt'
                            see http://tex.stackexchange.com/q/128792/5049 and
                            http://tex.stackexchange.com/q/118467/5049 for
                            reference
2013/10/28 - version 4.2  - changed particles with electron pairs to use
                            \chlewis
                          - changed \Delta in thermodynamic state variables
                            into \ChemDelta for IUPAC compliance and defined
                            it as an operator
                          - change in the syntax of \DeclareChemState and
                            \RenewChemState and improved both internal
                            definition and user interface
2013/10/31 - version 4.2a - bug bix in \hapto and \bridge
2013/11/04 - version 4.2b - new IUPAC commands: \fac/\mer
2013/11/20 - version 4.2c - step bundle version due to changes in `chemgreek'
2013/12/15 - version 4.2d - small changes to the translating mechansim which
                            now seems to be more logical: `language=auto'
                            detects the current `babel' language and
                            `language=<lang>' overwrites to the chosen
                            language
                          - new options `acid-base/K-acid', `acid-base/K-base'
                            and `acid-base/K-water'
                          - adapt \ox to updates in `l3fp'
2014/01/09 - version 4.2e - step bundle version due to changes in `ghsystem'
2014/01/24 - version 4.3  - \NewChemIUPAC, \LetChemIUPAC
                          - \NewChemParticle
                          - \NewChemNMR
                          - \NewChemPhase
                          - \NewChemReaction, \RenewChemReaction
                          - \NewChemState
                          - added macro names with more meaningfule names to
                            each of the one-letter name commands
                          - changed behaviour of \DeclareChem to match
                            \DeclareRobustCommand, i.e., no check if command
                            is defined; added a \NewChem variant to each that
                            /does/ check; use \NewChem instead of \DeclareChem
                            for definitions
                          - new iupac command \dento
                          - new option choice `nmr/pos=super'
                          - bug fix in appearance of coupling nuclei
                          - new possibilities for formatting the output of the
                            NMR coupling constants output with \J:
                            `coupling-pos=side/sub', `coupling-nuclei-pre',
                            coupling-nuclei-post', `coupling-bonds-pre',
                            coupling-bonds-post', `coupling-symbol'
                          - internal changes to the greek letter mapping
                            selection mechanism
                          - deprecate package option `strict'
                          - deprecate package option `cmversion': also all
                            backwards compatibility for version 1 has been
                            dropped
                          - drop command \mhName
2014/01/29 - version 4.4  - bug fix in the display of the coupling constant
                          - bug fix in phase definitions (need to adapt to
                            changes in `translations'
                          - new option `nmr/atom-number-cs'
                          - new option `nmr/coupling-pos-cs'
2014/04/08 - version 4.5  - new option `acid-base/subscript'
                          - added Dutch translations
2014/06/30 - version 4.5a - adapt to deprecated expl3 functions
2014/08/08 - version 4.6  - from bundle to packages: packages `chemformula',
                            `ghsystem' and `chemgreek' no longer belong to the
                            bundle but now are packages of their own.
2015/02/08 - version 4.7  - fix \iupac so active letters like | still work
                            inside other macros (\section, ...)
                          - Change the default subscripts of the equilibrium
                            constants to match the usage in the IUPAC Green
                            Book
                          - allow \NewChemPhase and friends after \begin{document}
                          - new optional argument to phase commands
                          - new options `nmr/method' and `nmr/connector'
2015/09/11 - version 5.0  - the former chemmacros.sty is now chemmacros4.sty
                            and can be loaded through the `compatibility'
                            option
                          - chemmacros is now organized in separate modules
                            which either are preloaded or can be loaded by the
                            user with \usechemmodule
                          - various changes, see
                            http://www.mychemistry.eu/2015/06/chemmacros-development/
                            and the manual section 3.4. Upgrading from version < 5.0
                            for details
2015/09/23 - version 5.1  - add option `method' to `chemformula' module
                          - make module `scheme' compatible with `floatrow'
                          - add module hooks `before' and `after'
2015/10/14 - version 5.2  - warn if compatibility version requested is higher
                            than the current version number
                          - enable to specify a minimal compatibility version
                            for a module
                          - add info message to `all' module
                          - add values `newest' and `latest' to the
                            compatibility option
                          - check for mhchem and chemformula and choose the
                            formula method accordingly
                          - fixes in the module hook mechanism
                          - fix in \chemmacros_if_module_loaded:n
                          - new internal module `errorcheck'
2016/01/13 - version 5.3  - removed options `german' and `ngerman' (lang)
                          - remove deprecated pre-v5 macros (several modules)
                          - new option `atom-number-space' (spectroscopy)
                          - add \chemprime and ' shorthand (nomenclature)
                          - new option `space' (particles)
                          - TikZ decoration `wave' (tikz)
2016/01/23 - version 5.3a - compatibility with chemscheme package (scheme)
                          - IUPAC shorthands only defined within \iupac (nomenclature)
2016/02/10 - version 5.4  - \NewChemEqConstant and family, new option
                            `eq-constant' (acid-base)
                          - added \ignorespacesafterend to environments
                            (reactions)
                          - fixed erroneous definition of \NewChemMacroset
                            (base)
                          - new option `explicit-zero-sign' (redox)
2016/03/08 - version 5.5  - new module `polymers'
2016/05/02 - version 5.6  - generalization of the formula method concept, new
                            methods `chemist' and `chemfig' (chemformula)
                          - use `tocbasic' for the list of reactions if
                            available (reactions)
                          - fix reaction environments to obey \thereaction
                            (reactions)
                          - add cleveref and fancyref support (reactions)
                          - add cleveref and fancyref support (scheme)
2016/05/04 - version 5.6a - fix small but annoying bugs (base and chemformula)