diff options
author | Karl Berry <karl@freefriends.org> | 2015-06-30 21:26:42 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2015-06-30 21:26:42 +0000 |
commit | e181b33df663a8c3af7b2432b5c10d4ae9b95359 (patch) | |
tree | 438fa6133c5bb633b7fcc77e89ca080572e03d24 | |
parent | 3de37f70674efe52ad1d2eb884f0c8af271dddd5 (diff) |
chemformula (30jun15)
git-svn-id: svn://tug.org/texlive/trunk@37722 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r-- | Master/texmf-dist/doc/latex/chemformula/README | 4 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/chemformula/chemformula_en.pdf | bin | 947255 -> 943624 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/chemformula/chemformula_en.tex | 256 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/chemformula/chemformula.sty | 407 |
4 files changed, 397 insertions, 270 deletions
diff --git a/Master/texmf-dist/doc/latex/chemformula/README b/Master/texmf-dist/doc/latex/chemformula/README index 074e5f444b2..c3483146f9e 100644 --- a/Master/texmf-dist/doc/latex/chemformula/README +++ b/Master/texmf-dist/doc/latex/chemformula/README @@ -1,11 +1,11 @@ -------------------------------------------------------------------------- -the CHEMFORMULA package v4.10a 2015/04/03 +the CHEMFORMULA package v4.11 2015/06/30 typeset chemical compounds and reactions -------------------------------------------------------------------------- Clemens Niederberger -Web: https://github.com/cgnieder/chemformula/ +Web: http://www.mychemistry.eu/forums/forum/chemformula/ E-Mail: contact@mychemistry.eu -------------------------------------------------------------------------- Copyright 2011-2015 Clemens Niederberger diff --git a/Master/texmf-dist/doc/latex/chemformula/chemformula_en.pdf b/Master/texmf-dist/doc/latex/chemformula/chemformula_en.pdf Binary files differindex 5dc2615b2e7..77e82cb1263 100644 --- a/Master/texmf-dist/doc/latex/chemformula/chemformula_en.pdf +++ b/Master/texmf-dist/doc/latex/chemformula/chemformula_en.pdf diff --git a/Master/texmf-dist/doc/latex/chemformula/chemformula_en.tex b/Master/texmf-dist/doc/latex/chemformula/chemformula_en.tex index a269504f99c..29c1f60f701 100644 --- a/Master/texmf-dist/doc/latex/chemformula/chemformula_en.tex +++ b/Master/texmf-dist/doc/latex/chemformula/chemformula_en.tex @@ -1,6 +1,6 @@ -% arara: pdflatex -% !arara: biber % !arara: pdflatex +% !arara: biber +% arara: pdflatex % arara: pdflatex % -------------------------------------------------------------------------- % the CHEMFORMULA package @@ -35,7 +35,7 @@ \usepackage[greek=newtx]{chemmacros} \setcnltx{ package = {chemformula}, - url = https://github.com/cgnieder/chemformula/ , + url = http://www.mychemistry.eu/forums/forum/chemformula/ , authors = Clemens Niederberger , email = contact@mychemistry.eu , abstract = {% @@ -47,27 +47,29 @@ bond, ce, ch, charrow, chcpd, chemformula@bondlength, chemsetup, chlewis, chname, - DeclareChemArrow, DeclareChemBond, DeclareChemBondAlias, - DeclareChemCompoundProperty, + DeclareChemAdditionSymbol, DeclareChemArrow, DeclareChemBond, + DeclareChemBondAlias, DeclareChemCompoundProperty, DeclareChemSymbol, mch, - NewChemArrow, NewChemBond, NewChemBondAlias, NewChemCompoundProperty, + NewChemAdditionSymbol, NewChemArrow, NewChemBond, NewChemBondAlias, + NewChemCompoundProperty, NewChemSymbol, ox, OX, pch, - redox, RemoveChemCompoundProperty, RenewChemArrow, RenewChemBond, - RenewChemCompoundProperty, + redox, RemoveChemCompoundProperty, RenewChemAdditionSymbol, + RenewChemArrow, RenewChemBond, RenewChemCompoundProperty, + RenewChemSymbol, setchemformula, ShowChemArrow, ShowChemBond } , add-silent-cmds = { addplot, chemfig, DeclareInstance, draw, - sample, setatomsep, + sample, setatomsep, sfrac, usetikzlibrary } } \usepackage{chemfig,booktabs,cancel,varioref} -\usepackage[version=3]{mhchem} +\usepackage[version=4]{mhchem} \expandafter\def\csname libertine@figurestyle\endcsname{LF} \usepackage[libertine]{newtxmath} @@ -206,85 +208,85 @@ a highly customizable alternative led to \chemformula{} after all. compounds, stoichiometric factors and arrows are input. In the same time \chemformula{} offers \emph{many} possibilities to customize the output. -\section{News} -\subsection{Version 4.0} -Since version 4.0\sinceversion{4.0}, the \chemformula{} package can be used -independently from \chemmacros. This means that if you say -\begin{sourcecode} - \usepackage{chemformula} -\end{sourcecode} -then \chemmacros\ will not be loaded. The \chemmacros\ package, however, -\emph{will} load \chemformula. - -\subsection{Version 4.2} -\begin{itemize} - \item New option \option{arrow-style}. - \item New command \cs{chlewis} that allows to add Lewis electrons to an - atom, see section~\ref{sec:lewis-formulae}. -\end{itemize} - -\subsection{Version 4.3} -\begin{itemize} - \item New option \option{stoich-print}. - \item New command \cs{chstoich}. - \item The commands \cs*{DeclareChem\meta{...}} now don't give an error any - more if the command already exists. This is more consistent with \LaTeX's - \cs*{DeclareRobustCommand}. For all those commands a version - \cs*{NewChem\meta{...}} is introduced that \emph{does} give an error if - the new command is already defined. -\end{itemize} - -\subsection{Version 4.4} -\begin{itemize} - \item A single dash \code{-} in \cs{ch} is now treated as a minus sign. - This is consistent with the behaviour of a \code{+}. -\end{itemize} - -\subsection{Version 4.5} -\begin{itemize} - \item New arrow types \arrowtype{>=<}, \arrowtype{>=<<}, \arrowtype{>>=<} - and \arrowtype{<==>}. - \item Internal changes to \cs{ch} allow usage of optional arguments of - \cs*{\textbackslash} and \cs*{label} in \chemmacros' \env*{reactions} - environment. -\end{itemize} - -\subsection{Version 4.6} -\begin{itemize} - \item New options \option{circled} and \option{circletype}. this allows to - set the behaviour as described on \chemmacros' manual for a specific usage - of \cs{ch}. -\end{itemize} - -\subsection{Version 4.7} -\begin{itemize} - \item Dependency change: \chemformula{} now requires the \TikZ{} library - \code{arrows.meta} instead of the library \code{arrows}. This requires - \TikZ{} version~3.0.0. -\end{itemize} - -\subsection{Version 4.8} -\begin{itemize} - \item The \chemformula{} package now is no longer part of the \chemmacros{} - bundle but is dirtributed as a package of it's own. -\end{itemize} - -\subsection{Version 4.9} -\begin{itemize} - \item New options \option{minus-space} and \option{minus-penalty} equivalent - to the existing \option{plus-space} and \option{plus-penalty} - \item New options \option{plus-output-symbol} and - \option{minus-output-symbol} for customizing the plus and minus signs in - the output. -\end{itemize} - -\subsection{Version 4.10} -\begin{itemize} - \item new macros \cs{NewChemCompoundProperty}, - \cs{RenewChemCompoundProperty}, \\ - \cs{DeclareChemCompoundProperty} and \cs{RemoveChemCompoundProperty}. See - section~\ref{sec:extend-comp-prop} for a description. -\end{itemize} +% \section{News} +% \subsection{Version 4.0} +% Since version 4.0\sinceversion{4.0}, the \chemformula{} package can be used +% independently from \chemmacros. This means that if you say +% \begin{sourcecode} +% \usepackage{chemformula} +% \end{sourcecode} +% then \chemmacros\ will not be loaded. The \chemmacros\ package, however, +% \emph{will} load \chemformula. + +% \subsection{Version 4.2} +% \begin{itemize} +% \item New option \option{arrow-style}. +% \item New command \cs{chlewis} that allows to add Lewis electrons to an +% atom, see section~\ref{sec:lewis-formulae}. +% \end{itemize} + +% \subsection{Version 4.3} +% \begin{itemize} +% \item New option \option{stoich-print}. +% \item New command \cs{chstoich}. +% \item The commands \cs*{DeclareChem\meta{...}} now don't give an error any +% more if the command already exists. This is more consistent with \LaTeX's +% \cs*{DeclareRobustCommand}. For all those commands a version +% \cs*{NewChem\meta{...}} is introduced that \emph{does} give an error if +% the new command is already defined. +% \end{itemize} + +% \subsection{Version 4.4} +% \begin{itemize} +% \item A single dash \code{-} in \cs{ch} is now treated as a minus sign. +% This is consistent with the behaviour of a \code{+}. +% \end{itemize} + +% \subsection{Version 4.5} +% \begin{itemize} +% \item New arrow types \arrowtype{>=<}, \arrowtype{>=<<}, \arrowtype{>>=<} +% and \arrowtype{<==>}. +% \item Internal changes to \cs{ch} allow usage of optional arguments of +% \cs*{\textbackslash} and \cs*{label} in \chemmacros' \env*{reactions} +% environment. +% \end{itemize} + +% \subsection{Version 4.6} +% \begin{itemize} +% \item New options \option{circled} and \option{circletype}. this allows to +% set the behaviour as described on \chemmacros' manual for a specific usage +% of \cs{ch}. +% \end{itemize} + +% \subsection{Version 4.7} +% \begin{itemize} +% \item Dependency change: \chemformula{} now requires the \TikZ{} library +% \code{arrows.meta} instead of the library \code{arrows}. This requires +% \TikZ{} version~3.0.0. +% \end{itemize} + +% \subsection{Version 4.8} +% \begin{itemize} +% \item The \chemformula{} package now is no longer part of the \chemmacros{} +% bundle but is dirtributed as a package of it's own. +% \end{itemize} + +% \subsection{Version 4.9} +% \begin{itemize} +% \item New options \option{minus-space} and \option{minus-penalty} equivalent +% to the existing \option{plus-space} and \option{plus-penalty} +% \item New options \option{plus-output-symbol} and +% \option{minus-output-symbol} for customizing the plus and minus signs in +% the output. +% \end{itemize} + +% \subsection{Version 4.10} +% \begin{itemize} +% \item new macros \cs{NewChemCompoundProperty}, +% \cs{RenewChemCompoundProperty}, \\ +% \cs{DeclareChemCompoundProperty} and \cs{RemoveChemCompoundProperty}. See +% section~\ref{sec:extend-comp-prop} for a description. +% \end{itemize} \section{Licence and Requirements} \license @@ -454,12 +456,12 @@ There are a few possibilities to customize the output. \ch[decimal-marker={,}]{3.5} \ch[decimal-marker={$\cdot$}]{3,5} \end{example} -The option \keyis{frac-style}{xfrac} uses the \verbcode+\sfrac+ command of the +The option \keyis{frac-style}{xfrac} uses the \cs*{sfrac} command of the \pkg{xfrac} package. The output strongly depends on the font you use. \begin{example} \ch[frac-style=xfrac]{3/2} \ch[frac-style=xfrac]{1_1/2} \end{example} -\chemformula{} defines the instance \verbcode=formula-text-frac= which you can +\chemformula{} defines the instance \code{chemformula-text-frac} which you can redefine to your needs. See the \pkg{xfrac} documentation for further information. The default definition is this: \begin{sourcecode} @@ -483,8 +485,8 @@ This document uses the font Linux Libertine~O and the following definition: } \end{sourcecode} -The option \keyis{frac-style}{nicefrac} uses the \verbcode+\nicefrac+ command -of the \pkg{nicefrac} package. +The option \keyis{frac-style}{nicefrac} uses the \cs*{nicefrac} command of the +\pkg{nicefrac} package. \begin{example} \ch[frac-style=nicefrac]{3/2} \ch[frac-style=nicefrac]{1_1/2} \end{example} @@ -927,8 +929,10 @@ to allow line breaks after slashes in compounds. There are some \enquote{special type} input groups. \subsection{Single Token Groups} -The first kind are groups which consist of only one token, namely of the -following ones: +The first kind are groups which consist of only one token. They are again +divided into two groups, \enquote{addition symbols} and \enquote{symbols}. + +\subsubsection{Addition Symbols} \begin{commands} \command{ch}[\Marg{ + } \ch{ + }] Creates the plus sign between compounds with space around it:\\ @@ -937,37 +941,77 @@ following ones: \sinceversion{4.3a}Creates the minus sign between compounds with space around it:\\ \cs{ch}\Marg{M - H} \ch{M - H} - \command{ch}[\Marg{ v } \ch{ v }] - Sign for precipitate: \cs{ch}\Marg{BaSO4 v} \ch{BaSO4 v} - \command{ch}[\Marg{ \textasciicircum\ } \ch{ ^ }] - Sign for escaping gas\footnotemark: \cs{ch}\Marg{H2 \textasciicircum} - \ch{H2 ^} \end{commands} -\footnotetext{Is this the correct English term? Please correct me if it isn't.} +Addition symbols are surrounded with space which can be customized according +to options explained in a bit. There is also some penalty prohibiting a line +break after them which also can be customized with an option. + +You can define/redefine your own addition symbols: +\begin{commands} + \command{NewChemAdditionSymbol}[\marg{name}\marg{input}\marg{output}] + Defines\sinceversion{4.11} the addition symbol \meta{name} with input + symbol \meta{input} and output \meta{output}. + \command{RenewChemAdditionSymbol}[\marg{name}\marg{input}\marg{output}] + Redefines\sinceversion{4.11} the addition symbol \meta{name} with input + symbol \meta{input} and output \meta{output}. + \command{DeclareChemAdditionSymbol}[\marg{name}\marg{input}\marg{output}] + (Re-)Defines\sinceversion{4.11} the addition symbol \meta{name} with input + symbol \meta{input} and output \meta{output} without checking if the + symbol exists or not. +\end{commands} The space left and right of the plus and the minus sign and the signs themselves can be set with the following options: \begin{options} \keyval{plus-space}{skip}\Default{.3em plus .1em minus .1em} A rubber length. - \keyval{minus-space}{skip}\Default{.3em plus .1em minus .1em} - \sinceversion{4.9}A rubber length. \keyval{plus-penalty}{num}\Default{700} \sinceversion{4.0a}The penalty that is inserted after the plus sign for (dis-)allowing line breaks. + \keyval{plus-output-symbol}{code}\Default{+} + \sinceversion{4.9}The \meta{code} that is used for the plus sign. + \keyval{minus-space}{skip}\Default{.3em plus .1em minus .1em} + \sinceversion{4.9}A rubber length. \keyval{minus-penalty}{num}\Default{700} \sinceversion{4.9}The penalty that is inserted after the minus sign for (dis-)allowing line breaks. - \keyval{plus-output-symbol}{code}\Default{+} - \sinceversion{4.9}The \meta{code} that is used for the plus sign. \keyval{minus-output-symbol}{code}\Default{\$-\$} \sinceversion{4.9}The \meta{code} that is used for the minus sign. \end{options} +The corresponding three options are defined when \cs{NewChemAdditionSymbol} +or one of the variants is used, \code{\meta{name}-space} and +\code{\meta{name}-penalty} both with the same defaults as above, and +\code{\meta{name}-output-symbol}. + \begin{example}[side-by-side] \ch{A + B}\par \ch[plus-space=4pt]{A + B} \end{example} +\subsubsection{Symbols} +\begin{commands} + \command{ch}[\Marg{ v } \ch{ v }] + Sign for precipitate: \cs{ch}\Marg{BaSO4 v} \ch{BaSO4 v} + \command{ch}[\Marg{ \textasciicircum\ } \ch{ ^ }] + Sign for escaping gas\footnotemark: \cs{ch}\Marg{H2 \textasciicircum} + \ch{H2 ^} +\end{commands} +\footnotetext{Is this the correct English term? Please correct me if it isn't.} + +You can define/redefine your own symbols: +\begin{commands} + \command{NewChemSymbol}[\marg{input}\marg{output}] + Defines\sinceversion{4.11} the addition symbol with input \meta{input} and + output \meta{output}. + \command{RenewChemSymbol}[\marg{input}\marg{output}] + Redefines\sinceversion{4.11} the addition symbol with input \meta{input} + and output \meta{output}. + \command{DeclareChemSymbol}[\marg{input}\marg{output}] + (Re-)Defines\sinceversion{4.11} the addition symbol with input + \meta{input} and output \meta{output} without checking if the symbol + exists or not. +\end{commands} + \subsection{Option Input} Sometimes you might want to apply an option only to a part of a, say, reaction. Of course you have the possibility to use \cs{ch} several times. @@ -1005,7 +1049,7 @@ be input with \verbcode+~+. \command{ch}[\Marg{ \textquotesingle\meta{escaped text}\textquotesingle{} }] The second of two possibilities to \emph{escape} \chemformula's parsing. \end{commands} -\begin{example} +\begin{example}[add-sourcecode-options={literate=}] \ch{"\ox{2,Ca}" O} \par \ch{"\ldots\," Na + "\ldots\," Cl2 -> "\ldots\," NaCl} \par \ch{'A~->~B'} diff --git a/Master/texmf-dist/tex/latex/chemformula/chemformula.sty b/Master/texmf-dist/tex/latex/chemformula/chemformula.sty index e80de909eb9..baaccb57fc8 100644 --- a/Master/texmf-dist/tex/latex/chemformula/chemformula.sty +++ b/Master/texmf-dist/tex/latex/chemformula/chemformula.sty @@ -28,8 +28,8 @@ % -------------------------------------------------------------------------- \RequirePackage{ expl3 , xparse , l3keys2e , tikz , amsmath , xfrac , nicefrac , scrlfile } \usetikzlibrary{arrows.meta} -\def\chemformula@version{4.10a} -\def\chemformula@date{2015/04/03} +\def\chemformula@version{4.11} +\def\chemformula@date{2015/06/30} \ProvidesExplPackage {chemformula} @@ -38,23 +38,8 @@ {typeset chemical compounds and reactions} % -------------------------------------------------------------------------- -% check expl3 version: -\@ifpackagelater { expl3 } { 2012/11/21 } - { } - { - \PackageError { chemformula } { Support~package~expl3~too~old } - { - You~need~to~update~your~installation~of~the~bundles~'l3kernel'~and~ - 'l3packages'.\MessageBreak - Loading~chemformula~will~abort! - } - \tex_endinput:D - } - -% -------------------------------------------------------------------------- % warning and error messages: -\msg_new:nnnn { chemformula } { missing-argument } - { Wrong~name~input~ \msg_line_context: . } +\msg_new:nnn {chemformula} {missing-argument} { Maybe~you've~forgotten~to~add~the~second~argument~to~name~syntax?~ "!(<name>)(<chemformula>)".\\ @@ -63,55 +48,61 @@ Either~way~-~I~don't~know~what~to~do~ \msg_line_context: . } -\msg_new:nnnn { chemformula } { new-arrow } - { The~arrow~type~ \tl_to_str:n {#1} \c_space_tl is~already~defined. } +\msg_new:nnn {chemformula} {new-arrow} { You've~tried~to~define~the~arrow~type~\tl_to_str:n {#1} \c_space_tl with ~\token_to_str:N \NewChemArrow \c_space_tl but~it~already~exists. ~Choose~another~name. } -\msg_new:nnnn { chemformula } { renew-arrow } - { The~arrow~type~ \tl_to_str:n {#1} \c_space_tl is~not~defined. } +\msg_new:nnn {chemformula} {renew-arrow} { You've~tried~to~renew~the~arrow~type~\tl_to_str:n {#1} ~but~it~doesn't~ exist. } -\msg_new:nnnn { chemformula } { new-bond } - { The~bond~type~ \tl_to_str:n {#1} \c_space_tl is~already~defined. } +\msg_new:nnn {chemformula} {new-bond} { You've~tried~to~define~the~bond~type~\tl_to_str:n {#1} \c_space_tl with ~\token_to_str:N \NewChemBond \c_space_tl but~it~already~exists. ~Choose~another~name. } -\msg_new:nnnn { chemformula } { renew-bond } - { The~bond~type~ \tl_to_str:n {#1} \c_space_tl is~not~defined. } +\msg_new:nnn {chemformula} {renew-bond} { You've~tried~to~renew~the~bond~type~\tl_to_str:n {#1} ~but~it~doesn't~ exist. } -\msg_new:nnnn { chemformula } { stand-alone } +\msg_new:nnn {chemformula} {new-addition-symbol} { - You're~using~`chemformula'~as~a~stand-alone~package~or~have~loaded~it~ - before~you've~loaded~`chemmacros',~too.~Some~features~might~not~be~ - provided!~Espacially~you~cannot~use~\token_to_str:N \chemsetup \c_space_tl - to~setup~your~formulae. + You've~ tried~ to~ define~ the~ addition~ symbol~ `#1'~ (input~ symbol:~ + `#2')~ with~ \token_to_str:N \NewChemAdditionSymbol \c_space_tl but~ a~ + symbol~ with~ the~ name~ `#1'~ or~ the~ input~ `#2'~ already~ exists.~ + Choose~ another~ name/input. } + +\msg_new:nnn {chemformula} {renew-addition-symbol} { - You're~using~`chemformula'~as~a~stand-alone~package~or~have~loaded~it~ - before~you've~loaded~`chemmacros',~too.~Some~features~might~not~be~ - provided!~Espacially~you~cannot~use~\token_to_str:N \chemsetup \c_space_tl - to~setup~your~formulae. + You've~ tried~ to~ redefine~ the~ addition~ symbol~ `#1'~ (input~ symbol:~ + `#2')~ but~ a~ symbol~ with~ the~ name~ `#1'~ or~ input~ `#2' doesn't~ + exist. } -\msg_new:nnnn { chemformula } { command-deprecated } +\msg_new:nnn {chemformula} {new-symbol} { - The~command~\token_to_str:N #1 \c_space_tl is~deprecated.~Use~ - \token_to_str:N #2 \c_space_tl instead. + You've~ tried~ to~ define~ the~ symbol~ `#1'~ with~ \token_to_str:N + \NewChemSymbol \c_space_tl but~ a~ symbol~ `#1'~ already~ exists.~ + Choose~ another~ input. } + +\msg_new:nnn {chemformula} {renew-symbol} + { + You've~ tried~ to~ redefine~ the~ symbol~ `#1'~ with~ \token_to_str:N + \NewChemSymbol \c_space_tl but~ a~ symbol~ `#1'~ doesn't~ exist. + } + +\msg_new:nnn {chemformula} {command-deprecated} { The~command~\token_to_str:N #1 \c_space_tl is~deprecated.~Use~ \token_to_str:N #2 \c_space_tl instead. @@ -121,7 +112,7 @@ { \cs_new_protected:Npn #1 { - \msg_warning:nnnn { chemformula } { command-deprecated } + \msg_warning:nnnn {chemformula} { command-deprecated } {#1} {#2} #3 } @@ -189,9 +180,8 @@ \bool_new:N \l__chemformula_is_option_bool \bool_new:N \l__chemformula_stoich_bool \bool_new:N \l__chemformula_no_stoich_bool -\bool_new:N \l__chemformula_is_plus_bool -\bool_new:N \l__chemformula_is_up_bool -\bool_new:N \l__chemformula_is_down_bool +\bool_new:N \l__chemformula_is_addition_symbol_bool +\bool_new:N \l__chemformula_is_symbol_bool \bool_new:N \l__chemformula_is_arrow_bool \bool_new:N \l__chemformula_is_name_bool \bool_new:N \l__chemformula_stoich_is_iupac_bool @@ -276,11 +266,6 @@ \skip_set:Nn \l__chemformula_stoich_space_skip { .1667em plus .0333em minus .0117em } \skip_new:N \l__chemformula_math_space_skip \skip_set:Nn \l__chemformula_math_space_skip { .1667em plus .0333em minus .0117em } -\skip_new:N \l__chemformula_plus_space_skip -\skip_set:Nn \l__chemformula_plus_space_skip { .3em plus .1em minus .1em } -\skip_new:N \l__chemformula_minus_space_skip -\skip_set:Nn \l__chemformula_minus_space_skip { .3em plus .1em minus .1em } - % integers: \int_new:N \l__chemformula_count_tokens_int @@ -306,14 +291,6 @@ \tl_set:Nn \l__chemformula_arrow_penalty_tl { 0 } \tl_new:N \l__chemformula_arrow_offset_tl \tl_set:Nn \l__chemformula_arrow_offset_tl { .75em } -\tl_new:N \l__chemformula_plus_penalty_tl -\tl_set:Nn \l__chemformula_plus_penalty_tl { 700 } -\tl_new:N \l__chemformula_plus_output_tl -\tl_set:Nn \l__chemformula_plus_output_tl { + } -\tl_new:N \l__chemformula_minus_penalty_tl -\tl_set:Nn \l__chemformula_minus_penalty_tl { 700 } -\tl_new:N \l__chemformula_minus_output_tl -\tl_set:Nn \l__chemformula_minus_output_tl { $-$ } \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 @@ -342,7 +319,6 @@ \tl_set:Nn \l__chemformula_superscript_shift_additional_tl { 0pt } \tl_new:N \l__chemformula_subscript_tl \tl_new:N \l__chemformula_superscript_tl -\tl_new:N \g__chemformula_input_up_tl \tl_new:N \l__chemformula_elspec_angle_tl \tl_new:N \l__chemformula_elspec_radius_tl \tl_set:Nn \l__chemformula_elspec_radius_tl { .5ex } @@ -407,6 +383,7 @@ \skip_horizontal:N #1 \chemformula_nobreak: } +\cs_generate_variant:Nn \chemformula_skip_nobreak:N {c} \cs_new_protected:Npn \chemformula_skip_nobreak_penalty:Nn #1#2 { @@ -414,6 +391,7 @@ \skip_horizontal:N #1 \tex_penalty:D #2 \scan_stop: } +\cs_generate_variant:Nn \chemformula_skip_nobreak_penalty:Nn {c} % \binoppenalty=\maxdimen % \relpenalty=\maxdimen @@ -936,7 +914,7 @@ \NewDocumentCommand \NewChemArrow { mm } { \prop_if_in:NnTF \l__chemformula_arrows_code_prop {#1} - { \msg_error:nnn { chemformula } { new-arrow } {#1} } + { \msg_error:nnn {chemformula} { new-arrow } {#1} } { % store type in the sequence and code in the property list \seq_put_right:Nn \l__chemformula_arrows_type_seq {#1} @@ -956,7 +934,7 @@ { \prop_if_in:NnTF \l__chemformula_arrows_code_prop {#1} { \prop_put:Nnn \l__chemformula_arrows_code_prop {#1} {#2} } - { \msg_error:nnn { chemformula } { renew-arrow } {#1} } + { \msg_error:nnn {chemformula} { renew-arrow } {#1} } } \NewDocumentCommand \ShowChemArrow { m } @@ -1096,12 +1074,12 @@ \cs_new:Npn \chemformula_write:n #1 { \mode_if_math:TF - { - \mathchoice - { \text { \chemformula_font_inner: #1 } } - { \text { \chemformula_font_inner: #1 } } - { \text { \scriptsize \chemformula_font_inner: #1 } } - { \text { \tiny \chemformula_font_inner: #1 } } + { \text { \chemformula_font_inner: #1} + % \mathchoice + % { \text { \chemformula_font_inner: #1 } } + % { \text { \chemformula_font_inner: #1 } } + % { \text { \scriptsize \chemformula_font_inner: #1 } } + % { \text { \tiny \chemformula_font_inner: #1 } } } { \chemformula_font_inner: #1 } } @@ -1147,52 +1125,56 @@ % bypass &: \cs_new_protected:Npn \__chemformula_ch_align:w #1 & #2 \q_stop { - \__chemformula_ch_label:w #1 \label \q_no_value \q_stop + % \__chemformula_ch_label:w #1 \label \q_no_value \q_stop + % \__chemformula_ch_tag:w #1 \tag{} \q_no_value \q_stop + \__chemformula_ch_intertext:w #1 \intertext{} \q_no_value \q_stop + % \tl_gput_right:Nn \g__chemformula_output_tl + % { \__chemformula_ch_main:n {#1} } \quark_if_no_value:nF {#2} { \tl_gput_right:Nn \g__chemformula_output_tl { & } \__chemformula_ch_align:w #2 \q_stop } } - + % bypass \label: -\cs_new_protected:Npn \__chemformula_ch_label:w #1 \label #2 \q_stop - { - \__chemformula_ch_tag:w #1 \tag{} \q_no_value \q_stop - \quark_if_no_value:nF {#2} - { - \tl_gput_right:Nn \g__chemformula_output_tl { \label } - \peek_meaning:NTF [ % ] - { \__chemformula_ch_label_opt:w } - { \__chemformula_ch_label_no_opt:n } - #2 \q_stop - } - } - -\cs_new_protected:Npn \__chemformula_ch_label_opt:w [ #1 ] #2 - { - \tl_gput_right:Nn \g__chemformula_output_tl { [{#1}] {#2} } - \__chemformula_ch_label:w - } - -\cs_new_protected:Npn \__chemformula_ch_label_no_opt:n #1 - { - \tl_gput_right:Nn \g__chemformula_output_tl { {#1} } - \__chemformula_ch_label:w - } +% \cs_new_protected:Npn \__chemformula_ch_label:w #1 \label #2 \q_stop +% { +% \__chemformula_ch_tag:w #1 \tag{} \q_no_value \q_stop +% \quark_if_no_value:nF {#2} +% { +% \tl_gput_right:Nn \g__chemformula_output_tl { \label } +% \peek_meaning:NTF [ % ] +% { \__chemformula_ch_label_opt:w } +% { \__chemformula_ch_label_no_opt:n } +% #2 \q_stop +% } +% } + +% \cs_new_protected:Npn \__chemformula_ch_label_opt:w [ #1 ] #2 +% { +% \tl_gput_right:Nn \g__chemformula_output_tl { [{#1}] {#2} } +% \__chemformula_ch_label:w +% } + +% \cs_new_protected:Npn \__chemformula_ch_label_no_opt:n #1 +% { +% \tl_gput_right:Nn \g__chemformula_output_tl { {#1} } +% \__chemformula_ch_label:w +% } % here's something not working when used together with `hyperref' % which seems to be related to \nonumber % bypass \tag: -\cs_new_protected:Npn \__chemformula_ch_tag:w #1 \tag#2 #3 \q_stop - { - \__chemformula_ch_intertext:w #1 \intertext{} \q_no_value \q_stop - \quark_if_no_value:nF {#3} - { - \tl_gput_right:Nn \g__chemformula_output_tl { \protect\tag {#2} } - \__chemformula_ch_tag:w #3 \q_stop - } - } +% \cs_new_protected:Npn \__chemformula_ch_tag:w #1 \tag#2 #3 \q_stop +% { +% \__chemformula_ch_intertext:w #1 \intertext{} \q_no_value \q_stop +% \quark_if_no_value:nF {#3} +% { +% \tl_gput_right:Nn \g__chemformula_output_tl { \protect\tag {#2} } +% \__chemformula_ch_tag:w #3 \q_stop +% } +% } % bypass \intertext: \cs_new_protected:Npn \__chemformula_ch_intertext:w #1 \intertext#2 #3 \q_stop @@ -1219,7 +1201,7 @@ \__chemformula_sanitize:Nn \l__chemformula_chemformula_tmpa_tl {#2} - \chemformula_input_cmpd:VN + \chemformula_input_cmpd_no_check:VN \l__chemformula_chemformula_tmpa_tl \l__chemformula_compound_tl \__chemformula_prepare_output:N \l__chemformula_compound_tl @@ -1706,6 +1688,7 @@ + .4 \box_ht:N \l__chemformula_tmpb_box + \l__chemformula_subscript_shift_additional_tl } + \chemformula_leave_vmode: \tex_raise:D #1 } @@ -1827,6 +1810,7 @@ - .5 \box_ht:N \l__chemformula_tmpa_box + \l__chemformula_superscript_shift_additional_tl } + \chemformula_leave_vmode: \tex_raise:D #1 } @@ -1980,9 +1964,8 @@ \l__chemformula_chemformula_tmpa_tl \l__chemformula_input_tl \chemformula_input_arrow:n {#1} \chemformula_input_name:n {#1} - \chemformula_input_plus:n {#1} - \chemformula_input_up:n {#1} - \chemformula_input_down:n {#1} + \chemformula_input_addition:n {#1} + \chemformula_input_symbol:n {#1} } % -------------------------------------------------------------------------- @@ -2163,14 +2146,9 @@ { \tl_if_blank:VTF \l__chemformula_stoich_tl { - \tl_if_eq:nnT {#1} { + } - { \bool_set_true:N \l__chemformula_is_plus_bool } - \tl_if_eq:nnT {#1} { - } - { \bool_set_true:N \l__chemformula_is_plus_bool } - \tl_if_eq:nnT {#1} { v } - { \bool_set_true:N \l__chemformula_is_down_bool } - \tl_if_eq:nnT {#1} { ^ } - { \bool_set_true:N \l__chemformula_is_up_bool } + % TODO + \__chemformula_detect_addition_symbols:n {#1} + \__chemformula_detect_symbols:n {#1} \__chemformula_detect_arrows:n {#1} \__chemformula_detect_name:n {#1} \chemformula_input_options:n {#1} @@ -2187,9 +2165,8 @@ \bool_if:nT { !\l__chemformula_is_option_bool && - !\l__chemformula_is_plus_bool && - !\l__chemformula_is_down_bool && - !\l__chemformula_is_up_bool && + !\l__chemformula_is_addition_symbol_bool && + !\l__chemformula_is_symbol_bool && !\l__chemformula_is_arrow_bool && !\l__chemformula_is_name_bool && !\l__chemformula_first_last_text_bool && @@ -2216,6 +2193,10 @@ } \cs_generate_variant:Nn \chemformula_input_cmpd:nN { V } +\cs_new_protected:Npn \chemformula_input_cmpd_no_check:nN #1#2 + { \__chemformula_handle_sub_and_superscripts:nN {#1} #2 } +\cs_generate_variant:Nn \chemformula_input_cmpd_no_check:nN { V } + \cs_new_protected:Npn \chemformula_font_inner: { \bool_if:NT \l__chemformula_fss_bool @@ -2389,71 +2370,174 @@ % -------------------------------------------------------------------------- % input "and" sign -\cs_new_protected:Npn \chemformula_input_plus:n #1 +\prop_new:N \l__chemmacros_addition_symbol_prop +\skip_new:N \l__chemformula_additions_symbol_space_skip +\tl_new:N \l__chemformula_additions_symbol_penalty_tl + +\skip_set:Nn \l__chemformula_additions_symbol_space_skip + {.3em plus .1em minus .1em} +\tl_set:Nn \l__chemformula_additions_symbol_penalty_tl {700} + +\cs_generate_variant:Nn \skip_set:Nn {cV} +\cs_generate_variant:Nn \tl_set:Nn {cV} + +% #1: name +% #2: input symbol +% #3: output symbol +\cs_new_protected:Npn \chemmacros_new_addition_symbol:nnn #1#2#3 { - \tl_if_eq:nnT {#1} { + } + \prop_put:Nnn \l__chemmacros_addition_symbol_prop {#1} {#2} + \skip_zero_new:c {l__chemformula_#1_space_skip} + \skip_set:cV {l__chemformula_#1_space_skip} + \l__chemformula_additions_symbol_space_skip + \tl_clear_new:c {l__chemformula_#1_penalty_tl} + \tl_set:cV {l__chemformula_#1_penalty_tl} + \l__chemformula_additions_symbol_penalty_tl + \tl_clear_new:c {l__chemformula_#1_output_tl} + \tl_set:cn {l__chemformula_#1_output_tl} {#3} + \keys_define:nn {chemmacros/chemformula} { - \tl_put_right:Nn \l__chemformula_input_tl + #1-space .skip_set:c = {l__chemformula_#1_space_skip} , + #1-penalty .tl_set:c = {l__chemformula_#1_penalty_tl} , + #1-output-symbol .tl_set:c = {l__chemformula_#1_output_tl} + } + } + +% #1: name +\cs_new_protected:Npn \chemformula_get_addition_symbol:n #1 + { + \chemformula_skip_nobreak:c {l__chemformula_#1_space_skip} + \tl_use:c {l__chemformula_#1_output_tl} + \chemformula_skip_nobreak_penalty:cn + {l__chemformula_#1_space_skip} + { \use:c {l__chemformula_#1_penalty_tl} } + } + +% #1: name +\cs_new_protected:Npn \chemformula_input_addition:n #1 + { + \prop_map_inline:Nn \l__chemmacros_addition_symbol_prop + { + \str_if_eq:nnT {#1} {##2} { - \chemformula_skip_nobreak:N \l__chemformula_plus_space_skip - \tl_use:N \l__chemformula_plus_output_tl - \chemformula_skip_nobreak_penalty:Nn - \l__chemformula_plus_space_skip - { \l__chemformula_plus_penalty_tl } + \tl_put_right:Nn \l__chemformula_input_tl + { \chemformula_get_addition_symbol:n {##1} } + \prop_map_break: } } - \tl_if_eq:nnT {#1} { - } + } + +% #1: input string +\cs_new_protected:Npn \__chemformula_detect_addition_symbols:n #1 + { + \bool_set_false:N \l__chemformula_is_addition_symbol_bool + \chemformula_is_addition_symbol_input:nT {#1} + { \bool_set_true:N \l__chemformula_is_addition_symbol_bool } + } + +\prg_new_protected_conditional:Npnn \chemformula_is_addition_symbol_input:n #1 {T,F,TF} + { + \bool_set_false:N \l__chemformula_tmpa_bool + \prop_map_inline:Nn \l__chemmacros_addition_symbol_prop { - \tl_put_right:Nn \l__chemformula_input_tl + \str_if_eq:nnT {#1} {##2} { - \chemformula_skip_nobreak:N \l__chemformula_minus_space_skip - \tl_use:N \l__chemformula_minus_output_tl - \chemformula_skip_nobreak_penalty:Nn - \l__chemformula_minus_space_skip - { \l__chemformula_minus_penalty_tl } + \bool_set_true:N \l__chemformula_tmpa_bool + \prop_map_break: } } - \bool_set_false:N \l__chemformula_is_plus_bool + \bool_if:NTF \l__chemformula_tmpa_bool + { \prg_return_true: } + { \prg_return_false: } } -% -------------------------------------------------------------------------- -% input escaping gas -\cs_new_protected:Npn \chemformula_input_up:n #1 +\prg_new_conditional:Npnn \chemformula_is_addition_symbol_name:n #1 {T,F,TF} { - \group_begin: - % ensure ^ has catcode 7 - % (else chemmacros wouldn't work with e.g. `breqn') - \__chemformula_sanitize:Nn \g__chemformula_input_up_tl {#1} - \char_set_catcode_math_superscript:N \^ - \__chemformula_input_up:V \g__chemformula_input_up_tl + \prop_if_in:NnTF \l__chemmacros_addition_symbol_prop {#1} + { \prg_return_true: } + { \prg_return_false: } } -\cs_new_protected:Npn \__chemformula_input_up:n #1 +\NewDocumentCommand \NewChemAdditionSymbol {mmm} { - \tl_gclear:N \g__chemformula_input_up_tl - \tl_if_eq:nnT {#1} { ^ } - { - \tl_gset:Nn \g__chemformula_input_up_tl - { \c_math_toggle_token \uparrow \c_math_toggle_token } - } - \group_end: - \tl_put_right:NV \l__chemformula_input_tl \g__chemformula_input_up_tl - \bool_set_false:N \l__chemformula_is_up_bool + \chemformula_is_addition_symbol_name:nT {#1} + { \msg_error:nnnn {chemformula} {new-addition-symbol} {#1} {#2} } + \chemformula_is_addition_symbol_input:nT {#2} + { \msg_error:nnnn {chemformula} {new-addition-symbol} {#1} {#2} } + \chemmacros_new_addition_symbol:nnn {#1} {#2} {#3} + } + +\NewDocumentCommand \RenewChemAdditionSymbol {mmm} + { + \chemformula_is_addition_symbol_name:nF {#1} + { \msg_error:nnnn {chemformula} {renew-addition-symbol} {#1} {#2} } + \chemformula_is_addition_symbol_input:nF {#2} + { \msg_error:nnnn {chemformula} {renew-addition-symbol} {#1} {#2} } + \chemmacros_new_addition_symbol:nnn {#1} {#2} {#3} } -\cs_generate_variant:Nn \__chemformula_input_up:n { V } + +\NewDocumentCommand \DeclareChemAdditionSymbol {mmm} + { \chemmacros_new_addition_symbol:nnn {#1} {#2} {#3} } + +% default addition symbols: +\NewChemAdditionSymbol {plus} {+} {+} +\NewChemAdditionSymbol {minus} {-} {$-$} % -------------------------------------------------------------------------- -% input precipitate -\cs_new_protected:Npn \chemformula_input_down:n #1 +% input escaping gas and precipitate +\prop_new:N \l__chemmacros_symbols_prop + +\cs_new_protected:Npn \chemformula_input_symbol:n #1 { - \tl_if_eq:nnT {#1} { v } + \prop_map_inline:Nn \l__chemmacros_symbols_prop { - \tl_put_right:Nn \l__chemformula_input_tl - { \c_math_toggle_token \downarrow \c_math_toggle_token } + \str_if_eq:nnT {#1} {##1} + { + \tl_put_right:Nn \l__chemformula_input_tl {##2} + \prop_map_break: + } } - \bool_set_false:N \l__chemformula_is_down_bool + \bool_set_false:N \l__chemformula_is_symbol_bool + } +\cs_generate_variant:Nn \str_if_eq:nnT {V} + +\cs_new_protected:Npn \chemmacros_new_symbol:nn #1#2 + { \prop_put:Nnn \l__chemmacros_symbols_prop {#1} {#2} } + +\cs_new_protected:Npn \__chemformula_detect_symbols:n #1 + { + \bool_set_false:N \l__chemformula_is_symbol_bool + \chemformula_is_symbol:nT {#1} + { \bool_set_true:N \l__chemformula_is_symbol_bool } } +\prg_new_conditional:Npnn \chemformula_is_symbol:n #1 {T,F,TF} + { + \prop_if_in:NnTF \l__chemmacros_symbols_prop {#1} + { \prg_return_true: } + { \prg_return_false: } + } + +\NewDocumentCommand \NewChemSymbol {mm} + { + \chemformula_is_symbol:nTF {#1} + { \msg_error:nnn {chemformula} {new-symbol} {#1} } + { \chemmacros_new_symbol:nn {#1} {#2} } + } + +\NewDocumentCommand \RenewChemSymbol {mm} + { + \chemformula_is_symbol:nTF {#1} + { \chemmacros_new_symbol:nn {#1} {#2} } + { \msg_error:nnn {chemformula} {renew-symbol} {#1} } + } + +\NewDocumentCommand \DeclareChemSymbol {mm} + { \chemmacros_new_symbol:nn {#1} {#2} } + +\NewChemSymbol {v} {$\downarrow$} +\NewChemSymbol {^} {$\uparrow$} + % -------------------------------------------------------------------------- % input arrow \cs_new_protected:Npn \chemformula_input_arrow:n #1 @@ -2696,12 +2780,6 @@ stoich-print .code:n = \cs_set_eq:NN \chemformula_print_stoich:n #1 , 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 , - plus-output-symbol .tl_set:N = \l__chemformula_plus_output_tl , - minus-space .skip_set:N = \l__chemformula_minus_space_skip , - minus-penalty .tl_set:N = \l__chemformula_minus_penalty_tl , - minus-output-symbol .tl_set:N = \l__chemformula_minus_output_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 = @@ -3166,6 +3244,11 @@ VERSION HISTORY \DeclareChemCompoundProperty, \RemoveChemCompoundProperty 2015/04/03 - version 4.10a - bug fix in \chemformula_input_stoich:n +2015/06/30 - version 4.11 - small changes in \chcpd + - remove unnecessary \mathchoice => noticable speed + improvement + - \NewChemAdditionSymbol + - \NewChemSymbol % -------------------------------------------------------------------------- % TODO |