summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/chemmacros/chemformula.sty')
-rw-r--r--Master/texmf-dist/tex/latex/chemmacros/chemformula.sty173
1 files changed, 119 insertions, 54 deletions
diff --git a/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty b/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty
index b29047b1e3d..d041025fe17 100644
--- a/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty
+++ b/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty
@@ -27,8 +27,8 @@
% --------------------------------------------------------------------------
\RequirePackage{ expl3 , xparse , l3keys2e , tikz , amsmath , xfrac , nicefrac , scrlfile }
\usetikzlibrary{arrows}
-\def\chemformula@version{4.0}
-\def\chemformula@date{2013/07/06}
+\def\chemformula@version{4.1}
+\def\chemformula@date{2013/08/24}
\ProvidesExplPackage
{chemformula}
@@ -167,7 +167,7 @@
% variants of kernel functions:
\cs_generate_variant:Nn \keys_set:nn { nV }
\cs_generate_variant:Nn \tl_if_blank:nF { V }
-\cs_generate_variant:Nn \tl_if_in:nnT { x }
+\cs_generate_variant:Nn \tl_if_in:nnT { x , nV }
\cs_generate_variant:Nn \prop_get:Nn { NV }
\cs_generate_variant:Nn \tl_set_rescan:Nnn { NnV }
@@ -248,6 +248,8 @@
\bool_new:N \l__chemformula_fss_shape_bool
\bool_new:N \l__chemformula_name_width_bool
\bool_new:N \l__chemformula_charge_full_shift_bool
+\bool_new:N \l__chemformula_tikzexternaldisable_bool
+\bool_set_true:N \l__chemformula_tikzexternaldisable_bool
% dimensions:
\dim_new:N \l__chemformula_arrow_length_dim
@@ -311,6 +313,12 @@
\tl_set:Nn \l__chemformula_arrow_label_style_tl { \footnotesize }
\tl_new:N \l__chemformula_arrow_tmp_tl
\tl_new:N \l__chemformula_arrow_type_tl
+\tl_new:N \l__chemformula_arrow_penalty_tl
+\tl_set:Nn \l__chemformula_arrow_penalty_tl { 0 }
+\tl_new:N \l__chemformula_plus_penalty_tl
+\tl_set:Nn \l__chemformula_plus_penalty_tl { 700 }
+\tl_new:N \l__chemformula_bond_penalty_tl
+\tl_set:Nn \l__chemformula_bond_penalty_tl { 10000 }
\tl_new:N \l__chemformula_name_tmp_tl
\tl_new:N \l__chemformula_chemformula_tmpa_tl
\tl_new:N \g__chemformula_options_tl
@@ -385,6 +393,15 @@
\chemformula_nobreak:
}
+\cs_new_protected:Npn \chemformula_skip_nobreak_penalty:Nn #1#2
+ {
+ \chemformula_nobreak:
+ \skip_horizontal:N #1
+ \tex_penalty:D #2 \scan_stop:
+ }
+% \binoppenalty=\maxdimen
+% \relpenalty=\maxdimen
+
\cs_new_protected:Npn \chemformula_dim_to_width:Nn #1#2
{
\hbox_set:Nn \l__chemformula_tmpa_box { #2 }
@@ -399,6 +416,22 @@
{ \use:c { if #1 } \prg_return_true: \else: \prg_return_false: \fi: }
% --------------------------------------------------------------------------
+% prevent externalisation of tikz parts of the formulae:
+\AtBeginDocument { \providecommand \tikzexternaldisable {} }
+
+\keys_define:nn { chemmacros / chemformula }
+ {
+ tikz-external-disable .bool_set:N =
+ \l__chemformula_tikzexternaldisable_bool
+ }
+
+\cs_new_protected:Npn \chemformula_tikzexternaldisable:
+ {
+ \bool_if:NT \l__chemformula_tikzexternaldisable_bool
+ { \tikzexternaldisable }
+ }
+
+% --------------------------------------------------------------------------
% circled charge signs:
\cs_new_protected:Npn \chemformula_fplus:
{ \ensuremath { \__chemformula_fplus: } }
@@ -645,9 +678,9 @@
{ \dim_set_eq:NN \l__chemformula_arrow_length_dim \l__chemformula_tmpa_dim }
{ \dim_set_eq:NN \l__chemformula_arrow_length_dim \l__chemformula_tmpb_dim }
\dim_add:Nn \l__chemformula_arrow_length_dim
- { \l__chemformula_arrow_offset_dim }
- \dim_add:Nn \l__chemformula_arrow_length_dim
- { \l__chemformula_arrow_offset_dim }
+ { 2\l__chemformula_arrow_offset_dim }
+% \dim_add:Nn \l__chemformula_arrow_length_dim
+% { \l__chemformula_arrow_offset_dim }
\dim_compare:nF
{ \l__chemformula_arrow_length_dim > \l__chemformula_arrow_minimum_length_dim }
{
@@ -657,15 +690,12 @@
}
\dim_set:Nn \l__chemformula_arrow_shortage_dim
{
- \l__chemformula_arrow_length_dim *
- \dim_ratio:nn { \l__chemformula_arrow_ratio_tl pt } { 1pt }
- }
- \dim_set:Nn \l__chemformula_arrow_shortage_dim
- { \l__chemformula_arrow_length_dim - \l__chemformula_arrow_shortage_dim }
- \dim_set:Nn \l__chemformula_arrow_shortage_dim
- {
- \l__chemformula_arrow_shortage_dim *
- \dim_ratio:nn { 1pt } { 2pt }
+ (
+ \l__chemformula_arrow_length_dim
+ -
+ \l__chemformula_arrow_length_dim *
+ \dim_ratio:nn { \l__chemformula_arrow_ratio_tl pt } { 1pt }
+ ) * 1/2
}
}
@@ -701,14 +731,17 @@
% this will be \arrow inside \ch
\DeclareDocumentCommand \charrow { mO{}O{} }
{
- \__chemformula_arrows_get:n { #1 }
- \chemformula_arrow_labels:nn { #2 } { #3 }
+ \group_begin:
+ \chemformula_tikzexternaldisable:
+ \__chemformula_arrows_get:n { #1 }
+ \chemformula_arrow_labels:nn { #2 } { #3 }
+ \group_end:
}
% draw the arrows
\cs_new:Npn \__chemformula_arrow_draw:n #1
{
- \chemformula_allow_break:
+ \chemformula_nobreak:
% prepare arrow code for drawing:
\tl_set_rescan:Nnn \l__chemformula_tmpc_tl
{ \char_set_catcode_letter:N \_ } { #1 }
@@ -723,18 +756,18 @@
\chemformula_draw:xn
{ \l__chemformula_arrow_style_tl }
{
- coordinate (chemformula_arrow_start) (0,0)
- ++ (\l__chemformula_compound_sep_dim,.3432em)
- ++ (0,\l__chemformula_arrow_yshift_dim)
+ coordinate (chemformula_arrow_start) (0pt,0pt)
+ ++ ( \l__chemformula_compound_sep_dim , .3432em)
+ ++ (0pt,\l__chemformula_arrow_yshift_dim)
coordinate (cf_arrow_start)
- ++ ( .5 * \dim_use:N \l__chemformula_arrow_length_dim , 0)
+ ++ ( .5 * \dim_use:N \l__chemformula_arrow_length_dim , 0pt)
coordinate (cf_arrow_mid)
- ++ ( .5 * \dim_use:N \l__chemformula_arrow_length_dim , 0)
+ ++ ( .5 * \dim_use:N \l__chemformula_arrow_length_dim , 0pt)
coordinate (cf_arrow_end)
- ++ (\l__chemformula_compound_sep_dim,0)
- (cf_arrow_start) ++ (\l__chemformula_arrow_shortage_dim,0)
+ ++ ( \l__chemformula_compound_sep_dim , 0pt )
+ (cf_arrow_start) ++ (\l__chemformula_arrow_shortage_dim , 0pt)
coordinate (cf_arrow_mid_start)
- (cf_arrow_end) ++ (-\l__chemformula_arrow_shortage_dim , 0)
+ (cf_arrow_end) ++ (-\l__chemformula_arrow_shortage_dim , 0pt)
coordinate (cf_arrow_mid_end)
}
% the arrow labels:
@@ -748,7 +781,9 @@
;
\tl_use:N \l__chemformula_tmpc_tl
}
- \chemformula_allow_break:
+ \chemformula_skip_nobreak_penalty:Nn
+ \c_zero_skip
+ { \l__chemformula_arrow_penalty_tl }
}
\cs_generate_variant:Nn \__chemformula_arrow_draw:n { V }
@@ -844,7 +879,8 @@
label-offset .dim_set:N = \l__chemformula_arrow_label_offset_dim ,
compound-sep .dim_set:N = \l__chemformula_compound_sep_dim ,
arrow-style .tl_set:N = \l__chemformula_arrow_style_tl ,
- label-style .tl_set:N = \l__chemformula_arrow_label_style_tl
+ label-style .tl_set:N = \l__chemformula_arrow_label_style_tl ,
+ arrow-penalty .tl_set:N = \l__chemformula_arrow_penalty_tl
}
% --------------------------------------------------------------------------
@@ -1000,7 +1036,7 @@
\prop_map_inline:Nn \l__chemformula_arrows_code_prop
{
\tl_set_rescan:Nnn \l__chemformula_tmpa_tl {} { ##1 }
- \tl_if_in:noT { #1 } { \l__chemformula_tmpa_tl }
+ \tl_if_in:nVT { #1 } \l__chemformula_tmpa_tl
{ \bool_set_true:N \l__chemformula_is_arrow_bool }
}
}
@@ -1143,25 +1179,30 @@
\cs_new_protected:Npn \chemformula_bond:n #1
{
\chemformula_skip_nobreak:N \l__chemformula_bond_space_dim
+ \group_begin:
+ \chemformula_tikzexternaldisable:
\chemformula_tikz:nn
{
- inner~sep = 0 ,
- outer~sep = 0 ,
+ inner~sep = 0pt ,
+ outer~sep = 0pt ,
text~height = 1em ,
baseline = (chemformula-bond-ground.base)
}
{
\draw node[draw=none,minimum~height=1em,minimum~width=0]
- (chemformula-bond-ground) at (0,0) {};
- \draw (chemformula-bond-ground) ++ (0,-.1716em)
+ (chemformula-bond-ground) at (0pt,0pt) {};
+ \draw (chemformula-bond-ground) ++ (0pt,-.1716em)
coordinate (chemformula-bond-start) ;
- \draw (chemformula-bond-start) ++(\l__chemformula_bond_dim ,0)
+ \draw (chemformula-bond-start) ++(\l__chemformula_bond_dim ,0pt)
coordinate (chemformula-bond-end) ;
\tl_if_blank:nTF { #1 }
{ \__chemformula_bond_draw:n { single } }
{ \__chemformula_bond_draw:n { #1 } }
}
- \chemformula_skip_nobreak:N \l__chemformula_bond_space_dim
+ \group_end:
+ \chemformula_skip_nobreak_penalty:Nn
+ \l__chemformula_bond_space_dim
+ { \l__chemformula_bond_penalty_tl }
}
\cs_new_protected:Npn \__chemformula_bond_draw:n #1
@@ -1222,10 +1263,10 @@
\DeclareChemBond{double}
{
- \draw (chemformula-bond-start) ++ (0,.0858em) coordinate (double-start-up) ;
- \draw (chemformula-bond-end) ++ (0,.0858em) coordinate (double-end-up) ;
- \draw (chemformula-bond-start) ++ (0,-.0858em) coordinate (double-start-down) ;
- \draw (chemformula-bond-end) ++ (0,-.0858em) coordinate (double-end-down) ;
+ \draw (chemformula-bond-start) ++ (0pt,.0858em) coordinate (double-start-up) ;
+ \draw (chemformula-bond-end) ++ (0pt,.0858em) coordinate (double-end-up) ;
+ \draw (chemformula-bond-start) ++ (0pt,-.0858em) coordinate (double-start-down) ;
+ \draw (chemformula-bond-end) ++ (0pt,-.0858em) coordinate (double-end-down) ;
\draw[chembond]
(double-start-down) -- (double-end-down)
(double-start-up) -- (double-end-up) ;
@@ -1234,10 +1275,10 @@
\DeclareChemBond{semidouble}
{
- \draw (chemformula-bond-start) ++ (0,.0858em) coordinate (double-start-up) ;
- \draw (chemformula-bond-end) ++ (0,.0858em) coordinate (double-end-up) ;
- \draw (chemformula-bond-start) ++ (0,-.0858em) coordinate (double-start-down) ;
- \draw (chemformula-bond-end) ++ (0,-.0858em) coordinate (double-end-down) ;
+ \draw (chemformula-bond-start) ++ (0pt,.0858em) coordinate (double-start-up) ;
+ \draw (chemformula-bond-end) ++ (0pt,.0858em) coordinate (double-end-up) ;
+ \draw (chemformula-bond-start) ++ (0pt,-.0858em) coordinate (double-start-down) ;
+ \draw (chemformula-bond-end) ++ (0pt,-.0858em) coordinate (double-end-down) ;
\draw[chembond] (double-start-down) -- (double-end-down) ;
\draw[chembond,densely~dotted] (double-start-up) -- (double-end-up) ;
}
@@ -1247,10 +1288,10 @@
\DeclareChemBond{triple}
{
- \draw (chemformula-bond-start) ++ (0,.1287em) coordinate (triple-start-up) ;
- \draw (chemformula-bond-end) ++ (0,.1287em) coordinate (triple-end-up) ;
- \draw (chemformula-bond-start) ++ (0,-.1287em) coordinate (triple-start-down) ;
- \draw (chemformula-bond-end) ++ (0,-.1287em) coordinate (triple-end-down) ;
+ \draw (chemformula-bond-start) ++ (0pt,.1287em) coordinate (triple-start-up) ;
+ \draw (chemformula-bond-end) ++ (0pt,.1287em) coordinate (triple-end-up) ;
+ \draw (chemformula-bond-start) ++ (0pt,-.1287em) coordinate (triple-start-down) ;
+ \draw (chemformula-bond-end) ++ (0pt,-.1287em) coordinate (triple-end-down) ;
\draw[chembond]
(triple-start-down) -- (triple-end-down)
(chemformula-bond-start) -- (chemformula-bond-end)
@@ -1260,10 +1301,10 @@
\DeclareChemBond{semitriple}
{
- \draw (chemformula-bond-start) ++ (0,.1287em) coordinate (triple-start-up) ;
- \draw (chemformula-bond-end) ++ (0,.1287em) coordinate (triple-end-up) ;
- \draw (chemformula-bond-start) ++ (0,-.1287em) coordinate (triple-start-down) ;
- \draw (chemformula-bond-end) ++ (0,-.1287em) coordinate (triple-end-down) ;
+ \draw (chemformula-bond-start) ++ (0pt,.1287em) coordinate (triple-start-up) ;
+ \draw (chemformula-bond-end) ++ (0pt,.1287em) coordinate (triple-end-up) ;
+ \draw (chemformula-bond-start) ++ (0pt,-.1287em) coordinate (triple-start-down) ;
+ \draw (chemformula-bond-end) ++ (0pt,-.1287em) coordinate (triple-end-down) ;
\draw[chembond]
(triple-start-down) -- (triple-end-down)
(chemformula-bond-start) -- (chemformula-bond-end) ;
@@ -1649,6 +1690,7 @@
\tl_if_blank:VF \l__chemformula_stoich_tl
{
\tl_put_left:Nn \l__chemformula_stoich_tl { \chemformula_font_inner: }
+ % TODO: is \ExplSyntaxOn needed here?
\tl_set_rescan:Nno \l__chemformula_stoich_tl
{ \ExplSyntaxOn }
{ \l__chemformula_stoich_tl }
@@ -1733,6 +1775,8 @@
\tl_put_right:Nn \l__chemformula_input_tl { ) }
}
+\cs_new_eq:NN \chemformula_math_frac:nn \frac
+
\cs_new:Npn \__chemformula_frac:nn #1#2
{
\bool_if:NT \l__chemformula_xfrac_bool
@@ -1740,7 +1784,7 @@
\bool_if:NT \l__chemformula_nicefrac_bool
{ \nicefrac{#1}{#2} }
\bool_if:NT \l__chemformula_mathfrac_bool
- { \( \frac{ \text { #1 } } { \text { #2 } } \) }
+ { \( \chemformula_math_frac:nn { \text { #1 } } { \text { #2 } } \) }
}
\cs_new:Npn \__chemformula_misc_frac:nnn #1#2#3
@@ -1750,7 +1794,7 @@
\bool_if:NT \l__chemformula_nicefrac_bool
{ #1\nicefrac{#2}{#3} }
\bool_if:NT \l__chemformula_mathfrac_bool
- { #1 \( \frac{ \text { #2 } } { \text { #3 } } \) }
+ { #1 \( \chemformula_math_frac:nn { \text { #2 } } { \text { #3 } } \) }
}
% --------------------------------------------------------------------------
@@ -1955,7 +1999,9 @@
{
\chemformula_skip_nobreak:N \l__chemformula_plus_space_skip
+
- \skip_horizontal:N \l__chemformula_plus_space_skip
+ \chemformula_skip_nobreak_penalty:Nn
+ \l__chemformula_plus_space_skip
+ { \l__chemformula_plus_penalty_tl }
}
}
\bool_set_false:N \l__chemformula_is_plus_bool
@@ -2211,10 +2257,13 @@
\bool_set_false:N \l__chemformula_xfrac_bool
\bool_set_true:N \l__chemformula_nicefrac_bool
\bool_set_false:N \l__chemformula_mathfrac_bool ,
+ frac-math-cmd .code:n =
+ { \cs_set_eq:NN \chemformula_math_frac:nn #1 } ,
stoich-paren-parse .bool_set:N = \l__chemformula_stoich_parse_iupac_bool ,
stoich-space .skip_set:N = \l__chemformula_stoich_space_skip ,
adduct-space .dim_set:N = \l__chemformula_adduct_space_dim ,
plus-space .skip_set:N = \l__chemformula_plus_space_skip ,
+ plus-penalty .tl_set:N = \l__chemformula_plus_penalty_tl ,
math-space .skip_set:N = \l__chemformula_math_space_skip ,
name-format .tl_set:N = \l__chemformula_name_format_tl ,
name-width .code:n =
@@ -2229,6 +2278,7 @@
bond-length .dim_set:N = \l__chemformula_bond_dim ,
bond-offset .dim_set:N = \l__chemformula_bond_space_dim ,
bond-style .tl_set:N = \l__chemformula_bond_style_tl ,
+ bond-penalty .tl_set:N = \l__chemformula_bond_penalty_tl ,
font-family .code:n =
\bool_set_true:N \l__chemformula_fss_bool
\bool_set_false:N \l__chemformula_fontspec_bool
@@ -2371,8 +2421,23 @@ VERSION HISTORY
- don't allow a line break between a stoichiometric
factor and a compound
- changed formal charges to match ``plain'' charges
+2013/07/26 - version 4.0a - added options `arrow-penalty' (0), `plus-penalty'
+ (700) and `bond-penalty' (10000) that determine if
+ there may be a break after an arrow, a bond or the
+ plus
+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
+ - new option `tikz-external-disable'
+ - new option `frac-math-cmd'
+
% --------------------------------------------------------------------------
% TODO
+- add \tikzexternaldisable and an option to disable it to \ch, \chcpd,
+ \charrow, and \bond
- Addukte: Zahlen nach * und . automatisch erkennen?
- optionale Argumente von \\ nach außen weiterreichen?
+- zu `frac-style' die Möglichkeit einbauen, statt \frac, \dfrac oder \tfrac zu
+ verwenden.