From cbacacfcd4827d9cad12656a2b37666975770269 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 28 Oct 2011 23:42:16 +0000 Subject: chemmacros (28oct11) git-svn-id: svn://tug.org/texlive/trunk@24428 c570f23f-e606-0410-a88d-b1316a301751 --- .../tex/latex/chemmacros/chemmacros-version1.cfg | 334 +++ .../texmf-dist/tex/latex/chemmacros/chemmacros.sty | 2936 ++++++++++++++++---- 2 files changed, 2661 insertions(+), 609 deletions(-) create mode 100644 Master/texmf-dist/tex/latex/chemmacros/chemmacros-version1.cfg (limited to 'Master/texmf-dist/tex/latex/chemmacros') diff --git a/Master/texmf-dist/tex/latex/chemmacros/chemmacros-version1.cfg b/Master/texmf-dist/tex/latex/chemmacros/chemmacros-version1.cfg new file mode 100644 index 00000000000..7aa9dbcfb5b --- /dev/null +++ b/Master/texmf-dist/tex/latex/chemmacros/chemmacros-version1.cfg @@ -0,0 +1,334 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% --------------------------------------------------------------------------- % +% - chemmacros - chemmacros-version1.cfg - % +% - macros and commands for chemists - % +% --------------------------------------------------------------------------- % +% - Clemens Niederberger - % +% - 2011/10/28 - % +% --------------------------------------------------------------------------- % +% - http://www.mychemistry.eu/ - % +% - contact@mychemistry.eu - % +% --------------------------------------------------------------------------- % +% - If you have any ideas, questions, suggestions or bugs to report, please - % +% - feel free to contact me. - % +% --------------------------------------------------------------------------- % +% - Copyright 2011 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. - % +% - - % +% - This work consists of the files chemmacros.sty, chemmacros-version1.cfg,- % +% - chemmacros_doc_de.tex, chemmacros_doc_de.tex, README and the derived - % +% - files chemmacros_doc_de.pdf and chemmacros_doc_en.pdf - % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% old definitions of some commands, deprecated commands +\RequirePackage { ifthen } +% first copy old tools: +% --------------------------------------------------------------------------- % +\ExplSyntaxOff +% Test if #2 is part of #1 +% (the macro is a copy of chemfig's \CF@if@instr by Christian Tellechea) +\newcommand*\CM@ifinstr[2]{% + \def\CM@ifinstr@i##1#2##2\@nil{\ifx\@empty##2\@empty\expandafter\@secondoftwo\else\expandafter\@firstoftwo\fi}% + \CM@ifinstr@i#1#2\@nil% +} + +% split at comma, save part before in #3, save part after in \CM@RemainStr +% (the macro is a copy of chemfig's \CF@analyze@movearg by Christian Tellechea) +\def\CM@split#1,#2\@nil#3{% + \def#3{#1}\def\CM@RemainStr{#2}% +} +% --------------------------------------------------------------------------- % +% Optional Argument Analysis +\newcounter{CM@tmp@cnt} +\setcounter{CM@tmp@cnt}{0} +\newcounter{CM@splitting@cnt} +% empty \CM@arg@ +\newcommand*\CM@ClearArgs[1]{% + \whiledo{\value{CM@tmp@cnt}<#1}{% + \stepcounter{CM@tmp@cnt}% + \expandafter\let\csname CM@arg@\roman{CM@tmp@cnt}\endcsname\@empty% + }% + \setcounter{CM@tmp@cnt}{0}% +} +% split a list separated by commas into \CM@arg@, number of arguments chosen by #2 +\newcommand*\CM@splitting[2]{% + \CM@ClearArgs{#2}% + \setcounter{CM@splitting@cnt}{#2-1}% + \def\CM@RemainStr{#1}% + \whiledo{\value{CM@tmp@cnt}<\value{CM@splitting@cnt}}{% + \expandafter\CM@ifinstr\expandafter{\CM@RemainStr}{,}{% + \stepcounter{CM@tmp@cnt}% + \expandafter\CM@split\CM@RemainStr\@nil\CM@tmp@name% + \expandafter\let\csname CM@arg@\roman{CM@tmp@cnt}\endcsname\CM@tmp@name% + }{% + \stepcounter{CM@tmp@cnt}% + \expandafter\let\csname CM@arg@\roman{CM@tmp@cnt}\endcsname\CM@RemainStr% + \let\CM@RemainStr\@empty% + \setcounter{CM@tmp@cnt}{\value{CM@splitting@cnt}}% + }% + }% + \stepcounter{CM@tmp@cnt}% + \expandafter\let\csname CM@arg@\roman{CM@tmp@cnt}\endcsname\CM@RemainStr% + \setcounter{CM@tmp@cnt}{0}% +} +% --------------------------------------------------------------------------- % +% check commands for equality +\newcommand*\CM@compareCs[2]{% + \expandafter\let\expandafter\CM@cs@one\csname#1\endcsname% + \expandafter\let\expandafter\CM@cs@two\csname#2\endcsname% + \ifx\CM@cs@one\CM@cs@two\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi +} +% check strings for equality ---------------------------------------------------------- % +\newcommand*\CM@compareStr[2]{% + \edef\CM@cs@one{#1}% + \edef\CM@cs@two{#2}% + \ifx\CM@cs@one\CM@cs@two\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi +} + +% --------------------------------------------------------------------------- % +% \setnewstate, \renewstate \State +% copy of definitions in v1.1 +% \setstatesubscript{right/left} +\newcommand*\CM@State@subscript{left} +\newcommand*\setstatesubscript[1]{% + \renewcommand*\CM@State@subscript{\ifx\relax#1\relax left\else#1\fi} +} +% \State[,,]{}{} +% {} is an optional argument! +\NewDocumentCommand\State{omG{}}{% + \IfNoValueTF{#1}{\CM@splitting{}{3}}{\CM@splitting{#1}{3}}% + \ensuremath{% + \CM@compareCs{CM@arg@iii}{@empty}{% + \CM@compareStr{\CM@State@subscript}{right}{\let\CM@State@sub@left\@empty\def\CM@State@sub@right{_\mathrm{#3}}}{\let\CM@State@sub@right\@empty\def\CM@State@sub@left{_\mathrm{#3}}}% + }{ + \CM@compareStr{\CM@arg@iii}{right}{\let\CM@State@sub@left\@empty\def\CM@State@sub@right{_\mathrm{#3}}}{% + \CM@compareStr{\CM@arg@iii}{left}{\let\CM@State@sub@right\@empty\def\CM@State@sub@left{_\mathrm{#3}}}{% + \PackageWarning{chemmacros}{\string\State: can only have the values 'left' or 'right'}{}% + } + }% + }% + \CM@compareCs{CM@arg@ii}{@empty}{\Delta}{\CM@arg@ii}\CM@State@sub@left#2\CM@State@sub@right% + \CM@compareCs{CM@arg@i}{@empty}{^{\standardstate}}{^{\CM@arg@i}}}% +} + +% \setnewstate[,,]{}{}{} +% \renewstate[,,]{}{}{} +\newcommand*\CM@setnewstate[4][]{% + \CM@splitting{#1}{3}% [,,] + \CM@compareCs{CM@arg@i}{@empty}{\expandafter\let\csname CM@#2@supscript\endcsname\standardstate}{\expandafter\let\csname CM@#2@supscript\endcsname\CM@arg@i}% + \CM@compareCs{CM@arg@ii}{@empty}{\expandafter\let\csname CM@#2@delta\endcsname\Delta}{\expandafter\let\csname CM@#2@delta\endcsname\CM@arg@ii} + \CM@compareCs{CM@arg@iii}{@empty}{\@namedef{CM@#2@right}{left}}{\expandafter\let\csname CM@#2@right\endcsname\CM@arg@iii}% + \@namedef{#2}{\@ifnextchar[{\@nameuse{CM@#2@ii}}{\@nameuse{CM@#2@i}}}% + \@namedef{CM@#2@i}##1{\ensuremath{\State[\@nameuse{CM@#2@supscript},\@nameuse{CM@#2@delta},\@nameuse{CM@#2@right}]{#3}{}=\SI{##1}{#4}}}% + \@namedef{CM@#2@ii}[##1]##2{% + \CM@splitting{##1}{4}% [,,,] + \let\CM@State@index\CM@arg@i + \CM@compareCs{CM@arg@ii}{@empty}{\def\CM@State@supscript{\@nameuse{CM@#2@supscript}}}{\let\CM@State@supscript\CM@arg@ii}% + \CM@compareCs{CM@arg@iii}{@empty}{\def\CM@State@unit{#4}}{\let\CM@State@unit\CM@arg@iii}% + \CM@compareCs{CM@arg@iv}{@empty}{\def\CM@State@right{\@nameuse{CM@#2@right}}}{\let\CM@State@right\CM@arg@iv}% + \ensuremath{\State[\CM@State@supscript,\@nameuse{CM@#2@delta},\CM@State@right]{#3}{\CM@State@index} = \SI{##2}{\CM@State@unit}}% + }% +} +\newcommand*\setnewstate[4][]{% + \@ifundefined{#2}{\CM@setnewstate[#1]{#2}{#3}{#4}}{\PackageError{chemmacros}{\string\setnewstate: state #2 is already defined}{}}% +} +\newcommand*\renewstate[4][]{% + \@ifundefined{#2}{\PackageError{chemmacros}{\string\renewstate: state #2 is not defined}{}}{\CM@setnewstate[#1]{#2}{#3}{#4}}% +} +\setnewstate{Enthalpy}{H}{\kilo\joule\per\mole}% +\setnewstate[, ]{Entropy}{S}{\joule\per\kelvin\per\mole}% +\setnewstate{Gibbs}{G}{\kilo\joule\per\mole}% + +\ExplSyntaxOn + +% --------------------------------------------------------------------------- % +% \newreaction +\NewDocumentCommand \newreaction { s t+ m m } + { + \cs_if_exist:cTF { #3 } + { + \msg_error:nnx { chemmacros } { already-defined } { #3 } + } + { + \IfBooleanTF { #1 } + { \bool_set_true:N \l_chemmacros_reactions_star_bool } + { \bool_set_false:N \l_chemmacros_reactions_star_bool } + \IfBooleanTF { #2 } + { \bool_set_true:N \l_chemmacros_reactions_args_bool } + { \bool_set_false:N \l_chemmacros_reactions_args_bool } + \bool_if:NTF \l_chemmacros_reactions_args_bool + { + \NewEnviron { #3 } [ 1 ] + { + \chemmacros_begin_reaction: + \begin { #4 } { ##1 } + \chemmacros_cee:f { \BODY } + \end{ #4 } + \chemmacros_end_reaction: + } + \bool_if:NT \l_chemmacros_reactions_star_bool + { + \NewEnviron { #3* } [ 1 ] + { + \begin { #4* } { ##1 } + \chemmacros_cee:f { \BODY } + \end { #4* } + } + } + } + { + \NewEnviron { #3 } + { + \chemmacros_begin_reaction: + \begin { #4 } + \chemmacros_cee:f { \BODY } + \end { #4 } + \chemmacros_end_reaction: + } + \bool_if:NT \l_chemmacros_reactions_star_bool + { + \NewEnviron { #3* } + { + \begin { #4* } + \chemmacros_cee:f { \BODY } + \end { #4* } + } + } + } + } + } + +\newreaction* { reaction } { equation } +\newreaction* { reactions } { align } + +% --------------------------------------------------------------------------- % +% \mhName +% copy of definition in v1.1 +% placing text below atom/molecule + \newcommand*\CM@mhName@textattr@default{\centering\tiny} +% \setmhName{} + \newcommand*\setmhName[1]{ + \ifx\@empty#1\@empty + \renewcommand*\CM@mhName@textattr@default{\centering\tiny} + \else + \renewcommand*\CM@mhName@textattr@default{#1} + \fi + } +% \mhName[][]{}{} + \newlength{\CM@mhName@boxlength} + \NewDocumentCommand\mhName{oomm}{ + \IfNoValueTF{#1}{ + \settowidth{\CM@mhName@boxlength}{#3} + }{ + \ifx\@empty#1\@empty + \settowidth{\CM@mhName@boxlength}{#3} + \else + \setlength{\CM@mhName@boxlength}{#1} + \fi + }% + \IfNoValueTF{#2}{ + \let\CM@mhName@textattr\CM@mhName@textattr@default + }{ + \def\CM@mhName@textattr{#2} + } + \def\CM@mhName@formula{#3} + \ensuremath{\underset{\parbox{\CM@mhName@boxlength} + {\CM@mhName@textattr#4}}{\expandafter\ce\expandafter{\CM@mhName@formula}}} + } + +\ExplSyntaxOff +% --------------------------------------------------------------------------- % +% \newman +% copy of definition in v1.1 +\NewDocumentCommand\newman{ooom}{% + \IfNoValueTF{#1}{% + \def\CM@newman@angle{0}% + \def\CM@newman@scale{1}% + \def\CM@newman@tikz@ring{}% + }{% + \CM@splitting{#1}{3}% + \CM@compareCs{CM@arg@i}{@empty}{\def\CM@newman@angle{0}}{\let\CM@newman@angle\CM@arg@i}% + \CM@compareCs{CM@arg@ii}{@empty}{\def\CM@newman@scale{1}}{\let\CM@newman@scale\CM@arg@ii}% + \expandafter\def\expandafter\CM@newman@tikz@ring\expandafter{\CM@arg@iii}% + } + \IfNoValueTF{#2}{% + \let\CM@newman@tikz@one\@empty% + }{% + \def\CM@newman@tikz@one{#2}% + } + \IfNoValueTF{#3}{% + \let\CM@newman@tikz@two\CM@newman@tikz@one% + }{% + \def\CM@newman@tikz@two{#3}% + } + \CM@splitting{#4}{6}% + \edef\CM@newman@tikz{scale=\CM@newman@scale,CMatomFront/.style={inner sep=0,outer sep=0,\CM@newman@tikz@one},CMatomBack/.style={inner sep=0,outer sep=0,\CM@newman@tikz@two}} + \expandafter\tikz\expandafter[\CM@newman@tikz]{% + \expandafter\draw\expandafter[\CM@newman@tikz@ring] (0,0) circle (.5);% + \foreach\i in{30+\CM@newman@angle,150+\CM@newman@angle,270+\CM@newman@angle}{% + \expandafter\draw\expandafter[\CM@newman@tikz@ring] (\i:0.5) --++(\i:.5);% + }% + \node[CMatomBack,anchor=-150+\CM@newman@angle] at (30+\CM@newman@angle:1.05) {\CM@arg@v};% + \node[CMatomBack,anchor=-30+\CM@newman@angle] at (150+\CM@newman@angle:1.05) {\CM@arg@vi};% + \node[CMatomBack,anchor=90+\CM@newman@angle] at (270+\CM@newman@angle:1.05) {\CM@arg@iv};% + \foreach\i in{90,210,330}{% + \expandafter\draw\expandafter[\CM@newman@tikz@ring] (0,0) --++(\i:1);% + }% + \node[CMatomFront,anchor=-90] at (90:1.05) {\CM@arg@i};% + \node[CMatomFront,anchor=30] at (210:1.05) {\CM@arg@ii};% + \node[CMatomFront,anchor=150] at (330:1.05) {\CM@arg@iii};% + }% +} + +% --------------------------------------------------------------------------- % +% - p-orbitals -------------------------------------------------------------- % +% copy of definition in v1.1 +\newcommand*\CM@porb[1][]{% + \CM@splitting{#1}{3}% + \CM@compareCs{CM@arg@i}{@empty}{\let\CM@orbital@height\CM@orb@height}{\def\CM@orbital@height{\CM@arg@i*\CM@orb@height}}% + \CM@compareCs{CM@arg@ii}{@empty}{\def\CM@orb@color{black}}{\let\CM@orb@color\CM@arg@ii}% + \CM@compareStr{\CM@orb@color}{white}{\def\CM@orb@color@draw{black}}{\let\CM@orb@color@draw\CM@orb@color}% + \CM@compareCs{CM@arg@iii}{@empty}{\def\CM@orb@ang{0}}{\let\CM@orb@ang\CM@arg@iii}% + \tikzpicture[overlay,rotate={\CM@orb@ang-90},opacity=.5,inner sep=0pt,outer sep=0pt,text height=0pt,text depth=0pt]% + \pgfsetfillopacity{.5}% + \CM@compareStr{\CM@orb@half}{false}{% + \draw[draw=black] (0,0) .. controls ++(-.9*\CM@orbital@height,-1.5*\CM@orbital@height) and ++(.9*\CM@orbital@height,-1.5*\CM@orbital@height) .. (0,0);% + }{}% + \draw[draw=\CM@orb@color@draw,fill=\CM@orb@color] (0,0) .. controls ++(-.9*\CM@orbital@height,1.5*\CM@orbital@height) and ++(.9*\CM@orbital@height,1.5*\CM@orbital@height) .. (0,0);% + \endtikzpicture% +} +% full orbital: +% \porb[,,] +\newcommand*\porb{\def\CM@orb@half{false}\CM@porb}% +% half of an orbital: +% \phorb[,,] +\newcommand*\phorb{\def\CM@orb@half{true}\CM@porb}% + +% predefined orbitals: +\newcommand*\pzorb{\porb[,,90]}% +\newcommand*\pyorb{\porb[,,0]}% +\newcommand*\pxorb{\porb[,,-135]}% + +% change orbital settings: +\newcommand*\CM@orb@height{1em}% +\newcommand*\setorbheight[1]{% + \ifx\@empty#1\@empty + \renewcommand*\CM@orb@height{1em}% + \else + \renewcommand*\CM@orb@height{#1}% + \fi +} + +\ExplSyntaxOn + +\tex_endinput:D \ No newline at end of file diff --git a/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty b/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty index dcf361df406..659757ef0cd 100644 --- a/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty +++ b/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty @@ -1,633 +1,2351 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% ------------------------------------------------------------------------------------- % -% - chemmacros - chemmacros.sty ------------------------------------------------------- % -% - a collection of macros to make typesetting chemistry documents more convenient ---- % -% ------------------------------------------------------------------------------------- % -% - Clemens Niederberger -------------------------------------------------------------- % -% - 2011/06/22 ------------------------------------------------------------------------ % -% ------------------------------------------------------------------------------------- % -% - http://www.mychemistry.eu/ -------------------------------------------------------- % -% - contact@mychemistry.eu ------------------------------------------------------------ % -% ------------------------------------------------------------------------------------- % -% - If you have any ideas, questions, suggestions or bugs to report, please feel free - % -% - to contact me. -------------------------------------------------------------------- % -% ------------------------------------------------------------------------------------- % -% - Copyright 2011 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. - % -% - - % -% - This work consists of the files chemmacros.sty, chemmacros_doc_de.tex, - % -% - chemmacros_doc_de.tex, README - % -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\newcommand*\CM@version{1.1}% -\newcommand*\CM@date{2011/06/22}% -\newcommand*\CM@name{chemmacros}% -\NeedsTeXFormat{LaTeX2e}[2009/09/24]% -\ProvidesPackage{chemmacros}[2011/06/22 v1.1 chemistry macros]% -\RequirePackage{amsmath,tikz,xparse,ifthen,siunitx}% -\usetikzlibrary{calc}% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - ifs ------------------------------------------------------------------------------- % -\newif\if@CM@circled\@CM@circledfalse% -\newif\if@CM@german\@CM@germanfalse% -\newif\if@CM@xspace\@CM@xspacefalse% -\newif\if@CM@mhchemloaded\@CM@mhchemloadedfalse% -\newif\if@CM@chemstyleloaded\@CM@chemstyleloadedfalse% -\newif\if@CM@bpchemloaded\@CM@bpchemloadedfalse% -\newif\if@CM@bpchem\@CM@bpchemfalse% -\newif\if@CM@mychemistryloaded\@CM@mychemistryloadedfalse% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - package options ------------------------------------------------------------------- % -% circled: -\DeclareOption{circled}{% - \@CM@circledtrue% -} - -% xspace: -\newcommand*\CM@xspace{} -\DeclareOption{xspace}{% - \@CM@xspacetrue% -} - -% german: -\DeclareOption{german}{% - \@CM@germantrue% -} - -% bpchem: -\DeclareOption{bpchem}{ - \@CM@bpchemtrue -} - -% unknown options: -\DeclareOption*{% - \PackageWarning{chemmacros}{Unknown option `\CurrentOption'}% -} -\ProcessOptions\relax - -\if@CM@bpchem - \RequirePackage{bpchem} -\fi - -\if@CM@xspace - \RequirePackage{xspace}% - \let\CM@xspace\xspace% -\fi - -\AtBeginDocument{% - \@ifpackageloaded{mhchem}{\@CM@mhchemloadedtrue}{\@CM@mhchemloadedfalse} - \@ifpackageloaded{chemstyle}{\@CM@chemstyleloadedtrue}{\@CM@chemstyleloadedfalse} - \@ifpackageloaded{bpchem}{\@CM@bpchemloadedtrue}{\@CM@bpchemloadedfalse} - \@ifpackageloaded{mychemistry}{\@CM@mychemistryloadedtrue}{\@CM@mychemistryloadedfalse} - - \if@CM@mhchemloaded - \newcommand*\CM@atom[1]{\cf{#1}}% - \else - \newcommand*\CM@atom[1]{\mbox{#1}}% - \fi - - \if@CM@circled - \let\CM@plus\oplus - \let\CM@minus\ominus - \else - \newcommand*\CM@plus{+}% - \newcommand*\CM@minus{-}% - \fi -} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - tools ----------------------------------------------------------------------------- % -% Test if #2 is part of #1 -% (the macro is a copy of chemfig's \CF@if@instr by Christian Tellechea) -\newcommand*\CM@ifinstr[2]{% - \def\CM@ifinstr@i##1#2##2\@nil{\ifx\@empty##2\@empty\expandafter\@secondoftwo\else\expandafter\@firstoftwo\fi}% - \CM@ifinstr@i#1#2\@nil% -} - -% split at comma, save part before in #3, save part after in \CM@RemainStr -% (the macro is a copy of chemfig's \CF@analyze@movearg by Christian Tellechea) -\def\CM@split#1,#2\@nil#3{% - \def#3{#1}\def\CM@RemainStr{#2}% -} - -% Optional Argument Analysis ---------------------------------------------------------- % -\newcounter{CM@tmp@cnt} -\setcounter{CM@tmp@cnt}{0} -\newcounter{CM@splitting@cnt} -% empty \CM@arg@ -\newcommand*\CM@ClearArgs[1]{% - \whiledo{\value{CM@tmp@cnt}<#1}{% - \stepcounter{CM@tmp@cnt}% - \expandafter\let\csname CM@arg@\roman{CM@tmp@cnt}\endcsname\@empty% - }% - \setcounter{CM@tmp@cnt}{0}% -} -% split a list separated by commas into \CM@arg@, number of arguments chosen by #2 -\newcommand*\CM@splitting[2]{% - \CM@ClearArgs{#2}% - \setcounter{CM@splitting@cnt}{#2-1}% - \def\CM@RemainStr{#1}% - \whiledo{\value{CM@tmp@cnt}<\value{CM@splitting@cnt}}{% - \expandafter\CM@ifinstr\expandafter{\CM@RemainStr}{,}{% - \stepcounter{CM@tmp@cnt}% - \expandafter\CM@split\CM@RemainStr\@nil\CM@tmp@name% - \expandafter\let\csname CM@arg@\roman{CM@tmp@cnt}\endcsname\CM@tmp@name% - }{% - \stepcounter{CM@tmp@cnt}% - \expandafter\let\csname CM@arg@\roman{CM@tmp@cnt}\endcsname\CM@RemainStr% - \let\CM@RemainStr\@empty% - \setcounter{CM@tmp@cnt}{\value{CM@splitting@cnt}}% - }% - }% - \stepcounter{CM@tmp@cnt}% - \expandafter\let\csname CM@arg@\roman{CM@tmp@cnt}\endcsname\CM@RemainStr% - \setcounter{CM@tmp@cnt}{0}% -} - -% check commands for equality --------------------------------------------------------- % -\newcommand*\CM@compareCs[2]{% - \expandafter\let\expandafter\CM@cs@one\csname#1\endcsname% - \expandafter\let\expandafter\CM@cs@two\csname#2\endcsname% - \ifx\CM@cs@one\CM@cs@two\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi -} - -% check strings for equality ---------------------------------------------------------- % -\newcommand*\CM@compareStr[2]{% - \edef\CM@cs@one{#1}% - \edef\CM@cs@two{#2}% - \ifx\CM@cs@one\CM@cs@two\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi -} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - particles, charges ---------------------------------------------------------------- % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% --------------------------------------------------------------------------- % +% - chemmacros - chemmacros.sty - % +% - macros and commands for chemists - % +% --------------------------------------------------------------------------- % +% - Clemens Niederberger - % +% - 2011/10/28 - % +% --------------------------------------------------------------------------- % +% - http://www.mychemistry.eu/ - % +% - contact@mychemistry.eu - % +% --------------------------------------------------------------------------- % +% - If you have any ideas, questions, suggestions or bugs to report, please - % +% - feel free to contact me. - % +% --------------------------------------------------------------------------- % +% - Copyright 2011 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. - % +% - - % +% - This work consists of the files chemmacros.sty, chemmacros-version1.cfg - % +% - chemmacros_doc_de.tex, chemmacros_doc_de.tex, README and the derived - % +% - files chemmacros_doc_de.pdf and chemmacros_doc_en.pdf - % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\RequirePackage{ expl3 , xparse , l3keys2e , xfrac , siunitx , tikz , mathtools , cancel , environ } +\usetikzlibrary{calc,arrows} +\AtBeginDocument + { + \@ifpackageloaded{mhchem}{} { \RequirePackage[ version=3 ]{ mhchem } } + } +\ProvidesExplPackage {chemmacros} {2011/10/27} {2.0} {macros and commands for chemists} + +\bool_new:N \l_chemmacros_version_one_bool +\bool_set_false:N \l_chemmacros_version_one_bool + +\bool_new:N \l_chemmacros_german_bool +\bool_set_false:N \l_chemmacros_german_bool + +\bool_new:N \l_chemmacros_xspace_bool +\bool_set_true:N \l_chemmacros_xspace_bool + +\bool_new:N \l_chemmacros_bpchem_bool +\bool_set_false:N \l_chemmacros_bpchem_bool + +\bool_new:N \l_chemmacros_circled_bool +\bool_set_true:N \l_chemmacros_circled_bool + +\bool_new:N \l_chemmacros_circled_formal_bool +\bool_set_true:N \l_chemmacros_circled_formal_bool + +\bool_new:N \l_chemmacros_circled_chem_bool +\bool_set_true:N \l_chemmacros_circled_chem_bool + +\bool_new:N \l_chemmacros_EZ_cool_bool +\bool_set_false:N \l_chemmacros_EZ_cool_bool + +\bool_new:N \l_chemmacros_chemstyle_bool +\bool_new:N \l_chemmacros_hyperref_bool +\bool_new:N \l_chemmacros_varioref_bool + +\AtBeginDocument + { + \@ifpackageloaded { chemstyle } + { \bool_set_true:N \l_chemmacros_chemstyle_bool } + { \bool_set_false:N \l_chemmacros_chemstyle_bool } + \@ifpackageloaded { varioref } + { \bool_set_true:N \l_chemmacros_varioref_bool } + { \bool_set_false:N \l_chemmacros_varioref_bool } + \@ifpackageloaded { hyperref } + { \bool_set_true:N \l_chemmacros_hyperref_bool } + { \bool_set_false:N \l_chemmacros_hyperref_bool } + } + +% --------------------------------------------------------------------------- % +% package options +% german => change pKA => pKS etc +% xspace => add an \xspace after a whole bunch of macros +% bpchem => use \IUPAC inside for \NMR command +% circled => circle charges +% EZ => cool or chemmacros version of \E +% version=1 => compatibility for documents set with v1.* + +\keys_define:nn { chemmacros / option } + { + bpchem .bool_set:N = \l_chemmacros_bpchem_bool , + bpchem .default:n = true , + circletype .choice: , + circletype / math .code:n = + { \bool_set_false:N \l_chemmacros_circled_chem_bool } , + circletype / chem .code:n = + { \bool_set_true:N \l_chemmacros_circled_chem_bool } , + circletype .default:n = chem , + circled .choice: , + circled / none .code:n = + { + \bool_set_false:N \l_chemmacros_circled_bool + \bool_set_false:N \l_chemmacros_circled_formal_bool + } , + circled / formal .code:n = + { + \bool_set_true:N \l_chemmacros_circled_bool + \bool_set_true:N \l_chemmacros_circled_formal_bool + } , + circled / all .code:n = + { + \bool_set_true:N \l_chemmacros_circled_bool + \bool_set_false:N \l_chemmacros_circled_formal_bool + } , + circled .default:n = formal , + EZ .choice: , + EZ / cool .code:n = + { \bool_set_true:N \l_chemmacros_EZ_cool_bool } , + EZ / chemmacros .code:n = + { \bool_set_false:N \l_chemmacros_EZ_cool_bool } , + EZ .default:n = chemmacros , + german .bool_set:N = \l_chemmacros_german_bool , + german .default:n = true , + xspace .bool_set:N = \l_chemmacros_xspace_bool , + xspace .default:n = true , + version .choice: , + version / 1 .code:n = + { \bool_set_true:N \l_chemmacros_version_one_bool } , + version / 2 .code:n = + { \bool_set_false:N \l_chemmacros_version_one_bool } + } + +\ProcessKeysOptions { chemmacros / option } + +\AtBeginDocument + { + \bool_if:NT \l_chemmacros_bpchem_bool + { \RequirePackage { bpchem } } + \bool_if:NT \l_chemmacros_xspace_bool + { \RequirePackage { xspace } } + } + +\cs_new_nopar:Npn \chemmacros_xspace: + { + \bool_if:NT \l_chemmacros_xspace_bool + { \xspace } + } + +% --------------------------------------------------------------------------- % +% warning / error messages +\msg_set:nnnn { chemmacros } { already-defined } + { + The~command~#1~has~also~been~defined~by~another~package. + } + { + The~command~#1~has~also~been~defined~by~another~package.~ + chemmacros~provides~an~alternative~definition.~ + See~the~documentation~for~more~information. + } + +\msg_set:nnn { chemmacros } { circled=chemfig } + { + You~used~the~option~"circled~=~chemfig"~but~did~not~load~the~package~ + chemfig.~Option~"circled~=~formal"~will~be~used~instead. + } + +\msg_set:nnn { chemmacros } { ox } + { + \token_to_str:N \ox \c_space_tl : ~ #1 ~ \msg_line_context: . + } + +\msg_set:nnn { chemmacros } { OX } + { + \token_to_str:N \OX \c_space_tl : ~ #1 ~ \msg_line_context: . + } + +\msg_set:nnn { chemmacros } { redox } + { + \token_to_str:N \redox \c_space_tl : ~ #1 ~ \msg_line_context: . + } + +\msg_set:nnn { chemmacros } { already-defined } + { + The~command/environment ~ #1 ~ \msg_line_context: \c_space_tl + is~already~defined. + } + +\msg_set:nnnn { chemmacros } { outside-MOdiagram } + { You~can't~use~#1~outside~the~MOdiagram~environment. } + { + The~command~#1~can~only~be~used~inside~the~MOdiagram~ + environment~\msg_line_context: . + } + +\msg_set:nnn { chemmacros } { setnewstate } + { + The~state~\tl_to_str:n { \ #1 } \c_space_tl already~exists.~You~need~to~ + use~\token_to_str:N \renewstate \c_space_tl to~alter~it. + } + +\msg_set:nnn { chemmacros } { renewstate } + { + The~state~\tl_to_str:n { \ #1 } \c_space_tl isn't~set~up~yet.~You~need~to~ + use~\token_to_str:N \setnewstate \c_space_tl to~create~it. + } + +% --------------------------------------------------------------------------- % +% TikZ drawings +\cs_new_nopar:Npn \chemmacros_tikz_picture:nn #1#2 + { \tikzpicture[#1] #2 \endtikzpicture } +\cs_generate_variant:Nn \chemmacros_tikz_picture:nn { fn,xn } + +\cs_new_nopar:Npn \chemmacros_tikz_draw:n #1 + { \draw[#1] } +\cs_generate_variant:Nn \chemmacros_tikz_draw:n { f,x } + +\cs_new_nopar:Npn \chemmacros_tikz_node:n #1 + { \node[#1] } +\cs_generate_variant:Nn \chemmacros_tikz_node:n { f,x } + +\cs_new_nopar:Npn \chemmacros_tikz_shade:n #1 + { \shade[#1] } +\cs_generate_variant:Nn \chemmacros_tikz_shade:n { f,x } + +\cs_new_nopar:Npn \chemmacros_tikz_shadedraw:n #1 + { \shadedraw[#1] } +\cs_generate_variant:Nn \chemmacros_tikz_shadedraw:n { f,x } + +\cs_new_nopar:Npn \chemmacros_tikz_node_in_draw:n #1 + { node[#1] } +\cs_generate_variant:Nn \chemmacros_tikz_node_in_draw:n { f,x } + +% --------------------------------------------------------------------------- % +% circled charge signs +\cs_new_nopar:Npn \chemmacros_fplus_aux: + { + \raise.1ex\hbox{\scalebox{.65}{\textcircled{\lower.1ex\hbox{$+$}}}} + } +\cs_new_nopar:Npn \chemmacros_fplus: + { + \mode_if_math:TF + { \text { \chemmacros_fplus_aux: } } + { \chemmacros_fplus_aux: } + } + +\cs_new_nopar:Npn \chemmacros_fminus_aux: + { + \raise.1ex\hbox{\scalebox{.65}{\textcircled{\lower.1ex\hbox{$-$}}}} + } +\cs_new_nopar:Npn \chemmacros_fminus: + { + \mode_if_math:TF + { \text { \chemmacros_fminus_aux: } } + { \chemmacros_fminus_aux: } + } + +% use directly: +\cs_new_eq:NN \fplus \chemmacros_fplus: +\cs_new_eq:NN \fminus \chemmacros_fminus: + +% change output depending on circled-option +\cs_new_nopar:Npn \chemmacros_plus: + { + \bool_if:nTF { \l_chemmacros_circled_bool && !\l_chemmacros_circled_formal_bool } + { + \bool_if:NTF \l_chemmacros_circled_chem_bool + { \chemmacros_fplus: } + { \oplus } + } + { + } + } + +\cs_new_nopar:Npn \chemmacros_minus: + { + \bool_if:nTF { \l_chemmacros_circled_bool && !\l_chemmacros_circled_formal_bool } + { + \bool_if:NTF \l_chemmacros_circled_chem_bool + { \chemmacros_fminus: } + { \ominus } + } + { - } + } + +\cs_new_nopar:Npn \chemmacros_formal_plus: + { + \bool_set_false:N \l_chemmacros_circled_formal_bool + \chemmacros_plus: + } + +\cs_new_nopar:Npn \chemmacros_formal_minus: + { + \bool_set_false:N \l_chemmacros_circled_formal_bool + \chemmacros_minus: + } + +% --------------------------------------------------------------------------- % +% transition state symbol +\AtBeginDocument + { + \cs_new_nopar:Npn \chemmacros_transitionstatesymbol: + { + \mode_if_math:TF + { \text { \chemmacros_transitionstatesymbol_aux: } } + { \chemmacros_transitionstatesymbol_aux: } + } + + \cs_new_nopar:Npn \chemmacros_transitionstatesymbol_aux: + { + \tikz[inner~sep=0,outer~sep=0,minimum~size=0,space-space,line~width=.3pt] + { + \draw (0,0) -- + node[pos=.36] + (chemmacros_transitionstate_x) {} + node[pos=.64] + (chemmacros_transitionstate_y){} + (0,.8em) ; + \draw (chemmacros_transitionstate_x) ++(-.4em,0) -- ++(.8em,0) ; + \draw (chemmacros_transitionstate_y) ++(-.4em,0) -- ++(.8em,0) ; + } + } + + \@ifpackageloaded{mychemistry} + { + \cs_set_eq:NN + \transitionstatesymbol + \chemmacros_transitionstatesymbol: + } + { + \cs_new_eq:NN + \transitionstatesymbol + \chemmacros_transitionstatesymbol: + } + } + +\cs_new_nopar:Npn \chemmacros_atom:n #1 + { \ce { #1 } } +\cs_generate_variant:Nn \chemmacros_atom:n { o,f,x } + +% --------------------------------------------------------------------------- % +% particles, charges % electron -\newcommand*\el{\ensuremath{e^\CM@minus}\CM@xspace} +\bool_new:N \l_chemmacros_charge_append_bool +\bool_set_false:N \l_chemmacros_charge_append_bool + +\cs_new_nopar:Npn \el + { \chemmacros_atom:n { e } \mch \chemmacros_xspace: } % proton -\newcommand*\prt{\ensuremath{p^\CM@plus}\CM@xspace} -% charges -\newcommand*\mch[1][]{\ensuremath{{}^{#1\CM@minus}}} -\newcommand*\pch[1][]{\ensuremath{{}^{#1\CM@plus}}} -\newcommand*\delm{\mbox{\tiny$\delta\CM@minus$}\CM@xspace} -\newcommand*\delp{\mbox{\tiny$\delta\CM@plus$}\CM@xspace} -\newcommand*\scrm{\ensuremath{\scriptstyle\CM@minus}} -\newcommand*\scrp{\ensuremath{\scriptstyle\CM@plus}} +\cs_new_nopar:Npn \prt + { \chemmacros_atom:n { p } \pch \chemmacros_xspace: } % neutron -\newcommand*\ntr{\ensuremath{n^0}\CM@xspace} +\cs_new_nopar:Npn \ntr + { \chemmacros_atom:n { n^0 } \chemmacros_xspace: } + +% charges +\cs_new_nopar:Npn \chemmacros_charge:n #1 + { + \bool_if:NTF \l_chemmacros_charge_append_bool + { + \mode_if_math:TF + { {}^ { #1 } } + { $ {}^ { #1 } $ } + } + { + \mode_if_math:TF + { ^ { #1 } } + { $ ^ { #1 } $ } + } + } + +\keys_define:nn { chemmacros / charges } + { + append .bool_set:N = \l_chemmacros_charge_append_bool , + append .default:n = true + } + +\NewDocumentCommand \mch { o } + { + \IfNoValueTF { #1 } + { \chemmacros_charge:n { \chemmacros_minus: } } + { \chemmacros_charge:n { #1 \chemmacros_minus: } } + } -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - stereo descriptors and sim. ------------------------------------------------------- % +\NewDocumentCommand \pch { o } + { + \IfNoValueTF { #1 } + { \chemmacros_charge:n { \chemmacros_plus: } } + { \chemmacros_charge:n { #1 \chemmacros_plus: } } + } + +\NewDocumentCommand \fmch { o } + { + \IfNoValueTF { #1 } + { \chemmacros_charge:n { \chemmacros_formal_minus: } } + { \chemmacros_charge:n { #1 \chemmacros_formal_minus: } } + } + +\NewDocumentCommand \fpch { o } + { + \IfNoValueTF { #1 } + { \chemmacros_charge:n { \chemmacros_formal_plus: } } + { \chemmacros_charge:n { #1 \chemmacros_formal_plus: } } + } + +\cs_new_nopar:Npn \delm + { \mbox { \tiny \( \delta \chemmacros_minus: \) } \chemmacros_xspace: } +\cs_new_nopar:Npn \delp + { \mbox { \tiny \( \delta \chemmacros_plus: \) } \chemmacros_xspace: } +\cs_new_nopar:Npn \fdelm + { \mbox { \tiny \( \delta \chemmacros_formal_minus: \) } \chemmacros_xspace: } +\cs_new_nopar:Npn \fdelp + { \mbox { \tiny \( \delta \chemmacros_formal_plus: \) } \chemmacros_xspace: } +\cs_new_nopar:Npn \scrm + { \ensuremath { \scriptstyle \chemmacros_minus: } } +\cs_new_nopar:Npn \scrp + { \ensuremath { \scriptstyle \chemmacros_plus: } } +\cs_new_nopar:Npn \fscrm + { \ensuremath { \scriptstyle \chemmacros_formal_minus: } } +\cs_new_nopar:Npn \fscrp + { \ensuremath { \scriptstyle \chemmacros_formal_plus: } } + +% --------------------------------------------------------------------------- % +% ions, molecules +% proton, hydroxide, hydronium/oxonium, water, nucleophile, electrophile +\cs_new_nopar:Npn \Hpl + { \chemmacros_atom:n { H } \pch \chemmacros_xspace: } +\cs_new_nopar:Npn \Hyd + { \chemmacros_atom:n { OH } \mch \chemmacros_xspace: } +\cs_new_nopar:Npn \HtO + { \chemmacros_atom:n { H3O } \pch \chemmacros_xspace: } +\cs_new_nopar:Npn \water + { \chemmacros_atom:n { H2O } \chemmacros_xspace: } +\cs_new_nopar:Npn \Nu + { \chemmacros_atom:n { Nu } \mch \chemmacros_xspace: } +\cs_new_nopar:Npn \El + { \chemmacros_atom:n { E } \pch \chemmacros_xspace: } + +% --------------------------------------------------------------------------- % +% stereo descriptors and sim. % Cahn-Ingold-Prelog -\newcommand*\Rcip{\textit{(R)}} -\newcommand*\Scip{\textit{(S)}} -\newcommand*\cip[1]{\textit{(#1)}} -\newcommand*\Sconf[1][S]{\tikz[baseline=(a.base),text height=1.5ex,text depth=.25ex]{\draw node(a) {#1};\draw[->,thick,rotate=90] ($(a.center)+(20:.8em)$) arc (20:340:.8em);}} -\newcommand*\Rconf[1][R]{\tikz[baseline=(a.base),text height=1.5ex,text depth=.25ex]{\draw node(a) {#1};\draw[<-,thick,rotate=90] ($(a.center)+(20:.8em)$) arc (20:340:.8em);}} +\cs_new_nopar:Npn \Rcip { \textit { (R) } } +\cs_new_nopar:Npn \Scip { \textit { (S) } } +\cs_new_nopar:Npn \cip #1 { \textit { (#1) } } +\ExplSyntaxOff +\NewDocumentCommand\Sconf { O { S } }% + {% + \tikz[baseline=(a.base),text height=1.5ex,text depth=.25ex] + { + \node(a) {#1} ; + \draw[->,thick,rotate=90] ($(a.center)+(20:.8em)$) arc (20:340:.8em); + }% + } + +\NewDocumentCommand \Rconf { O { R } }% + {% + \tikz[baseline=(a.base),text height=1.5ex,text depth=.25ex] + { + \node(a) {#1} ; + \draw[<-,thick,rotate=90] ($(a.center)+(20:.8em)$) arc (20:340:.8em) ; + }% + }% +\ExplSyntaxOn % E(ntgegen)/Z(usammen) -\newcommand*\E{\textit{(E)}} -\newcommand*\Z{\textit{(Z)}} -\AtBeginDocument{\if@CM@bpchemloaded - \renewcommand*\cis{\textit{cis}\CM@xspace} - \renewcommand*\trans{\textit{trans}\CM@xspace} - \else - \newcommand*\cis{\textit{cis}\CM@xspace} - \newcommand*\trans{\textit{trans}\CM@xspace} -\fi} -\newcommand*\tert{\textit{tert}\CM@xspace} +\AtBeginDocument + { + \bool_if:NTF \l_chemmacros_EZ_cool_bool + { + \cs_new_nopar:Npn \Ent { \textit { (E) } } + \cs_new_nopar:Npn \Zus { \textit { (Z) } } + } + { + \cs_if_free:NTF \E + { \cs_new_nopar:Npn \E { \textit { (E) } } } + { \cs_set_nopar:Npn \E { \textit { (E) } } } + \cs_new_nopar:Npn \Z { \textit { (Z) } } + } + } + +\AtBeginDocument + { + \cs_if_free:NTF \cis + { + \cs_new_nopar:Npn \cis { \textit { cis } \chemmacros_xspace: } + } + { + \cs_set_nopar:Npn \cis { \textit { cis } \chemmacros_xspace: } + } + \cs_if_free:NTF \trans + { + \cs_new_nopar:Npn \trans { \textit { trans } \chemmacros_xspace: } + } + { + \cs_set_nopar:Npn \trans { \textit { trans } \chemmacros_xspace: } + } + } + +\cs_new_nopar:Npn \tert { \textit { tert } \chemmacros_xspace: } % Fischer -\newcommand*\Dfi{\textsc{d}} -\newcommand*\Lfi{\textsc{l}} +\cs_new_nopar:Npn \Dfi { \textsc { d } } +\cs_new_nopar:Npn \Lfi { \textsc { l } } % ortho/meta/para -\newcommand*\ortho{\textsl{o}} -\newcommand*\meta{\textsl{m}} -\newcommand*\para{\textsl{p}} +\cs_new_nopar:Npn \ortho { \textsl { o } } +\cs_new_nopar:Npn \meta { \textsl { m } } +\cs_new_nopar:Npn \para { \textsl { p } } % latin phrases -\AtBeginDocument{\if@CM@chemstyleloaded - \newcommand*\insitu{\latin{in situ}\CM@xspace} - \newcommand*\abinitio{\latin{ab initio}\CM@xspace} -\else - \newcommand*\insitu{\textit{in situ}\CM@xspace} - \newcommand*\abinitio{\textit{ab initio}\CM@xspace} -\fi} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - ions, molecules ------------------------------------------------------------------- % -% Proton, Hydroxide, Hydronium/Oxonium, water, nucleophile, electrophile -\newcommand*\Hpl{\CM@atom{H\pch}\CM@xspace} -\newcommand*\Hyd{\CM@atom{OH\mch}\CM@xspace} -\newcommand*\HtO{\CM@atom{H$_3$O\pch}\CM@xspace} -\newcommand*\water{\CM@atom{H$_2$O}\CM@xspace} -\newcommand*\Nu{\CM@atom{Nu\mch}\CM@xspace} -\newcommand*\El{\CM@atom{E\pch}\CM@xspace} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - acid/base ------------------------------------------------------------------------- % -\newcommand*\pH{\mbox{\textsl{p}H}\CM@xspace} -\newcommand*\pOH{\mbox{\textsl{p}OH}\CM@xspace} -\newcommand*\pKa[1][]{\mbox{\textsl{p}$K_\mathrm{\if@CM@german S\else A\fi#1}$}\CM@xspace} -\newcommand*\pKb[1][]{\mbox{\textsl{p}$K_\mathrm{B#1}$}\CM@xspace} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - substituents ---------------------------------------------------------------------- % +\AtBeginDocument + { + \bool_if:NTF \l_chemmacros_chemstyle_bool + { + \cs_new_nopar:Npn \insitu { \latin{in~situ} \chemmacros_xspace: } + \cs_new_nopar:Npn \abinitio { \latin{ab~initio} \chemmacros_xspace: } + } + { + \cs_new_nopar:Npn \insitu { \textit{in~situ} \chemmacros_xspace: } + \cs_new_nopar:Npn \abinitio { \textit{ab~initio} \chemmacros_xspace: } + } + } + +% --------------------------------------------------------------------------- % +% acid/base +\cs_new_nopar:Npn \pH + { \mbox { \textsl { p } H } \chemmacros_xspace: } +\cs_new_nopar:Npn \pOH + { \mbox { \textsl { p } OH } \chemmacros_xspace: } +\NewDocumentCommand \p { m } + { \mbox { \textsl { p } \ensuremath { #1 } } \chemmacros_xspace: } + +\char_set_catcode_math_subscript:N \@ +\NewDocumentCommand \pKa { o } + { + \mbox + { + \textsl { p } + \( + K @ \mathrm + { + \bool_if:NTF \l_chemmacros_german_bool + { S } + { A } + \IfNoValueF{ #1 } { #1 } + } + \) + } + \chemmacros_xspace: + } + +\NewDocumentCommand \pKb { o } + { + \mbox + { + \textsl { p } + \( + K @ \mathrm + { + B + \IfNoValueF{ #1 } { #1 } + } + \) + } + \chemmacros_xspace: + } +\char_set_catcode_letter:N \@ + +% --------------------------------------------------------------------------- % +% substituents % \R[]{} -\newcommand*\R[2][]{\CM@atom{R$_{\mathrm{#2}}^{\ifx#1+\CM@plus\else\ifx#1-\CM@minus\fi\fi}$}} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - units ----------------------------------------------------------------------------- % -\DeclareSIUnit{\atm}{atm} -\DeclareSIUnit{\atmosphere}{atm} -\DeclareSIUnit{\calory}{cal} -\DeclareSIUnit{\cal}{cal} -\AtBeginDocument{\if@CM@chemstyleloaded\else - \DeclareSIUnit{\cmc}{\cubic\centi\metre} - \DeclareSIUnit{\molar}{\mole\per\cubic\deci\metre} - \DeclareSIUnit{\Molar}{\textsc{m}} -\fi} -\DeclareSIUnit{\moLar}{\mole\per\liter} -\DeclareSIUnit{\MolMass}{\gram\per\mole} -\DeclareSIUnit{\normal}{\textsc{n}} -\DeclareSIUnit{\torr}{torr} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - reaction mechanisms --------------------------------------------------------------- % + +\char_set_catcode_math_subscript:N \@ +\NewDocumentCommand \R { o g } + { + \chemmacros_atom:n + { + R + $ + \IfNoValueF { #2 } { @ { \mathrm { #2 } } } + ^ { + \IfNoValueF { #1 } + { + \tl_if_eq:nnTF { #1 } { + } + { \chemmacros_plus: } + { + \tl_if_eq:nnT { #1 } { - } + { \chemmacros_minus: } + } + } + } + $ + } + } +\char_set_catcode_letter:N \@ + +% --------------------------------------------------------------------------- % +% units +\DeclareSIUnit { \atm } { atm } +\DeclareSIUnit { \atmosphere } { atm } +\DeclareSIUnit { \calory } { cal } +\DeclareSIUnit { \cal } { cal } +\AtBeginDocument + { + \bool_if:NF \l_chemmacros_chemstyle_bool + { + \DeclareSIUnit { \cmc } { \cubic\centi\metre } + \DeclareSIUnit { \molar } { \mole\per\cubic\deci\metre } + \DeclareSIUnit { \Molar } { \textsc{m} } + } + } +\DeclareSIUnit { \moLar } { \mole\per\liter } +\DeclareSIUnit { \MolMass } { \gram\per\mole } +\DeclareSIUnit { \normal } { \textsc{n} } +\DeclareSIUnit { \torr } { torr } + +% --------------------------------------------------------------------------- % +% reaction mechanisms % \mech[] % - substitutions: {}, 1, 2, se, 1e, 2e, ar % - eliminations: e, e1, e2, cb -\newcommand*\CM@Substitution[1][]{% - \CM@compareStr{#1}{se}{\def\CM@subst@mol{_\mathrm{E}}\let\CM@subst@ar\@empty}{% - \CM@compareStr{#1}{1e}{\def\CM@subst@mol{_\mathrm{E}1}\let\CM@subst@ar\@empty}{% - \CM@compareStr{#1}{2e}{\def\CM@subst@mol{_\mathrm{E}2}\let\CM@subst@ar\@empty}{% - \CM@compareStr{#1}{ar}{\def\CM@subst@mol{_\mathrm{E}}\def\CM@subst@ar{Ar-}}{% - \def\CM@subst@mol{_\mathrm{N}#1}\let\CM@subst@ar\@empty}}}}% - \CM@atom{\mbox{\CM@subst@ar S}$\CM@subst@mol$}\CM@xspace% -} -\newcommand*\CM@Elimination[1][]{% - \CM@compareStr{#1}{cb}{\def\CM@elim@mol{1_\mathrm{cb}}}{\def\CM@elim@mol{#1}}% - \CM@atom{E$\CM@elim@mol$}\CM@xspace% -} -\newcommand*\mech[1][]{% - \CM@compareStr{#1}{se}{\def\CM@mech@type{S}\def\CM@mech@mol{_\mathrm{E}}\let\CM@mech@ar\@empty}{% - \CM@compareStr{#1}{1e}{\def\CM@mech@type{S}\def\CM@mech@mol{_\mathrm{E}1}\let\CM@mech@ar\@empty}{% - \CM@compareStr{#1}{2e}{\def\CM@mech@type{S}\def\CM@mech@mol{_\mathrm{E}2}\let\CM@mech@ar\@empty}{% - \CM@compareStr{#1}{ar}{\def\CM@mech@type{S}\def\CM@mech@mol{_\mathrm{E}}\def\CM@mech@ar{Ar-}}{% - \CM@compareStr{#1}{e}{\def\CM@mech@type{E}\def\CM@mech@mol{}\let\CM@mech@ar\@empty}{% - \CM@compareStr{#1}{e1}{\def\CM@mech@type{E}\def\CM@mech@mol{1}\let\CM@mech@ar\@empty}{% - \CM@compareStr{#1}{e2}{\def\CM@mech@type{E}\def\CM@mech@mol{2}\let\CM@mech@ar\@empty}{% - \CM@compareStr{#1}{cb}{\def\CM@mech@type{E}\def\CM@mech@mol{1_\mathrm{cb}}\let\CM@mech@ar\@empty}{% - \def\CM@mech@type{S}\def\CM@mech@mol{_\mathrm{N}#1}\let\CM@mech@ar\@empty}}}}}}}}% - \CM@atom{\mbox{\CM@mech@ar\CM@mech@type}$\CM@mech@mol$}\CM@xspace% -} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - oxidation numbers ----------------------------------------------------------------- % +\tl_new:N \l_chemmacros_mech_type_tl +\tl_new:N \l_chemmacros_mech_mol_tl +\tl_new:N \l_chemmacros_mech_ar_tl + +\cs_new_nopar:Npn \chemmacros_set_mech:nnn #1#2#3 + { + \tl_set:Nn \l_chemmacros_mech_type_tl { #1 } + \tl_set:Nn \l_chemmacros_mech_mol_tl { #2 } + \tl_set:Nn \l_chemmacros_mech_ar_tl { #3 } + } + +\char_set_catcode_math_subscript:N \@ +\keys_define:nn { chemmacros / mech } + { + type .choice: , + type / .code:n = + { \chemmacros_set_mech:nnn { S } { $ @ \text {N} $ } {} } , + type / 1 .code:n = + { \chemmacros_set_mech:nnn { S } { $ @ \text {N} $ 1 } {} } , + type / 2 .code:n = + { \chemmacros_set_mech:nnn { S } { $ @ \text {N} $ 2 } {} } , + type / se .code:n = + { \chemmacros_set_mech:nnn { S } { $ @ \text {E} $ } {} } , + type / 1e .code:n = + { \chemmacros_set_mech:nnn { S } { $ @ \text {E} $ 1 } {} } , + type / 2e .code:n = + { \chemmacros_set_mech:nnn { S } { $ @ \text {E} $ 2 } {} } , + type / ar .code:n = + { \chemmacros_set_mech:nnn { S } { $ @ \text {E} $ } { Ar - } } , + type / e .code:n = + { \chemmacros_set_mech:nnn { E } {} {} } , + type / e1 .code:n = + { \chemmacros_set_mech:nnn { E } { 1 } {} } , + type / e2 .code:n = + { \chemmacros_set_mech:nnn { E } { 2 } {} } , + type / cb .code:n = + { \chemmacros_set_mech:nnn { E } { 1 $ @ \text {cb} $ } {} } , + type .default:n = + } + +\NewDocumentCommand \mech { o } + { + \IfNoValueTF { #1 } + { \keys_set:nn { chemmacros / mech } { type } } + { \keys_set:nn { chemmacros / mech } { type = #1 } } + \mbox + { + \tl_use:N \l_chemmacros_mech_ar_tl + \tl_use:N \l_chemmacros_mech_type_tl + \tl_use:N \l_chemmacros_mech_mol_tl + } + \chemmacros_xspace: + } +\char_set_catcode_letter:N \@ + +% --------------------------------------------------------------------------- % +% oxidation numbers % \ox{,} -\newcommand*\CM@ox@sign[1]{% - \ifx -#1{$-$}% TODO: bad method here, do you see what happens if #1 is more than 1 token??? Use \@car to avoid the bug! - \else \ifx +#1{$+$}% TODO: bad method here, do you see what happens if #1 is more than 1 token??? Use \@car to avoid the bug! - \else #1% - \fi\fi% -} -% I don't quite understand the problem: that macro is used ONLY in \ox (lines 286-291) where no other input than arabic or (more often) roman numbers with a sign make any sense at all (chemically speaking*). In these cases everything happens as it is supposed to: the signs are changed into the math ones but the letters/numbers stay as they are. I must confess I didn't test senseless cases... -%* And I would like to think that users who use a macro for oxidation numbers know what oxidation numbers are -\DeclareRobustCommand\ox[1]{% needs to be robust in order to be used in mhchem's \ce macro - \CM@splitting{#1}{2}% - \CM@compareCs{CM@arg@i}{@empty}{\PackageError{chemmacros}{\string\ox: oxidation number missing}{}}{}% - \CM@compareCs{CM@arg@ii}{@empty}{\PackageError{chemmacros}{\string\ox: atom missing}{}}{}% - \ensuremath{\overset{\mbox{\tiny\expandafter\CM@ox@sign\CM@arg@i}}{\expandafter\CM@atom\expandafter{\CM@arg@ii}}}% -} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - oxidation arrows ------------------------------------------------------------------ % +\bool_new:N \l_chemmacros_ox_sign_bool +\bool_new:N \l_chemmacros_ox_integer_bool + +\bool_new:N \l_chemmacros_ox_explicit_sign_bool +\bool_set_false:N \l_chemmacros_ox_explicit_sign_bool + +\bool_new:N \l_chemmacros_ox_format_roman_bool +\bool_set_true:N \l_chemmacros_ox_format_roman_bool + +\bool_new:N \l_chemmacros_ox_decimal_marker_comma_bool +\bool_set_false:N \l_chemmacros_ox_decimal_marker_comma_bool + +\bool_new:N \l_chemmacros_ox_parse_bool +\bool_set_true:N \l_chemmacros_ox_parse_bool + +\int_new:N \l_chemmacros_ox_number_int +\fp_new:N \l_chemmacros_ox_number_fp + +\bool_new:N \l_chemmacros_ox_side_bool +\bool_set_false:N \l_chemmacros_ox_side_bool +\bool_new:N \l_chemmacros_ox_super_bool +\bool_set_false:N \l_chemmacros_ox_super_bool +\bool_new:N \l_chemmacros_ox_top_bool +\bool_set_true:N \l_chemmacros_ox_top_bool + +\cs_new_nopar:Npn \chemmacros_ox_process_number:n #1 + { + \bool_if:NTF \l_chemmacros_ox_parse_bool + { + \tl_if_in:nnTF { #1 } { / } + { \chemmacros_ox_fraction:n #1 } + { + \chemmacros_ox_sign:n { #1 } + \chemmacros_ox_value:n { #1 } + } + } + { #1 } + } + +\DeclareInstance { xfrac } { chemmacros-ox-frac } { text } + { + scale-factor = 1.5 , + denominator-bot-sep = -.5ex , + numerator-top-sep = -.3ex , + slash-left-kern = -.05em , + slash-right-kern = -.05em , + slash-symbol-font = ptm + } + +\cs_new_nopar:Npn \chemmacros_ox_fraction:n #1/#2 + { + \bool_set_false:N \l_chemmacros_ox_format_roman_bool + \chemmacros_ox_sign:n { #1 } + \bool_if:NTF \l_chemmacros_ox_side_bool + { \sfrac { \chemmacros_ox_value:n { #1 } } { #2 } } + { \sfrac [ chemmacros-ox-frac ] { \chemmacros_ox_value:n { #1 } } { #2 } } + } + +\cs_new_nopar:Npn \chemmacros_ox_sign:n #1 + { + \fp_compare:nNnT { #1 } > { 0 } + { \bool_if:NT \l_chemmacros_ox_explicit_sign_bool { $+$ } } + \fp_compare:nNnT { #1 } = { 0 } + { \bool_if:NT \l_chemmacros_ox_explicit_sign_bool { $\pm$ } } + \fp_compare:nNnT { #1 } < { 0 } + { $-$ } + } + +\cs_new_nopar:Npn \chemmacros_ox_value:n #1 + { + \fp_set:Nn \l_chemmacros_ox_number_fp { #1 } + \fp_abs:N \l_chemmacros_ox_number_fp + \chemmacros_ox_is_integer:N \l_chemmacros_ox_number_fp + \bool_if:NTF \l_chemmacros_ox_format_roman_bool + { + \chemmacros_fp_to_Roman:N \l_chemmacros_ox_number_fp + } + { + \bool_if:NTF \l_chemmacros_ox_integer_bool + { \chemmacros_fp_to_arabic:N \l_chemmacros_ox_number_fp } + { \chemmacros_fp_show:N \l_chemmacros_ox_number_fp } + } + } + +\cs_new_nopar:Npn \chemmacros_ox_is_integer:n #1 + { + \fp_set:Nn \l_tmpa_tl { #1 } + \fp_add:Nn \l_tmpa_tl { 1 } + \fp_round_places:Nn \l_tmpa_tl { 0 } + \fp_sub:Nn \l_tmpa_tl { 1 } + \fp_compare:nNnTF { \l_tmpa_tl } = { #1 } + { \bool_set_true:N \l_chemmacros_ox_integer_bool } + { + \bool_set_false:N \l_chemmacros_ox_integer_bool + \bool_set_false:N \l_chemmacros_ox_format_roman_bool + } + } +\cs_generate_variant:Nn \chemmacros_ox_is_integer:n { N } + +\cs_new_nopar:Npn \chemmacros_fp_to_Roman:n #1 + { + \group_begin: + \fp_set:Nn \l_tmpa_tl { #1 } + \fp_round_places:Nn \l_tmpa_tl { 0 } + \int_set:Nn \l_tmpa_int { \fp_to_tl:N \l_tmpa_tl } + \int_compare:nTF { \l_tmpa_int = 0 } + { 0 } + { \int_to_Roman:n { \int_use:N \l_tmpa_int } } + \group_end: + } +\cs_generate_variant:Nn \chemmacros_fp_to_Roman:n { N } + +\cs_new_nopar:Npn \chemmacros_fp_to_arabic:n #1 + { + \group_begin: + \fp_set:Nn \l_tmpa_tl { #1 } + \fp_to_tl:N \l_tmpa_tl + \group_end: + } +\cs_generate_variant:Nn \chemmacros_fp_to_arabic:n { N } + +\cs_new_nopar:Npn \chemmacros_fp_show:n #1 + { + \group_begin: + \fp_set:Nn \l_tmpa_tl { #1 } + \bool_if:NTF \l_chemmacros_ox_decimal_marker_comma_bool + { + \tl_set:Nx \l_tmpb_tl { \fp_to_tl:N \l_tmpa_tl } + \tl_replace_once:Nnn \l_tmpb_tl { . } { {,} } + \tl_use:N \l_tmpb_tl + } + { \fp_to_tl:N \l_tmpa_tl } + \group_end: + } +\cs_generate_variant:Nn \chemmacros_fp_show:n { N } + +\cs_new_nopar:Npn \chemmacros_ox:nn #1#2 + { + \tl_if_blank:nT { #1 } + { + \msg_error:nnx { chemmacros } { ox } { oxidation~number~missing } + } + \tl_if_blank:nT { #2 } + { + \msg_error:nnx { chemmacros } { ox } { atom~missing } + } + \ensuremath + { + \bool_if:NT \l_chemmacros_ox_super_bool + { + \chemmacros_atom:n + { #2 ^ { \text { \tiny \chemmacros_ox_process_number:n { #1 } } } } + } + \bool_if:NT \l_chemmacros_ox_side_bool + { + \chemmacros_atom:n { #2 ( \text { \chemmacros_ox_process_number:n { #1 } } ) } + } + \bool_if:NT \l_chemmacros_ox_top_bool + { + \overset + { \mbox { \tiny \chemmacros_ox_process_number:n { #1 } } } + { \chemmacros_atom:n { #2 } } + } + } + } + +\cs_new_nopar:Npn \chemmacros_ox_pos_top: + { + \bool_set_true:N \l_chemmacros_ox_top_bool + \bool_set_false:N \l_chemmacros_ox_super_bool + \bool_set_false:N \l_chemmacros_ox_side_bool + } + +\cs_new_nopar:Npn \chemmacros_ox_pos_super: + { + \bool_set_false:N \l_chemmacros_ox_top_bool + \bool_set_true:N \l_chemmacros_ox_super_bool + \bool_set_false:N \l_chemmacros_ox_side_bool + } + +\cs_new_nopar:Npn \chemmacros_ox_pos_side: + { + \bool_set_false:N \l_chemmacros_ox_top_bool + \bool_set_false:N \l_chemmacros_ox_super_bool + \bool_set_true:N \l_chemmacros_ox_side_bool + } + +\keys_define:nn { chemmacros / ox } + { + pos .choice: , + pos / top .code:n = \chemmacros_ox_pos_top: , + pos / super .code:n = \chemmacros_ox_pos_super: , + pos / side .code:n = \chemmacros_ox_pos_side: , + roman .bool_set:N = \l_chemmacros_ox_format_roman_bool , + roman .default:n = true , + parse .bool_set:N = \l_chemmacros_ox_parse_bool , + parse .default:n = true , + explicit-sign .bool_set:N = \l_chemmacros_ox_explicit_sign_bool , + explicit-sign .default:n = true , + decimal-marker .choice: , + decimal-marker / comma .code:n = + { \bool_set_true:N \l_chemmacros_ox_decimal_marker_comma_bool } , + decimal-marker / point .code:n = + { \bool_set_false:N \l_chemmacros_ox_decimal_marker_comma_bool } + } + +% \ox[]{,} +% \ox*[]{,} => always number on the side +\NewDocumentCommand \ox { s o > { \SplitArgument { 1 } { , } } m } + { + \group_begin: + \IfBooleanT { #1 } { \chemmacros_ox_pos_super: } + \bool_if:NTF \l_chemmacros_version_one_bool + { \keys_set:nn { chemmacros / ox } { parse = false } } + { \IfNoValueF { #2 } { \keys_set:nn { chemmacros / ox } { #2 } } } + \chemmacros_ox:nn #3 + \group_end: + } + +% --------------------------------------------------------------------------- % +% - oxidation arrows +\tl_new:N \l_chemmacros_redox_begin_tl +\tl_new:N \l_chemmacros_redox_end_tl + +\tl_new:N \l_chemmacros_redox_tikz_tl + +\fp_new:N \l_chemmacros_redox_shift_fp +\tl_new:N \l_chemmacros_redox_shift_tl + +\tl_new:N \l_chemmacros_redox_anchor_tl + +\tl_new:N \l_chemmacros_redox_side_tl + +\dim_new:N \l_chemmacros_redox_sep_dim +\dim_new:N \l_chemmacros_redox_sep_default_dim +\dim_set:Nn \l_chemmacros_redox_sep_default_dim { .2em } + +\dim_new:N \l_chemmacros_redox_dist_dim +\dim_set:Nn \l_chemmacros_redox_dist_dim {.6em} + % place and name nodes: % \OX{,} -\DeclareRobustCommand*\OX[1]{% needs to be robust in order to be used in mhchem's \ce macro - \CM@splitting{#1}{2}% - \CM@compareCs{CM@arg@i}{@empty}{\PackageError{chemmacros}{\string\OX: node name missing}{}}{}% - \CM@compareCs{CM@arg@i}{@empty}{\PackageError{chemmacros}{\string\OX: atom missing}{}}{}% - \tikz[baseline=(\CM@arg@i.base),remember picture]{\node[inner sep=0](\CM@arg@i){\expandafter\CM@atom\expandafter{\CM@arg@ii}};}% -} - -% connect nodes with "redox"-line -% \redox(,)[][]{} -\newcommand*\CM@redox@dist{.6em} -\newcommand*\setredoxdist[1]{\ifx\@empty#1\@empty\renewcommand*\CM@redox@dist{.6em}\else\renewcommand*\CM@redox@dist{#1}\fi} -\NewDocumentCommand\redox{d()oom}{% - \IfNoValueTF{#1}{% - \PackageError{chemmacros}{\string\redox: You need to specify coordinates}{} - }{% - \CM@splitting{#1}{2}% - \let\CM@redox@begin\CM@arg@i% - \let\CM@redox@end\CM@arg@ii% - } - \IfNoValueTF{#2}{\def\CM@redox@tikz{}}{\def\CM@redox@tikz{#2}} - \IfNoValueTF{#3}{% - \def\CM@redox@shift{1}% - \def\CM@redox@anchor{above}% - \def\CM@redox@side{north}% - \def\CM@redox@sep{.2em}% - }{% - \pgfmathparse{#3<0}% TODO : You should learn to test if an integer is less than 0: \ifnum#1<\z@ -% #3 is not necessarily an integer. It is more likely real; if you know a way to test if '-.5' is less than 0 that's easier than \pgfmathparse, please let me know. - \ifnum\pgfmathresult=1 % - \def\CM@redox@anchor{below}\def\CM@redox@side{south}\def\CM@redox@sep{-.2em}% - \else% - \def\CM@redox@anchor{above}\def\CM@redox@side{north}\def\CM@redox@sep{.2em}% - \fi% - \def\CM@redox@shift{#3}% - } - \tikz[remember picture,overlay]{\expandafter\draw\expandafter[\CM@redox@tikz] ($(\CM@redox@begin.\CM@redox@side)+(0,\CM@redox@sep)$) -- ++(0,\CM@redox@shift*\CM@redox@dist) -| node[pos=.25,\CM@redox@anchor]{#4} ($(\CM@redox@end.\CM@redox@side)+(0,\CM@redox@sep)$);}% -} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - spectroscopy ---------------------------------------------------------------------- % -% \NMR(,)[,]{} ALL arguments are optional -% \NMR* same but without ": $\delta$" at end -\AtBeginDocument{ - \NewDocumentCommand\NMR{sG{1,H}d()o}{% - \IfBooleanTF{#1}{\let\CM@nmr@delta\@empty}{\ifmmode\def\CM@nmr@delta{\mbox{: }\delta}\else\def\CM@nmr@delta{: $\delta$}\fi}% - \CM@splitting{#2}{2}% - \let\CM@nmr@istp\CM@arg@i - \let\CM@nmr@elem\CM@arg@ii - \IfNoValueTF{#3}{% - \let\CM@nmr@spec\@empty - \let\CM@nmr@freq\@empty - }{% - \let\CM@nmr@spec\relax - \CM@splitting{#3}{2}% - \CM@compareCs{CM@arg@ii}{@empty}{\def\CM@nmr@unit{\mega\hertz}}{\def\CM@nmr@unit{\CM@arg@ii}}% - \def\CM@nmr@freq{\expandafter\SI\expandafter{\CM@arg@i}{\CM@nmr@unit}}% - }% - \IfNoValueTF{#4}{% - \let\CM@nmr@lm\@empty - \let\CM@nmr@comma\@empty - }{% - \let\CM@nmr@spec\relax - \def\CM@nmr@lm{\CM@atom{#4}}% - \CM@compareCs{CM@nmr@freq}{@empty}{\let\CM@nmr@comma\@empty}{\def\CM@nmr@comma{,\ifmmode\medspace\else\hspace{\smallskipamount}\fi}}% - }% - \CM@compareCs{CM@nmr@spec}{@empty}{}{% - \def\CM@nmr@spec{\hspace{\smallskipamount}(\CM@nmr@freq\CM@nmr@comma\CM@nmr@lm)}% - }% - \if@CM@bpchem - \ifmmode - \expandafter\text\expandafter{\IUPAC{\^{\CM@nmr@istp}\CM@nmr@elem-NMR}\CM@nmr@spec}\CM@nmr@delta - \else - \IUPAC{\^{\CM@nmr@istp}\CM@nmr@elem-NMR}\CM@nmr@spec\CM@nmr@delta\CM@xspace - \fi - \else - \ifmmode - ^{\CM@nmr@istp}\expandafter\CM@atom\expandafter{\CM@nmr@elem}\mbox{-}\text{NMR}\CM@nmr@spec\CM@nmr@delta - \else - $^{\CM@nmr@istp}$\expandafter\CM@atom\expandafter{\CM@nmr@elem}-NMR\CM@nmr@spec\CM@nmr@delta\CM@xspace - \fi - \fi - } -} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - for use with mhchem --------------------------------------------------------------- % -\AtBeginDocument{\if@CM@mhchemloaded +\NewDocumentCommand \OX { > { \SplitArgument { 1 } { , } } m } + { \chemmacros_redox_partner:nn #1 } + +\cs_new_nopar:Npn \chemmacros_redox_partner:nn #1#2 + { + \tl_if_blank:nT { #1 } + { + \msg_error:nnx { chemmacros } { OX } { node~name~missing } + } + \tl_if_blank:nT { #2 } + { + \msg_error:nnx { chemmacros } { OX } { atom~missing } + } + \tikz[baseline=(#1.base),remember~picture] + { + \node [inner~sep=0] (#1) { \chemmacros_atom:n {#2} } ; + } + } + +\cs_new_nopar:Npn \chemmacros_redox_coordinates:nn #1#2 + { + \tl_set:Nn \l_chemmacros_redox_begin_tl { #1 } + \tl_set:Nn \l_chemmacros_redox_end_tl { #2 } + } + +\NewDocumentCommand \redox { > { \SplitArgument { 1 } { , } } d() o o m } + { + \IfNoValueT { #1 } + { + \msg_error:nnx { chemmacros } { redox } { You~need~to~specify~coordinates } + } + \tl_clear:N \l_chemmacros_redox_begin_tl + \tl_clear:N \l_chemmacros_redox_end_tl + \tl_clear:N \l_chemmacros_redox_tikz_tl + \chemmacros_redox_coordinates:nn #1 + \IfNoValueF { #2 } + { \tl_set:Nn \l_chemmacros_redox_tikz_tl { #2 } } + \IfNoValueTF { #3 } + { + \fp_set:Nn \l_chemmacros_redox_shift_fp { 1 } + \tl_set:Nn \l_chemmacros_redox_anchor_tl { above } + \tl_set:Nn \l_chemmacros_redox_side_tl { north } + \dim_set_eq:NN \l_chemmacros_redox_sep_dim \l_chemmacros_redox_sep_default_dim + } + { + \fp_compare:nNnTF { #3 } < { 0 } + { + \tl_set:Nn \l_chemmacros_redox_anchor_tl { below } + \tl_set:Nn \l_chemmacros_redox_side_tl { south } + \exp_args:NNo \dim_set:Nn \l_chemmacros_redox_sep_dim { - \l_chemmacros_redox_sep_default_dim } + } + { + \tl_set:Nn \l_chemmacros_redox_anchor_tl { above } + \tl_set:Nn \l_chemmacros_redox_side_tl { north } + \dim_set_eq:NN \l_chemmacros_redox_sep_dim \l_chemmacros_redox_sep_default_dim + } + \fp_set:Nn \l_chemmacros_redox_shift_fp { #3 } + } + \tl_set:Nn \l_chemmacros_redox_shift_tl + { \fp_to_tl:N \l_chemmacros_redox_shift_fp } + \tikz[remember~picture,overlay] + { + \chemmacros_tikz_draw:f { \tl_use:N \l_chemmacros_redox_tikz_tl } + ($(\l_chemmacros_redox_begin_tl . \l_chemmacros_redox_side_tl)+(0,\l_chemmacros_redox_sep_dim)$) + -- + ++(0,\l_chemmacros_redox_shift_tl * \l_chemmacros_redox_dist_dim) -| + node [pos=.25,\l_chemmacros_redox_anchor_tl] { #4 } + ($(\l_chemmacros_redox_end_tl . \l_chemmacros_redox_side_tl)+(0,\l_chemmacros_redox_sep_dim)$) ; + } + } + +% redox-keys +\keys_define:nn { chemmacros / redox } + { + dist .dim_set:N = \l_chemmacros_redox_dist_dim , + dist .default:n = { .6em } , + sep .dim_set:N = \l_chemmacros_redox_sep_default_dim , + sep .default:n = { .2em } + } + +\bool_if:NT \l_chemmacros_version_one_bool + { + \NewDocumentCommand \setredoxdist { m } + { + \tl_if_blank:nTF { #1 } + { \dim_set:Nn \l_chemmacros_redox_dist_dim { .6em } } + { \dim_set:Nn \l_chemmacros_redox_dist_dim { #1 } } + } + } + +% --------------------------------------------------------------------------- % +% spectroscopy +\tl_new:N \l_chemmacros_nmr_isotope_tl +\tl_new:N \l_chemmacros_nmr_isotope_default_tl +\tl_set:Nn \l_chemmacros_nmr_isotope_default_tl { 1 } + +\tl_new:N \l_chemmacros_nmr_element_tl +\tl_new:N \l_chemmacros_nmr_element_default_tl +\tl_set:Nn \l_chemmacros_nmr_element_default_tl { H } + +\bool_new:N \l_chemmacros_nmr_frequency_bool +\bool_new:N \l_chemmacros_nmr_solvent_bool +\bool_new:N \l_chemmacros_nmr_delimiters_bool +\bool_new:N \l_chemmacros_nmr_comma_bool + +\tl_new:N \l_chemmacros_nmr_unit_tl +\tl_set:Nn \l_chemmacros_nmr_unit_tl { \mega\hertz } + +\cs_new_nopar:Npn \chemmacros_nmr_nucleus:n #1,#2 \q_stop + { + \tl_set:Nn \l_chemmacros_nmr_isotope_tl { #1 } + \tl_set:Nn \l_chemmacros_nmr_element_tl { #2 } + } + +\cs_new:Npn \chemmacros_nmr_default_nucleus:n #1,#2 \q_stop + { + \tl_set:Nn \l_chemmacros_nmr_isotope_default_tl { #1 } + \tl_set:Nn \l_chemmacros_nmr_element_default_tl { #2 } + } + +\cs_new_nopar:Npn \chemmacros_nmr_base:nn #1#2 + { + \bool_if:NTF \l_chemmacros_bpchem_bool + { \IUPAC { \^ { #1 } #2 - NMR } } + { $ ^ { #1 } $ #2 - NMR } + } + +\cs_new_nopar:Npn \chemmacros_nmr_frequency:n #1 + { + \tl_if_in:nnTF { #1 } { , } + { \chemmacros_nmr_frequency_aux_i:n #1 \q_stop } + { \chemmacros_nmr_frequency_aux_ii:n { #1 } } + } +\cs_new_nopar:Npn \chemmacros_nmr_frequency_aux_i:n #1,#2 \q_stop + { \SI { #1 } { #2 } } +\cs_new_nopar:Npn \chemmacros_nmr_frequency_aux_ii:n #1 + { \SI { #1 } { \tl_use:N \l_chemmacros_nmr_unit_tl } } + +\keys_define:nn { chemmacros / nmr } + { + unit .tl_set:N = \l_chemmacros_nmr_unit_tl , + unit .default:n = \mega\hertz , + nucleus .code:n = { \chemmacros_nmr_default_nucleus:n #1 \q_stop } , + nucleus .default:n = { 1,H } + } + +\AtBeginDocument + { + % \NMR{,}(,)[] ALL arguments are optional + % \NMR* same but without ": $\delta$" at end + \NewDocumentCommand \NMR { s g d() o } + { + \group_begin: + \bool_set_false:N \l_chemmacros_nmr_frequency_bool + \bool_set_false:N \l_chemmacros_nmr_solvent_bool + \IfNoValueF { #3 } + { \bool_set_true:N \l_chemmacros_nmr_frequency_bool } + \IfNoValueF { #4 } + { \bool_set_true:N \l_chemmacros_nmr_solvent_bool } + \bool_if:nT + { + \l_chemmacros_nmr_frequency_bool + || + \l_chemmacros_nmr_solvent_bool + } + { \bool_set_true:N \l_chemmacros_nmr_delimiters_bool } + \bool_if:nT + { + \l_chemmacros_nmr_frequency_bool + && + \l_chemmacros_nmr_solvent_bool + } + { \bool_set_true:N \l_chemmacros_nmr_comma_bool } + \IfNoValueTF { #2 } + { + \chemmacros_nmr_nucleus:n + \l_chemmacros_nmr_isotope_default_tl , + \l_chemmacros_nmr_element_default_tl \q_stop + } + { \chemmacros_nmr_nucleus:n #2 \q_stop } + \mode_if_math:TF + { + \text + { + \chemmacros_nmr_base:nn + { \tl_use:N \l_chemmacros_nmr_isotope_tl } + { \tl_use:N \l_chemmacros_nmr_element_tl } + \bool_if:NT \l_chemmacros_nmr_delimiters_bool + { ~ ( } + \bool_if:NT \l_chemmacros_nmr_frequency_bool + { \chemmacros_nmr_frequency:n { #3 } } + \bool_if:NT \l_chemmacros_nmr_comma_bool + { , ~ } + \bool_if:NT \l_chemmacros_nmr_solvent_bool + { \chemmacros_atom:n { #4 } } + \bool_if:NT \l_chemmacros_nmr_delimiters_bool + { ) } + \IfBooleanF { #1 } { : ~ } + } + \IfBooleanF { #1 } { \delta } + } + { + \chemmacros_nmr_base:nn + { \tl_use:N \l_chemmacros_nmr_isotope_tl } + { \tl_use:N \l_chemmacros_nmr_element_tl } + \bool_if:NT \l_chemmacros_nmr_delimiters_bool + { ~ ( } + \bool_if:NT \l_chemmacros_nmr_frequency_bool + { \chemmacros_nmr_frequency:n { #3 } } + \bool_if:NT \l_chemmacros_nmr_comma_bool + { , ~ } + \bool_if:NT \l_chemmacros_nmr_solvent_bool + { \chemmacros_atom:n { #4 } } + \bool_if:NT \l_chemmacros_nmr_delimiters_bool + { ) } + \IfBooleanF { #1 } + { : ~ $ \delta $ } + \bool_if:NF \l_chemmacros_nmr_comma_bool + { \IfBooleanF { #1 } { \chemmacros_xspace: } } + } + \group_end: + } + } + +% --------------------------------------------------------------------------- % % placing text below atom/molecule - \newcommand*\CM@mhName@textattr@default{\centering\tiny}% -% \setmhName{} - \newcommand*\setmhName[1]{% - \ifx\@empty#1\@empty - \renewcommand*\CM@mhName@textattr@default{\centering\tiny}% - \else - \renewcommand*\CM@mhName@textattr@default{#1}% - \fi - } -% \mhName[][]{}{} - \newlength{\CM@mhName@boxlength}% - \NewDocumentCommand\mhName{oomm}{% - \IfNoValueTF{#1}{% - \settowidth{\CM@mhName@boxlength}{#3}% - }{% - \ifx\@empty#1\@empty - \settowidth{\CM@mhName@boxlength}{#3}% - \else - \setlength{\CM@mhName@boxlength}{#1}% - \fi - }% - \IfNoValueTF{#2}{% - \let\CM@mhName@textattr\CM@mhName@textattr@default - }{% - \def\CM@mhName@textattr{#2} - } - \def\CM@mhName@formula{#3} - \ensuremath{\underset{\parbox{\CM@mhName@boxlength}{\CM@mhName@textattr#4}}{\expandafter\ce\expandafter{\CM@mhName@formula}}}% +\cs_new_nopar:Npn \dim_to_width:nn #1#2 + { \settowidth { #1 } { #2 } } +\cs_generate_variant:Nn \dim_to_width:nn { Nn } + +\bool_new:N \l_chemmacros_mhname_width_bool +\bool_set_false:N \l_chemmacros_mhname_width_bool +\dim_new:N \l_chemmacros_mhname_width_dim + +\tl_new:N \l_chemmacros_mhname_align_tl +\tl_set:Nn \l_chemmacros_mhname_align_tl { \centering } + +\tl_new:N \l_chemmacros_mhname_fontattr_tl +\tl_new:N \l_chemmacros_mhname_fontsize_tl +\tl_set:Nn \l_chemmacros_mhname_fontsize_tl { \tiny } + +\keys_define:nn { chemmacros / mhName } + { + align .tl_set:N = \l_chemmacros_mhname_align_tl , + fontattr .tl_set:N = \l_chemmacros_mhname_fontattr_tl , + fontsize .tl_set:N = \l_chemmacros_mhname_fontsize_tl , + width .code:n = + { + \tl_if_eq:nnTF { #1 } { auto } + { \bool_set_false:N \l_chemmacros_mhname_width_bool } + { + \bool_set_true:N \l_chemmacros_mhname_width_bool + \dim_set:Nn \l_chemmacros_mhname_width_dim { #1 } + } + } + } + +% \mhName[]{}{} +\bool_if:NF \l_chemmacros_version_one_bool + { + \NewDocumentCommand \mhName { o m m } + { + \group_begin: + \IfNoValueF { #1 } { \keys_set:nn { chemmacros / mhName } { #1 } } + \ensuremath + { + \underset + { + \bool_if:NF \l_chemmacros_mhname_width_bool + { \dim_to_width:Nn \l_chemmacros_mhname_width_dim { #2 } } + \parbox + { \dim_use:N \l_chemmacros_mhname_width_dim } + { + \tl_use:N \l_chemmacros_mhname_align_tl + \tl_use:N \l_chemmacros_mhname_fontattr_tl + \tl_use:N \l_chemmacros_mhname_fontsize_tl + #3 + } + } + { \chemmacros_atom:n { #2 } } + } + \group_end: + } } + +% --------------------------------------------------------------------------- % +% - phases +\char_set_catcode_math_subscript:N \@ +\cs_new_nopar:Npn \sld + { + \peek_meaning:NTF [ + { \chemmacros_sld_aux_i: } + { \chemmacros_sld_aux_ii: } + } + +\cs_new_nopar:Npn \chemmacros_sld_aux_i: [#1] + { \ensuremath { @ \mathrm { ( #1 ) } } } + +\cs_new_nopar:Npn \chemmacros_sld_aux_ii: + { + \ensuremath { @ \mathrm { + ( + \bool_if:NTF \l_chemmacros_german_bool + { f } + { s } + ) + } } + } + +\cs_new_nopar:Npn \lqd + { + \peek_meaning:NTF [ + { \chemmacros_lqd_aux_i: } + { \chemmacros_lqd_aux_ii: } + } + +\cs_new_nopar:Npn \chemmacros_lqd_aux_i: [#1] + { \ensuremath { @ \mathrm { ( #1 ) } } } + +\cs_new_nopar:Npn \chemmacros_lqd_aux_ii: + { + \ensuremath { @ \mathrm { + ( + \bool_if:NTF \l_chemmacros_german_bool + { f\/l } + { l } + ) + } } + } + +\bool_if:NT \l_chemmacros_version_one_bool + { + \cs_new_eq:NN \solid \sld + \cs_new_eq:NN \liquid \lqd + } + +\cs_new_nopar:Npn \gas + { \ensuremath { @ \mathrm { (g) } } } + +\cs_new_nopar:Npn \aq + { \ensuremath { @ \mathrm { (aq) } } } +\char_set_catcode_letter:N \@ + +% --------------------------------------------------------------------------- % +\bool_if:NTF \l_chemmacros_version_one_bool + { \newtagform { CMreaction } { \{ } { \} } } + { \newtagform { reaction } { \{ } { \} } } +\newcounter { chemmacros_save_reaction } +\newcounter { reaction } +\cs_new_nopar:Npn \chemmacros_begin_reaction: + { + \bool_if:NT \l_chemmacros_hyperref_bool % create individual names for hyperref + { \cs_set_nopar:Npn \theHequation { R . \theHsection . \arabic { reaction } } } + \bool_if:NT \l_chemmacros_varioref_bool % enable labelformat reaction + { \cs_set_eq:NN \p@equation \p@reaction } + \setcounter { chemmacros_save_reaction } { \value { equation } } + \setcounter { equation } { \value { reaction } } + \bool_if:NTF \l_chemmacros_version_one_bool + { \usetagform { CMreaction } } + { \usetagform { reaction } } + } +\cs_new_nopar:Npn \chemmacros_end_reaction: + { + \setcounter { reaction } { \value { equation } } + \setcounter { equation } { \value { chemmacros_save_reaction } } + } + +% --------------------------------------------------------------------------- % % reaction environments for mhchem - \RequirePackage{mathtools,environ} - \newtagform{CMreaction}{\{}{\}} - \newcounter{save@reaction}% - \newcounter{reaction}% - \newcommand*\CM@AtBeginReaction{\setcounter{save@reaction}{\value{equation}}\setcounter{equation}{\value{reaction}}\usetagform{CMreaction}}% - \newcommand*\CM@AtEndReaction{\setcounter{reaction}{\value{equation}}\setcounter{equation}{\value{save@reaction}}\usetagform{default}}% -% \newreaction*+{}{} -% * and + are optional - \NewDocumentCommand\newreaction{st+mm}{% - \@ifundefined{#3}{% - \IfBooleanTF{#2}{% - \NewEnviron{#3}[1]{\CM@AtBeginReaction\begin{#4}{##1}\expandafter\cee\expandafter{\BODY}\end{#4}\CM@AtEndReaction} - \IfBooleanTF{#1}{% - \NewEnviron{#3*}[1]{\begin{#4*}{##1}\expandafter\cee\expandafter{\BODY}\end{#4*}}% - }{}% - }{% - \NewEnviron{#3}{\CM@AtBeginReaction\begin{#4}\expandafter\cee\expandafter{\BODY}\end{#4}\CM@AtEndReaction} - \IfBooleanTF{#1}{% - \NewEnviron{#3*}{\begin{#4*}\expandafter\cee\expandafter{\BODY}\end{#4*}}% - }{}% - }% - }{\PackageError{chemmacros}{The environment/command #3 is already defined}{}}% +\bool_new:N \l_chemmacros_reactions_star_bool +\bool_new:N \l_chemmacros_reactions_args_bool +\int_new:N \l_chemmacros_reactions_args_int + +\keys_define:nn { chemmacros / reaction } + { + star .bool_set:N = \l_chemmacros_reactions_star_bool , + star .default:n = true , + arg .bool_set:N = \l_chemmacros_reactions_args_bool , + arg .default:n = true } + +% \newreaction[]{}{} +\bool_if:NF \l_chemmacros_version_one_bool + { + \NewDocumentCommand \newreaction { o m m } + { + \cs_if_exist:cTF { #2 } + { + \msg_error:nnx { chemmacros } { already-defined } { #2 } + } + { + \IfNoValueTF { #1 } + { + \bool_set_false:N \l_chemmacros_reactions_star_bool + \bool_set_false:N \l_chemmacros_reactions_args_bool + } + { \keys_set:nn { chemmacros / reaction } { #1 } } + \bool_if:NTF \l_chemmacros_reactions_args_bool + { + \NewEnviron { #2 } [ 1 ] + { + \chemmacros_begin_reaction: + \begin { #3 } { ##1 } + \chemmacros_cee:f { \BODY } + \end{ #3 } + \chemmacros_end_reaction: + } + \bool_if:NT \l_chemmacros_reactions_star_bool + { + \NewEnviron { #2* } [ 1 ] + { + \begin { #3* } { ##1 } + \chemmacros_cee:f { \BODY } + \end { #3* } + } + } + } + { + \NewEnviron { #2 } + { + \chemmacros_begin_reaction: + \begin { #3 } + \chemmacros_cee:f { \BODY } + \end { #3 } + \chemmacros_end_reaction: + } + \bool_if:NT \l_chemmacros_reactions_star_bool + { + \NewEnviron { #2* } + { + \begin { #3* } + \chemmacros_cee:f { \BODY } + \end { #3* } + } + } + } + } + } + } + +\cs_new:Npn \chemmacros_cee:n #1 + { \cee { #1 } } +\cs_generate_variant:Nn \chemmacros_cee:n { f } + % predefined: - \newreaction*{reaction}{equation}% - \newreaction*{reactions}{align}% -\fi} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - phases ---------------------------------------------------------------------------- % -\newcommand*\solid[1][]{\ensuremath{_\mathrm{(\ifx\@empty#1\@empty\if@CM@german f\else s\fi\else#1\fi)}}} -\newcommand*\gas{\ensuremath{_\mathrm{(g)}}} -\newcommand*\liquid[1][]{\ensuremath{_\mathrm{(\ifx\@empty#1\@empty\if@CM@german f\/l\else l\fi\else#1\fi)}}} -\newcommand*\aq{\ensuremath{_\mathrm{(aq)}}} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - transition state symbol ----------------------------------------------------------- % -\AtBeginDocument{% -\newcommand*\CM@transition@state@symbol{\tikz[inner sep=0,outer sep=0,minimum size=0]{% - \draw(0,0)--node[pos=.3333](@TSx){}node[pos=.6667](@TSy){}(0,.6em);% - \draw(@TSx)++(-.3em,0)--++(.6em,0);% - \draw(@TSy)++(-.3em,0)--++(.6em,0);}% -} -% make sure symbol scales correctly: -\if@CM@mychemistryloaded - \renewcommand*\transitionstatesymbol{\ifmmode\text{\CM@transition@state@symbol}\else\CM@transition@state@symbol\fi} -\else - \newcommand*\transitionstatesymbol{\ifmmode\text{\CM@transition@state@symbol}\else\CM@transition@state@symbol\fi} -\fi} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - thermodynamics et.al. ------------------------------------------------------------- % -\AtBeginDocument{\if@CM@chemstyleloaded\else\newcommand*\standardstate{\circ}\fi - -% \setstatesubscript{right/left} -\newcommand*\CM@State@subscript{left} -\newcommand*\setstatesubscript[1]{% - \renewcommand*\CM@State@subscript{\ifx\relax#1\relax left\else#1\fi} -} - -% \State[,,]{}{} -% {} is an optional argument! -\NewDocumentCommand\State{omG{}}{% - \IfNoValueTF{#1}{\CM@splitting{}{3}}{\CM@splitting{#1}{3}}% - \ensuremath{% - \CM@compareCs{CM@arg@iii}{@empty}{% - \CM@compareStr{\CM@State@subscript}{right}{\let\CM@State@sub@left\@empty\def\CM@State@sub@right{_\mathrm{#3}}}{\let\CM@State@sub@right\@empty\def\CM@State@sub@left{_\mathrm{#3}}}% - }{ - \CM@compareStr{\CM@arg@iii}{right}{\let\CM@State@sub@left\@empty\def\CM@State@sub@right{_\mathrm{#3}}}{% - \CM@compareStr{\CM@arg@iii}{left}{\let\CM@State@sub@right\@empty\def\CM@State@sub@left{_\mathrm{#3}}}{% - \PackageWarning{chemmacros}{\string\State: can only have the values 'left' or 'right'}{}% +\bool_if:NF \l_chemmacros_version_one_bool + { + \newreaction [ star ] { reaction } { equation } + \newreaction [ star ] { reactions } { align } + } + +\NewDocumentCommand \chcancel { m } + { \cancel { \chemmacros_atom:f { #1 } } } + +% --------------------------------------------------------------------------- % +% thermodynamics et.al. +% \standardstate as defined by the chemstyle package. Thanks to Joseph Wright +% \AtBeginDocument +% { + \cs_if_exist:NF \standardstate + { + \cs_new_nopar:Npn \standardstate + { + \ensuremath { \chemmacros_standardstate: } + } + \cs_new_nopar:Npn \chemmacros_standardstate: + { + \mathpalette \chemmacros_standardstate_aux: \circ + } + \cs_new_nopar:Npn \chemmacros_standardstate_aux: #1#2 + { + \ooalign + { + \tex_hfil:D + $#1-$ + \tex_hfil:D + \tex_cr:D + \tex_hfil:D + $#1#2$ + \tex_hfil:D + \tex_cr:D + } + } + } +% } + +% --------------------------------------------------------------------------- % +% \State +\tl_new:N \l_chemmacros_State_delta_tl +\tl_set:Nn \l_chemmacros_State_delta_tl { \Delta } +\bool_new:N \l_chemmacros_State_delta_bool +\bool_set_true:N \l_chemmacros_State_delta_bool +\bool_new:N \l_chemmacros_State_subscript_left_bool +\bool_set_true:N \l_chemmacros_State_subscript_left_bool +\bool_new:N \l_chemmacros_State_exponent_bool +\bool_set_true:N \l_chemmacros_State_exponent_bool +\tl_new:N \l_chemmacros_State_exponent_tl +\tl_set:Nn \l_chemmacros_State_exponent_tl { \standardstate } + +\keys_define:nn { chemmacros / state } + { + delta .code:n = + { + \exp_args:Nf \tl_if_eq:nnTF { #1 } { false } + { \bool_set_false:N \l_chemmacros_State_delta_bool } + { + \bool_set_true:N \l_chemmacros_State_delta_bool + \tl_set:Nn \l_chemmacros_State_delta_tl { #1 } + } + } , + subscript-left .bool_set:N = \l_chemmacros_State_subscript_left_bool , + subscript-left .default:n = true , + exponent .code:n = + { + \exp_args:Nf \tl_if_eq:nnTF { #1 } { false } + { \bool_set_false:N \l_chemmacros_State_exponent_bool } + { + \bool_set_true:N \l_chemmacros_State_exponent_bool + \tl_set:Nn \l_chemmacros_State_exponent_tl { #1 } + } + } , + exponent .default:n = \standardstate + } + +% old syntax (v1.1): +% \State[,,]{}{} +% old syntax (v2.0): +% \State[]{}{} +% {} is an optional argument! +\char_set_catcode_math_subscript:N \@ +\cs_new_nopar:Npn \chemmacros_state:nnn #1#2#3 + { + \group_begin: + \IfNoValueF { #1 } + { \keys_set:nn { chemmacros / state } { #1 } } + \ensuremath + { + \bool_if:NT \l_chemmacros_State_delta_bool + { \tl_use:N \l_chemmacros_State_delta_tl } + \bool_if:NT \l_chemmacros_State_subscript_left_bool + { @ { \text { #3 } } } + #2 + \bool_if:NF \l_chemmacros_State_subscript_left_bool + { @ { \text { #3 } } } + \bool_if:NT \l_chemmacros_State_exponent_bool + { ^ { \tl_use:N \l_chemmacros_State_exponent_tl } } } - }% - }% - \CM@compareCs{CM@arg@ii}{@empty}{\Delta}{\CM@arg@ii}\CM@State@sub@left#2\CM@State@sub@right% - \CM@compareCs{CM@arg@i}{@empty}{^{\standardstate}}{^{\CM@arg@i}}}% -} - -% \setnewstate[,,]{}{}{} -% \renewstate[,,]{}{}{} -\newcommand*\CM@setnewstate[4][]{% - \CM@splitting{#1}{3}% [,,] - \CM@compareCs{CM@arg@i}{@empty}{\expandafter\let\csname CM@#2@supscript\endcsname\standardstate}{\expandafter\let\csname CM@#2@supscript\endcsname\CM@arg@i}% - \CM@compareCs{CM@arg@ii}{@empty}{\expandafter\let\csname CM@#2@delta\endcsname\Delta}{\expandafter\let\csname CM@#2@delta\endcsname\CM@arg@ii} - \CM@compareCs{CM@arg@iii}{@empty}{\@namedef{CM@#2@right}{left}}{\expandafter\let\csname CM@#2@right\endcsname\CM@arg@iii}% - \@namedef{#2}{\@ifnextchar[{\@nameuse{CM@#2@ii}}{\@nameuse{CM@#2@i}}}% - \@namedef{CM@#2@i}##1{\ensuremath{\State[\@nameuse{CM@#2@supscript},\@nameuse{CM@#2@delta},\@nameuse{CM@#2@right}]{#3}{}=\SI{##1}{#4}}}% - \@namedef{CM@#2@ii}[##1]##2{% - \CM@splitting{##1}{4}% [,,,] - \let\CM@State@index\CM@arg@i - \CM@compareCs{CM@arg@ii}{@empty}{\def\CM@State@supscript{\@nameuse{CM@#2@supscript}}}{\let\CM@State@supscript\CM@arg@ii}% - \CM@compareCs{CM@arg@iii}{@empty}{\def\CM@State@unit{#4}}{\let\CM@State@unit\CM@arg@iii}% - \CM@compareCs{CM@arg@iv}{@empty}{\def\CM@State@right{\@nameuse{CM@#2@right}}}{\let\CM@State@right\CM@arg@iv}% - \ensuremath{\State[\CM@State@supscript,\@nameuse{CM@#2@delta},\CM@State@right]{#3}{\CM@State@index} = \SI{##2}{\CM@State@unit}}% - }% -} -\newcommand*\setnewstate[4][]{% - \@ifundefined{#2}{\CM@setnewstate[#1]{#2}{#3}{#4}}{\PackageError{chemmacros}{\string\setnewstate: state #2 is already defined}{}}% -} -\newcommand*\renewstate[4][]{% - \@ifundefined{#2}{\PackageError{chemmacros}{\string\renewstate: state #2 is not defined}{}}{\CM@setnewstate[#1]{#2}{#3}{#4}}% -} -\setnewstate{Enthalpy}{H}{\kilo\joule\per\mole}% -\setnewstate[, ]{Entropy}{S}{\joule\per\kelvin\per\mole}% -\setnewstate{Gibbs}{G}{\kilo\joule\per\mole}% -} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - p-orbitals ------------------------------------------------------------------------ % -\newcommand*\CM@porb[1][]{% - \CM@splitting{#1}{3}% - \CM@compareCs{CM@arg@i}{@empty}{\let\CM@orbital@height\CM@orb@height}{\def\CM@orbital@height{\CM@arg@i*\CM@orb@height}}% - \CM@compareCs{CM@arg@ii}{@empty}{\def\CM@orb@color{black}}{\let\CM@orb@color\CM@arg@ii}% - \CM@compareStr{\CM@orb@color}{white}{\def\CM@orb@color@draw{black}}{\let\CM@orb@color@draw\CM@orb@color}% - \CM@compareCs{CM@arg@iii}{@empty}{\def\CM@orb@ang{0}}{\let\CM@orb@ang\CM@arg@iii}% - \tikzpicture[overlay,rotate={\CM@orb@ang-90},opacity=.5,inner sep=0pt,outer sep=0pt,text height=0pt,text depth=0pt]% - \pgfsetfillopacity{.5}% - \CM@compareStr{\CM@orb@half}{false}{% - \draw[draw=black] (0,0) .. controls ++(-.9*\CM@orbital@height,-1.5*\CM@orbital@height) and ++(.9*\CM@orbital@height,-1.5*\CM@orbital@height) .. (0,0);% - }{}% - \draw[draw=\CM@orb@color@draw,fill=\CM@orb@color] (0,0) .. controls ++(-.9*\CM@orbital@height,1.5*\CM@orbital@height) and ++(.9*\CM@orbital@height,1.5*\CM@orbital@height) .. (0,0);% - \endtikzpicture% -} -% full orbital: -% \porb[,,] -\newcommand*\porb{\def\CM@orb@half{false}\CM@porb}% -% half of an orbital: -% \phorb[,,] -\newcommand*\phorb{\def\CM@orb@half{true}\CM@porb}% - -% predefined orbitals: -\newcommand*\pzorb{\porb[,,90]}% -\newcommand*\pyorb{\porb[,,0]}% -\newcommand*\pxorb{\porb[,,-135]}% - -% change orbital settings: -\newcommand*\CM@orb@height{1em}% -\newcommand*\setorbheight[1]{% - \ifx\@empty#1\@empty - \renewcommand*\CM@orb@height{1em}% - \else - \renewcommand*\CM@orb@height{#1}% - \fi -} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% - Newman projections ---------------------------------------------------------------- % + \group_end: + } +\cs_generate_variant:Nn \chemmacros_state:nnn { fnn,xnn } + +\bool_if:NF \l_chemmacros_version_one_bool + { + \NewDocumentCommand \State { s o m G{} } + { + \group_begin: + \IfBooleanT { #1 } + { + \keys_set:nn { chemmacros / state } + { subscript-left = false , exponent = } + } + \chemmacros_state:nnn { #2 } { #3 } { #4 } + \group_end: + } + } +\char_set_catcode_letter:N \@ + +% --------------------------------------------------------------------------- % +\tl_new:N \l_chemmacros_thermod_subscript_left_tl +\tl_new:N \l_chemmacros_thermod_subscript_left_default_tl +\tl_new:N \l_chemmacros_thermod_subscript_tl +\tl_new:N \l_chemmacros_thermod_subscript_default_tl + +\tl_new:N \l_chemmacros_thermod_unit_tl + +\tl_new:N \l_chemmacros_thermod_exponent_tl +\tl_new:N \l_chemmacros_thermod_exponent_default_tl +\tl_set:Nn \l_chemmacros_thermod_exponent_default_tl { \standardstate } + +\tl_new:N \l_chemmacros_thermod_delta_tl +\tl_new:N \l_chemmacros_thermod_delta_default_tl +\tl_set:Nn \l_chemmacros_thermod_delta_default_tl { \Delta } + +\bool_new:N \l_chemmacros_renewstate_bool + +\keys_define:nn { chemmacros } + { + State / subscript .choice: , + State / subscript / left .code:n = + { \tl_set:Nn \l_chemmacros_thermod_subscript_left_tl { true } } , + State / subscript / right .code:n = + { \tl_set:Nn \l_chemmacros_thermod_subscript_left_tl { false } } , + State / exponent .tl_set:N = + \l_chemmacros_thermod_exponent_tl , + State / delta .tl_set:N = + \l_chemmacros_thermod_delta_tl , + State / unit .tl_set:N = + \l_chemmacros_thermod_unit_tl , + setnewstate / subscript-left .tl_set:N = + \l_chemmacros_thermod_subscript_left_default_tl , + setnewstate / subscript .tl_set:N = + \l_chemmacros_thermod_subscript_default_tl , + setnewstate / exponent .tl_set:N = + \l_chemmacros_thermod_exponent_default_tl , + setnewstate / delta .tl_set:N = + \l_chemmacros_thermod_delta_default_tl + } + +% \setnewstate[]{}{}{} +\bool_if:NF \l_chemmacros_version_one_bool + { + \cs_new:Npn \setnewstate + { + \bool_set_false:N \l_chemmacros_renewstate_bool + \chemmacros_setnewstate_reset: + \peek_meaning:NTF [ + { \setnewstate_aux_i:n } + { \setnewstate_aux_ii:nnn } + } +% \renewstate[]{}{}{} + \cs_new:Npn \renewstate + { + \bool_set_true:N \l_chemmacros_renewstate_bool + \chemmacros_setnewstate_reset: + \peek_meaning:NTF [ + { \setnewstate_aux_i:n } + { \setnewstate_aux_ii:nnn } + } + } + +\cs_new_nopar:Npn \chemmacros_setnewstate_reset: + { + \tl_set:Nn \l_chemmacros_thermod_subscript_left_default_tl { true } + \tl_clear:N \l_chemmacros_thermod_subscript_default_tl + \tl_set:Nn \l_chemmacros_thermod_exponent_default_tl { \standardstate } + \tl_set:Nn \l_chemmacros_thermod_delta_default_tl { \Delta } + } + +\cs_new:Npn \setnewstate_aux_i:n [#1] + { + \keys_set:nn { chemmacros / setnewstate } { #1 } + \setnewstate_aux_ii:nnn + } + +\cs_new:Npn \setnewstate_aux_ii:nnn #1#2#3 + { + \bool_if:NTF \l_chemmacros_renewstate_bool + { + \cs_if_exist:cF { #1 } + { \msg_error:nnx { chemmacros } { renewstate } { #1 } } + \cs_undefine:c {chemmacros_ #1 _reset: } + \cs_undefine:c { l_chemmacros_ #1 _subscript_tl } + \cs_undefine:c { l_chemmacros_ #1 _exponent_tl } + \cs_undefine:c { l_chemmacros_ #1 _delta_tl } + \cs_undefine:c { l_chemmacros_ #1 _left_tl } + \cs_undefine:c { l_chemmacros_ #1 _unit_tl } + \cs_undefine:c { #1 } + \cs_undefine:c { #1 _aux_i:n } + \cs_undefine:c { #1 _aux_ii:n } + \cs_undefine:c { #1 _aux_iii:n } + } + { + \cs_if_exist:cT { #1 } + { \msg_error:nnx { chemmacros } { setnewstate } { #1 } } + } + \group_begin: + \exp_args:Nnf \tl_const:cn + { l_chemmacros_ #1 _subscript_tl } + { \tl_use:N \l_chemmacros_thermod_subscript_default_tl } + \exp_args:Nnf \tl_const:cn + { l_chemmacros_ #1 _exponent_tl } + { \tl_use:N \l_chemmacros_thermod_exponent_default_tl } + \exp_args:Nnf \tl_const:cn + { l_chemmacros_ #1 _delta_tl } + { \tl_use:N \l_chemmacros_thermod_delta_default_tl } + \exp_args:Nnf \tl_const:cn + { l_chemmacros_ #1 _left_tl } + { \tl_use:N \l_chemmacros_thermod_subscript_left_default_tl } + \tl_const:cn + { l_chemmacros_ #1 _unit_tl } + { #3 } + \cs_new_nopar:cpn {chemmacros_ #1 _reset: } + { + \tl_set_eq:Nc + \l_chemmacros_thermod_subscript_tl + { l_chemmacros_ #1 _subscript_tl } + \tl_set_eq:Nc + \l_chemmacros_thermod_exponent_tl + { l_chemmacros_ #1 _exponent_tl } + \tl_set_eq:Nc + \l_chemmacros_thermod_delta_tl + { l_chemmacros_ #1 _delta_tl } + \tl_set_eq:Nc + \l_chemmacros_thermod_subscript_left_tl + { l_chemmacros_ #1 _left_tl } + \tl_set_eq:Nc + \l_chemmacros_thermod_unit_tl + { l_chemmacros_ #1 _unit_tl } + } + \cs_new_nopar:cpn { #1 } + { + \use:c {chemmacros_ #1 _reset: } + \peek_meaning:NTF [ + { \tl_use:c { #1 _aux_i:n } } + { + \peek_meaning:NTF ( + { \tl_use:c { #1 _aux_ii:n } } + { \tl_use:c { #1 _aux_iii:n } } + } + } + \cs_new_nopar:cpn { #1 _aux_i:n } [##1] + { + \keys_set:nn { chemmacros / State } { ##1 } + \peek_meaning:NTF ( + { \tl_use:c { #1 _aux_ii:n } } + { \tl_use:c { #1 _aux_iii:n } } + } + \cs_new_nopar:cpn { #1 _aux_ii:n } (##1) + { + \tl_set:Nn \l_chemmacros_thermod_subscript_tl { ##1 } + \tl_use:c { #1 _aux_iii:n } + } + \cs_new_nopar:cpn { #1 _aux_iii:n } ##1 + { + \ensuremath + { + \exp_args:Nf \tl_if_eq:nnTF + { \tl_use:N \l_chemmacros_thermod_subscript_left_tl } { true } + { + \chemmacros_state:fnn + { + subscript-left = true , + exponent = + { \tl_use:N \l_chemmacros_thermod_exponent_tl } , + delta = + { \tl_use:N \l_chemmacros_thermod_delta_tl } + } + { #2 } + } + { + \chemmacros_state:fnn + { + subscript-left = false , + exponent = + { \tl_use:N \l_chemmacros_thermod_exponent_tl } , + delta = + { \tl_use:N \l_chemmacros_thermod_delta_tl } + } + { #2 } + } + { \tl_use:N \l_chemmacros_thermod_subscript_tl } + = + \exp_args:Nno \SI { ##1 } { \l_chemmacros_thermod_unit_tl } + } + } + \group_end: + } + +% predefined: +\bool_if:NF \l_chemmacros_version_one_bool + { + \setnewstate {Enthalpy} {H} {\kilo\joule\per\mole} + \setnewstate[delta=false,subscript-left=false] {Entropy} {S} {\joule\per\kelvin\per\mole} + \setnewstate {Gibbs} {G} {\kilo\joule\per\mole} + } + +% --------------------------------------------------------------------------- % +% Newman projections +\fp_new:N \l_chemmacros_newman_rel_angle_fp +\fp_zero:N \l_chemmacros_newman_rel_angle_fp +\fp_new:N \l_chemmacros_newman_tmp_angle_fp +\fp_new:N \l_chemmacros_newman_abs_angle_fp +\fp_zero:N \l_chemmacros_newman_abs_angle_fp + +\fp_new:N \l_chemmacros_newman_scale_fp +\fp_set:Nn \l_chemmacros_newman_scale_fp { 1 } + +\tl_new:N \l_chemmacros_newman_tikz_ring_tl +\tl_clear:N \l_chemmacros_newman_tikz_ring_tl + +\tl_new:N \l_chemmacros_newman_tikz_front_tl +\tl_clear:N \l_chemmacros_newman_tikz_front_tl + +\tl_new:N \l_chemmacros_newman_tikz_back_tl +\tl_clear:N \l_chemmacros_newman_tikz_back_tl + +\bool_new:N \l_chemmacros_newman_tikz_back_bool + +\fp_new:N \l_chemmacros_newman_x_fp +\fp_new:N \l_chemmacros_newman_y_fp + +\keys_define:nn { chemmacros / newman } + { + ring .tl_set:N = \l_chemmacros_newman_tikz_ring_tl , + atoms .tl_set:N = \l_chemmacros_newman_tikz_front_tl , + back-atoms .code:n = + { + \bool_set_true:N \l_chemmacros_newman_tikz_back_bool + \tl_set:Nn \l_chemmacros_newman_tikz_back_tl { #1 } + } , + scale .fp_set:N = \l_chemmacros_newman_scale_fp , + scale .default:n = 1 , + angle .fp_set:N = \l_chemmacros_newman_abs_angle_fp , + angle .default:n = 0 + } + +% old usage (v1.1): % \newman[,,][][]{<1>,<2>,<3>,<4>,<5>,<6>} -\NewDocumentCommand\newman{ooom}{% - \IfNoValueTF{#1}{% - \def\CM@newman@angle{0}% - \def\CM@newman@scale{1}% - \def\CM@newman@tikz@ring{}% - }{% - \CM@splitting{#1}{3}% - \CM@compareCs{CM@arg@i}{@empty}{\def\CM@newman@angle{0}}{\let\CM@newman@angle\CM@arg@i}% - \CM@compareCs{CM@arg@ii}{@empty}{\def\CM@newman@scale{1}}{\let\CM@newman@scale\CM@arg@ii}% - \expandafter\def\expandafter\CM@newman@tikz@ring\expandafter{\CM@arg@iii}% - } - \IfNoValueTF{#2}{% - \let\CM@newman@tikz@one\@empty% - }{% - \def\CM@newman@tikz@one{#2}% - } - \IfNoValueTF{#3}{% - \let\CM@newman@tikz@two\CM@newman@tikz@one% - }{% - \def\CM@newman@tikz@two{#3}% - } - \CM@splitting{#4}{6}% - \edef\CM@newman@tikz{scale=\CM@newman@scale,CMatomFront/.style={inner sep=0,outer sep=0,\CM@newman@tikz@one},CMatomBack/.style={inner sep=0,outer sep=0,\CM@newman@tikz@two}} - \expandafter\tikz\expandafter[\CM@newman@tikz]{% - \expandafter\draw\expandafter[\CM@newman@tikz@ring] (0,0) circle (.5);% - \foreach\i in{30+\CM@newman@angle,150+\CM@newman@angle,270+\CM@newman@angle}{% - \expandafter\draw\expandafter[\CM@newman@tikz@ring] (\i:0.5) --++(\i:.5);% - }% - \node[CMatomBack,anchor=-150+\CM@newman@angle] at (30+\CM@newman@angle:1.05) {\CM@arg@v};% - \node[CMatomBack,anchor=-30+\CM@newman@angle] at (150+\CM@newman@angle:1.05) {\CM@arg@vi};% - \node[CMatomBack,anchor=90+\CM@newman@angle] at (270+\CM@newman@angle:1.05) {\CM@arg@iv};% - \foreach\i in{90,210,330}{% - \expandafter\draw\expandafter[\CM@newman@tikz@ring] (0,0) --++(\i:1);% - }% - \node[CMatomFront,anchor=-90] at (90:1.05) {\CM@arg@i};% - \node[CMatomFront,anchor=30] at (210:1.05) {\CM@arg@ii};% - \node[CMatomFront,anchor=150] at (330:1.05) {\CM@arg@iii};% - }% -} -\endinput -% - 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 % \ No newline at end of file +% new usage (v1.2): +% \newman[](){<1>,<2>,<3>,<4>,<5>,<6>} +\bool_if:NF \l_chemmacros_version_one_bool + { + \NewDocumentCommand \newman { o d() > { \SplitArgument { 5 } { , } } m } + { + \group_begin: + \IfNoValueF { #1 } { \keys_set:nn { chemmacros / newman } { #1 } } + \IfNoValueTF { #2 } + { \fp_set_eq:NN \l_chemmacros_newman_rel_angle_fp \l_chemmacros_newman_abs_angle_fp } + { \fp_set:Nn \l_chemmacros_newman_rel_angle_fp { #2 } } + \chemmacros_newman_atoms:nnnnnn #3 + \group_end: + } + } + +% place atoms: +\cs_new:Npn \chemmacros_newman_atoms:nnnnnn #1#2#3#4#5#6 + { + \chemmacros_tikz_picture:xn + { + scale = \fp_to_tl:N \l_chemmacros_newman_scale_fp , + chemmacros_newman_atom_front / .style = + { + inner~sep=0, + outer~sep=0, + \tl_use:N \l_chemmacros_newman_tikz_front_tl + }, + chemmacros_newman_atom_back / .style = + { + inner~sep=0, + outer~sep=0, + \bool_if:NTF \l_chemmacros_newman_tikz_back_bool + { \tl_use:N \l_chemmacros_newman_tikz_back_tl } + { \tl_use:N \l_chemmacros_newman_tikz_front_tl } + } + } + { + \chemmacros_tikz_draw:f + { \tl_use:N \l_chemmacros_newman_tikz_ring_tl } + (0,0) circle (\fp_to_dim:N \l_chemmacros_newman_scale_fp * 15) ; + \chemmacros_newman_back_node:nf + { 30 } + { \IfNoValueF { #5 } { #5 } } + \chemmacros_newman_back_node:nf + { 150 } + { \IfNoValueF { #6 } { #6 } } + \chemmacros_newman_back_node:nf + { 270 } + { \IfNoValueF { #4 } { #4 } } + \chemmacros_newman_front_node:nf + { 90 } + { \IfNoValueF { #1 } { #1 } } + \chemmacros_newman_front_node:nf + { 210 } + { \IfNoValueF { #2 } { #2 } } + \chemmacros_newman_front_node:nf + { 330 } + { \IfNoValueF { #3 } { #3 } } + } + } + +% provide cartesian coordiantes from polar coordinates +% #1: angle pi #2: radius +\cs_new_nopar:Npn \chemmacros_newman_coordinates:nn #1#2 + { + \fp_set:Nn \l_chemmacros_newman_tmp_angle_fp { #1 } + \fp_div:Nn \l_chemmacros_newman_tmp_angle_fp { 180 } + \fp_mul:Nn \l_chemmacros_newman_tmp_angle_fp { \fp_use:N \c_pi_fp } + \fp_zero:N \l_chemmacros_newman_x_fp + \fp_zero:N \l_chemmacros_newman_y_fp + \fp_cos:Nn \l_chemmacros_newman_x_fp { \fp_use:N \l_chemmacros_newman_tmp_angle_fp } + \fp_sin:Nn \l_chemmacros_newman_y_fp { \fp_use:N \l_chemmacros_newman_tmp_angle_fp } + \fp_mul:Nn \l_chemmacros_newman_x_fp { \fp_use:N #2 } + \fp_mul:Nn \l_chemmacros_newman_y_fp { \fp_use:N #2 } + } +\cs_generate_variant:Nn \chemmacros_newman_coordinates:nn { on } + +% place back nodes +\cs_new:Npn \chemmacros_newman_back_node:nn #1#2 + { + \group_begin: + \fp_add:Nn \l_chemmacros_newman_rel_angle_fp { #1 } + \chemmacros_newman_coordinates:on + { \fp_to_int:N \l_chemmacros_newman_rel_angle_fp } + { \l_chemmacros_newman_scale_fp } + \chemmacros_tikz_draw:f + { \tl_use:N \l_chemmacros_newman_tikz_ring_tl } + ( 15 * \fp_to_dim:N \l_chemmacros_newman_x_fp , 15 * \fp_to_dim:N \l_chemmacros_newman_y_fp ) + -- + ( 30 * \fp_to_dim:N \l_chemmacros_newman_x_fp , 30 * \fp_to_dim:N \l_chemmacros_newman_y_fp ) ; + \chemmacros_newman_coordinates:on + { \fp_to_int:N \l_chemmacros_newman_rel_angle_fp } + { \l_chemmacros_newman_scale_fp } + \chemmacros_tikz_node:f + { + chemmacros_newman_atom_back, + anchor = -180 + \fp_to_int:N \l_chemmacros_newman_rel_angle_fp + } + at ( 31 * \fp_to_dim:N \l_chemmacros_newman_x_fp , 31 * \fp_to_dim:N \l_chemmacros_newman_y_fp ) + { #2 } ; + \group_end: + } +\cs_generate_variant:Nn \chemmacros_newman_back_node:nn { nf } + +% place front nodes: +\cs_new:Npn \chemmacros_newman_front_node:nn #1#2 + { + \chemmacros_newman_coordinates:nn { #1 } { \l_chemmacros_newman_scale_fp } + \chemmacros_tikz_draw:f + { \tl_use:N \l_chemmacros_newman_tikz_ring_tl } + (0,0) -- ++ ( 30 * \fp_to_dim:N \l_chemmacros_newman_x_fp , 30 * \fp_to_dim:N \l_chemmacros_newman_y_fp ) ; + \chemmacros_newman_coordinates:nn { #1 } { \l_chemmacros_newman_scale_fp } + \chemmacros_tikz_node:f + { chemmacros_newman_atom_front, anchor = -180 + #1 } + at ( 31 * \fp_to_dim:N \l_chemmacros_newman_x_fp , 31 * \fp_to_dim:N \l_chemmacros_newman_y_fp ) + { #2 } ; + } +\cs_generate_variant:Nn \chemmacros_newman_front_node:nn { nf } + +% --------------------------------------------------------------------------- % +% \orbital[]{} +% variables: +\bool_new:N \l_chemmacros_orbital_type_s_bool +\bool_new:N \l_chemmacros_orbital_type_p_bool +\bool_new:N \l_chemmacros_orbital_type_sp_bool +\bool_new:N \l_chemmacros_orbital_type_sptwo_bool +\bool_new:N \l_chemmacros_orbital_type_spthree_bool + +\tl_new:N \l_chemmacros_orbital_s_color_tl +\tl_set:Nn \l_chemmacros_orbital_s_color_tl { black } +\tl_new:N \l_chemmacros_orbital_s_phase_color_tl + +\tl_new:N \l_chemmacros_orbital_p_color_tl +\tl_set:Nn \l_chemmacros_orbital_p_color_tl { black } +\tl_new:N \l_chemmacros_orbital_p_pphase_color_tl +\tl_new:N \l_chemmacros_orbital_p_mphase_color_tl + +\tl_new:N \l_chemmacros_orbital_sp_color_tl +\tl_set:Nn \l_chemmacros_orbital_sp_color_tl { black } +\tl_new:N \l_chemmacros_orbital_sp_pphase_color_tl +\tl_new:N \l_chemmacros_orbital_sp_mphase_color_tl + +\tl_new:N \l_chemmacros_orbital_sptwo_color_tl +\tl_set:Nn \l_chemmacros_orbital_sptwo_color_tl { black } +\tl_new:N \l_chemmacros_orbital_sptwo_pphase_color_tl +\tl_new:N \l_chemmacros_orbital_sptwo_mphase_color_tl + +\tl_new:N \l_chemmacros_orbital_spthree_color_tl +\tl_set:Nn \l_chemmacros_orbital_spthree_color_tl { black } +\tl_new:N \l_chemmacros_orbital_spthree_pphase_color_tl +\tl_new:N \l_chemmacros_orbital_spthree_mphase_color_tl + +\bool_new:N \l_chemmacros_orbital_s_phase_bool +\bool_set_true:N \l_chemmacros_orbital_s_phase_bool + +\bool_new:N \l_chemmacros_orbital_p_phase_bool +\bool_set_true:N \l_chemmacros_orbital_p_phase_bool + +\bool_new:N \l_chemmacros_orbital_sp_phase_bool +\bool_set_true:N \l_chemmacros_orbital_sp_phase_bool + +\bool_new:N \l_chemmacros_orbital_sptwo_phase_bool +\bool_set_true:N \l_chemmacros_orbital_sptwo_phase_bool + +\bool_new:N \l_chemmacros_orbital_spthree_phase_bool +\bool_set_true:N \l_chemmacros_orbital_spthree_phase_bool + +\tl_new:N \l_chemmacros_orbital_s_scale_tl +\tl_set:Nn \l_chemmacros_orbital_s_scale_tl { 1 } + +\tl_new:N \l_chemmacros_orbital_p_scale_tl +\tl_set:Nn \l_chemmacros_orbital_p_scale_tl { 1 } + +\tl_new:N \l_chemmacros_orbital_sp_scale_tl +\tl_set:Nn \l_chemmacros_orbital_sp_scale_tl { 1 } + +\tl_new:N \l_chemmacros_orbital_sptwo_scale_tl +\tl_set:Nn \l_chemmacros_orbital_sptwo_scale_tl { 1 } + +\tl_new:N \l_chemmacros_orbital_spthree_scale_tl +\tl_set:Nn \l_chemmacros_orbital_spthree_scale_tl { 1 } + +\fp_new:N \l_chemmacros_orbital_angle_fp +\fp_set:Nn \l_chemmacros_orbital_angle_fp { 90 } + +\bool_new:N \l_chemmacros_orbital_p_half_bool +\bool_set_false:N \l_chemmacros_orbital_p_half_bool + +\bool_new:N \l_chemmacros_orbital_overlay_bool +\bool_set_false:N \l_chemmacros_orbital_overlay_bool + +\bool_new:N \l_chemmacros_orbital_opacity_bool +\bool_set_false:N \l_chemmacros_opacity_overlay_bool + +\fp_new:N \l_chemmacros_orbital_opacity_fp +\fp_set:Nn \l_chemmacros_orbital_opacity_fp { 0.5 } + +\cs_new_nopar:Npn \chemmacros_orbital_options: + { + \chemmacros_orbital_overlay: , \chemmacros_orbital_opacity: , + inner~sep=0 , outer~sep=0 , line~width=.2pt , + rotate = { \fp_use:N \l_chemmacros_orbital_angle_fp - 90 } , + baseline , + minimum~size = 0 + } + +\cs_new_nopar:Npn \chemmacros_orbital_overlay: + { + \bool_if:NT \l_chemmacros_orbital_overlay_bool { overlay } + } + +\cs_new_nopar:Npn \chemmacros_orbital_opacity: + { + \bool_if:NT \l_chemmacros_orbital_opacity_bool + { opacity = { \fp_use:N \l_chemmacros_orbital_opacity_fp } } + } + +% --------------------------------------------------------------------------- % +% s-orbitals +\cs_new_nopar:Npn \chemmacros_orbital_type_s: + { + \bool_set_true:N \l_chemmacros_orbital_type_s_bool + \bool_set_false:N \l_chemmacros_orbital_type_p_bool + \bool_set_false:N \l_chemmacros_orbital_type_sp_bool + \bool_set_false:N \l_chemmacros_orbital_type_sptwo_bool + \bool_set_false:N \l_chemmacros_orbital_type_spthree_bool + } + +\keys_define:nn { chemmacros / orbital / s } + { + phase .choice: , + phase / + .code:n = { \bool_set_true:N \l_chemmacros_orbital_s_phase_bool } , + phase / - .code:n = { \bool_set_false:N \l_chemmacros_orbital_s_phase_bool } , + phase .default:n = + , + scale .tl_set:N = \l_chemmacros_orbital_s_scale_tl , + color .tl_set:N = \l_chemmacros_orbital_s_color_tl + } + +\cs_new_nopar:Npn \chemmacros_orbital_s_draw:n #1 + { + \IfNoValueF { #1 } { \keys_set:nn { chemmacros / orbital / s } { #1 } } + \bool_if:NTF \l_chemmacros_orbital_s_phase_bool + { + \tl_if_in:NnTF \l_chemmacros_orbital_s_color_tl { ! } + { + \tl_set:Nn \l_chemmacros_orbital_s_phase_color_tl + { \tl_use:N \l_chemmacros_orbital_s_color_tl } + } + { + \tl_set:Nn \l_chemmacros_orbital_s_phase_color_tl + { \tl_use:N \l_chemmacros_orbital_s_color_tl ! 90 } + } + } + { + \tl_set:Nn \l_chemmacros_orbital_s_phase_color_tl + { black ! 5 } + } + \chemmacros_tikz_picture:xn{ \chemmacros_orbital_options: } + { + \chemmacros_tikz_shade:f { ball~color = \l_chemmacros_orbital_s_phase_color_tl } + (0,0) circle (\l_chemmacros_orbital_s_scale_tl * .6em) ; + } + } + +% --------------------------------------------------------------------------- % +% p-orbitals +\cs_new_nopar:Npn \chemmacros_orbital_type_p: + { + \bool_set_false:N \l_chemmacros_orbital_type_s_bool + \bool_set_true:N \l_chemmacros_orbital_type_p_bool + \bool_set_false:N \l_chemmacros_orbital_type_sp_bool + \bool_set_false:N \l_chemmacros_orbital_type_sptwo_bool + \bool_set_false:N \l_chemmacros_orbital_type_spthree_bool + } + +\keys_define:nn { chemmacros / orbital / p } + { + phase .choice: , + phase / + .code:n = { \bool_set_true:N \l_chemmacros_orbital_p_phase_bool } , + phase / - .code:n = { \bool_set_false:N \l_chemmacros_orbital_p_phase_bool } , + scale .tl_set:N = \l_chemmacros_orbital_p_scale_tl , + angle .fp_set:N = \l_chemmacros_orbital_angle_fp , + color .tl_set:N = \l_chemmacros_orbital_p_color_tl , + half .bool_set:N = \l_chemmacros_orbital_p_half_bool , + half .default:n = true + } + +\cs_new_nopar:Npn \chemmacros_orbital_p_draw:n #1 + { + \IfNoValueF { #1 } { \keys_set:nn { chemmacros / orbital / p } { #1 } } + \bool_if:NTF \l_chemmacros_orbital_p_phase_bool + { + \tl_if_in:NnTF \l_chemmacros_orbital_p_color_tl { ! } + { + \tl_set:Nn \l_chemmacros_orbital_p_pphase_color_tl + { \tl_use:N \l_chemmacros_orbital_p_color_tl } + } + { + \tl_set:Nn \l_chemmacros_orbital_p_pphase_color_tl + { \tl_use:N \l_chemmacros_orbital_p_color_tl ! 90 } + } + \tl_set:Nn \l_chemmacros_orbital_p_mphase_color_tl + { black ! 5 } + + } + { + \tl_if_in:NnTF \l_chemmacros_orbital_p_color_tl { ! } + { + \tl_set:Nn \l_chemmacros_orbital_p_mphase_color_tl + { \tl_use:N \l_chemmacros_orbital_p_color_tl } + } + { + \tl_set:Nn \l_chemmacros_orbital_p_mphase_color_tl + { \tl_use:N \l_chemmacros_orbital_p_color_tl ! 90 } + } + \tl_set:Nn \l_chemmacros_orbital_p_pphase_color_tl + { black ! 5 } + } + \chemmacros_tikz_picture:xn { \chemmacros_orbital_options: } + { + \chemmacros_tikz_shadedraw:f { draw = \l_chemmacros_orbital_p_pphase_color_tl , ball~color = \l_chemmacros_orbital_p_pphase_color_tl } + (0,0) .. controls + ++(- \l_chemmacros_orbital_p_scale_tl * 2em,\l_chemmacros_orbital_p_scale_tl * 2em) and + ++(\l_chemmacros_orbital_p_scale_tl * 2em,\l_chemmacros_orbital_p_scale_tl * 2em) + .. (0,0); + \bool_if:NF \l_chemmacros_orbital_p_half_bool + { + \chemmacros_tikz_shadedraw:f { draw = \l_chemmacros_orbital_p_mphase_color_tl , ball~color = \l_chemmacros_orbital_p_mphase_color_tl } + (0,0) .. controls + ++(- \l_chemmacros_orbital_p_scale_tl * 2em,- \l_chemmacros_orbital_p_scale_tl * 2em) and + ++(\l_chemmacros_orbital_p_scale_tl * 2em,- \l_chemmacros_orbital_p_scale_tl * 2em) + .. (0,0); + } + } + } + +% --------------------------------------------------------------------------- % +% sp-orbitals +\cs_new_nopar:Npn \chemmacros_orbital_type_sp: + { + \bool_set_false:N \l_chemmacros_orbital_type_s_bool + \bool_set_false:N \l_chemmacros_orbital_type_p_bool + \bool_set_true:N \l_chemmacros_orbital_type_sp_bool + \bool_set_false:N \l_chemmacros_orbital_type_sptwo_bool + \bool_set_false:N \l_chemmacros_orbital_type_spthree_bool + } + +\keys_define:nn { chemmacros / orbital / sp } + { + phase .choice: , + phase / + .code:n = { \bool_set_true:N \l_chemmacros_orbital_sp_phase_bool } , + phase / - .code:n = { \bool_set_false:N \l_chemmacros_orbital_sp_phase_bool } , + scale .tl_set:N = \l_chemmacros_orbital_sp_scale_tl , + angle .fp_set:N = \l_chemmacros_orbital_angle_fp , + color .tl_set:N = \l_chemmacros_orbital_sp_color_tl + } + +\cs_new_nopar:Npn \chemmacros_orbital_sp_draw:n #1 + { + \IfNoValueF { #1 } { \keys_set:nn { chemmacros / orbital / sp } { #1 } } + \bool_if:NTF \l_chemmacros_orbital_sp_phase_bool + { + \tl_if_in:NnTF \l_chemmacros_orbital_sp_color_tl { ! } + { + \tl_set:Nn \l_chemmacros_orbital_sp_pphase_color_tl + { \tl_use:N \l_chemmacros_orbital_sp_color_tl } + } + { + \tl_set:Nn \l_chemmacros_orbital_sp_pphase_color_tl + { \tl_use:N \l_chemmacros_orbital_sp_color_tl ! 90 } + } + \tl_set:Nn \l_chemmacros_orbital_sp_mphase_color_tl + { black ! 5 } + + } + { + \tl_if_in:NnTF \l_chemmacros_orbital_sp_color_tl { ! } + { + \tl_set:Nn \l_chemmacros_orbital_sp_mphase_color_tl + { \tl_use:N \l_chemmacros_orbital_sp_color_tl } + } + { + \tl_set:Nn \l_chemmacros_orbital_sp_mphase_color_tl + { \tl_use:N \l_chemmacros_orbital_sp_color_tl ! 90 } + } + \tl_set:Nn \l_chemmacros_orbital_sp_pphase_color_tl + { black ! 5 } + } + \chemmacros_tikz_picture:xn { \chemmacros_orbital_options: } + { + \chemmacros_tikz_shadedraw:f { draw = \l_chemmacros_orbital_sp_pphase_color_tl , ball~color = \l_chemmacros_orbital_sp_pphase_color_tl } + (0,0) .. controls + ++(- \l_chemmacros_orbital_sp_scale_tl * 2em,\l_chemmacros_orbital_sp_scale_tl * 2em) and + ++(\l_chemmacros_orbital_sp_scale_tl * 2em,\l_chemmacros_orbital_sp_scale_tl * 2em) + .. (0,0); + \chemmacros_tikz_shadedraw:f { draw = \l_chemmacros_orbital_sp_mphase_color_tl , ball~color = \l_chemmacros_orbital_sp_mphase_color_tl } + (0,0) .. controls + ++(- \l_chemmacros_orbital_sp_scale_tl * .6em,- \l_chemmacros_orbital_sp_scale_tl * .6em) and + ++(\l_chemmacros_orbital_sp_scale_tl * .6em,- \l_chemmacros_orbital_sp_scale_tl * .6em) + .. (0,0); + } + } + +% --------------------------------------------------------------------------- % +% sp2-orbitals +\cs_new_nopar:Npn \chemmacros_orbital_type_sptwo: + { + \bool_set_false:N \l_chemmacros_orbital_type_s_bool + \bool_set_false:N \l_chemmacros_orbital_type_p_bool + \bool_set_false:N \l_chemmacros_orbital_type_sp_bool + \bool_set_true:N \l_chemmacros_orbital_type_sptwo_bool + \bool_set_false:N \l_chemmacros_orbital_type_spthree_bool + } + +\keys_define:nn { chemmacros / orbital / sp2 } + { + phase .choice: , + phase / + .code:n = { \bool_set_true:N \l_chemmacros_orbital_sptwo_phase_bool } , + phase / - .code:n = { \bool_set_false:N \l_chemmacros_orbital_sptwo_phase_bool } , + scale .tl_set:N = \l_chemmacros_orbital_sptwo_scale_tl , + angle .fp_set:N = \l_chemmacros_orbital_angle_fp , + color .tl_set:N = \l_chemmacros_orbital_sptwo_color_tl + } + +\cs_new_nopar:Npn \chemmacros_orbital_sptwo_draw:n #1 + { + \IfNoValueF { #1 } { \keys_set:nn { chemmacros / orbital / sp2 } { #1 } } + \bool_if:NTF \l_chemmacros_orbital_sptwo_phase_bool + { + \tl_if_in:NnTF \l_chemmacros_orbital_sptwo_color_tl { ! } + { + \tl_set:Nn \l_chemmacros_orbital_sptwo_pphase_color_tl + { \tl_use:N \l_chemmacros_orbital_sptwo_color_tl } + } + { + \tl_set:Nn \l_chemmacros_orbital_sptwo_pphase_color_tl + { \tl_use:N \l_chemmacros_orbital_sptwo_color_tl ! 90 } + } + \tl_set:Nn \l_chemmacros_orbital_sptwo_mphase_color_tl + { black ! 5 } + + } + { + \tl_if_in:NnTF \l_chemmacros_orbital_sptwo_color_tl { ! } + { + \tl_set:Nn \l_chemmacros_orbital_sptwo_mphase_color_tl + { \tl_use:N \l_chemmacros_orbital_sptwo_color_tl } + } + { + \tl_set:Nn \l_chemmacros_orbital_sptwo_mphase_color_tl + { \tl_use:N \l_chemmacros_orbital_sptwo_color_tl ! 90 } + } + \tl_set:Nn \l_chemmacros_orbital_sptwo_pphase_color_tl + { black ! 5 } + } + \chemmacros_tikz_picture:xn { \chemmacros_orbital_options: } + { + \chemmacros_tikz_shadedraw:f { draw = \l_chemmacros_orbital_sptwo_pphase_color_tl , ball~color = \l_chemmacros_orbital_sptwo_pphase_color_tl } + (0,0) .. controls + ++(- \l_chemmacros_orbital_sptwo_scale_tl * 2em,\l_chemmacros_orbital_sptwo_scale_tl * 2em) and + ++(\l_chemmacros_orbital_sptwo_scale_tl * 2em,\l_chemmacros_orbital_sptwo_scale_tl * 2em) + .. (0,0); + \chemmacros_tikz_shadedraw:f { draw = \l_chemmacros_orbital_sptwo_mphase_color_tl , ball~color = \l_chemmacros_orbital_sptwo_mphase_color_tl } + (0,0) .. controls + ++(- \l_chemmacros_orbital_sptwo_scale_tl * .8em,- \l_chemmacros_orbital_sptwo_scale_tl * .8em) and + ++(\l_chemmacros_orbital_sptwo_scale_tl * .8em,- \l_chemmacros_orbital_sptwo_scale_tl * .8em) + .. (0,0); + } + } + +% --------------------------------------------------------------------------- % +% sp3-orbitals +\cs_new_nopar:Npn \chemmacros_orbital_type_spthree: + { + \bool_set_false:N \l_chemmacros_orbital_type_s_bool + \bool_set_false:N \l_chemmacros_orbital_type_p_bool + \bool_set_false:N \l_chemmacros_orbital_type_sp_bool + \bool_set_false:N \l_chemmacros_orbital_type_sptwo_bool + \bool_set_true:N \l_chemmacros_orbital_type_spthree_bool + } + +\keys_define:nn { chemmacros / orbital / sp3 } + { + phase .choice: , + phase / + .code:n = { \bool_set_true:N \l_chemmacros_orbital_spthree_phase_bool } , + phase / - .code:n = { \bool_set_false:N \l_chemmacros_orbital_spthree_phase_bool } , + scale .tl_set:N = \l_chemmacros_orbital_spthree_scale_tl , + angle .fp_set:N = \l_chemmacros_orbital_angle_fp , + color .tl_set:N = \l_chemmacros_orbital_spthree_color_tl + } + +\cs_new_nopar:Npn \chemmacros_orbital_spthree_draw:n #1 + { + \IfNoValueF { #1 } { \keys_set:nn { chemmacros / orbital / sp3 } { #1 } } + \bool_if:NTF \l_chemmacros_orbital_spthree_phase_bool + { + \tl_if_in:NnTF \l_chemmacros_orbital_spthree_color_tl { ! } + { + \tl_set:Nn \l_chemmacros_orbital_spthree_pphase_color_tl + { \tl_use:N \l_chemmacros_orbital_spthree_color_tl } + } + { + \tl_set:Nn \l_chemmacros_orbital_spthree_pphase_color_tl + { \tl_use:N \l_chemmacros_orbital_spthree_color_tl ! 90 } + } + \tl_set:Nn \l_chemmacros_orbital_spthree_mphase_color_tl + { black ! 5 } + + } + { + \tl_if_in:NnTF \l_chemmacros_orbital_spthree_color_tl { ! } + { + \tl_set:Nn \l_chemmacros_orbital_spthree_mphase_color_tl + { \tl_use:N \l_chemmacros_orbital_spthree_color_tl } + } + { + \tl_set:Nn \l_chemmacros_orbital_spthree_mphase_color_tl + { \tl_use:N \l_chemmacros_orbital_spthree_color_tl ! 90 } + } + \tl_set:Nn \l_chemmacros_orbital_spthree_pphase_color_tl + { black ! 5 } + } + \chemmacros_tikz_picture:xn { \chemmacros_orbital_options: } + { + \chemmacros_tikz_shadedraw:f { draw = \l_chemmacros_orbital_spthree_pphase_color_tl , ball~color = \l_chemmacros_orbital_spthree_pphase_color_tl } + (0,0) .. controls + ++(- \l_chemmacros_orbital_spthree_scale_tl * 2em,\l_chemmacros_orbital_spthree_scale_tl * 2em) and + ++(\l_chemmacros_orbital_spthree_scale_tl * 2em,\l_chemmacros_orbital_spthree_scale_tl * 2em) + .. (0,0); + \chemmacros_tikz_shadedraw:f { draw = \l_chemmacros_orbital_spthree_mphase_color_tl , ball~color = \l_chemmacros_orbital_spthree_mphase_color_tl } + (0,0) .. controls + ++(- \l_chemmacros_orbital_spthree_scale_tl * 1em,- \l_chemmacros_orbital_spthree_scale_tl * 1em) and + ++(\l_chemmacros_orbital_spthree_scale_tl * 1em,- \l_chemmacros_orbital_spthree_scale_tl * 1em) + .. (0,0); + } + } + +% --------------------------------------------------------------------------- % +% main command +\keys_define:nn { chemmacros / orbital } + { + overlay .bool_set:N = \l_chemmacros_orbital_overlay_bool , + overlay .default:n = true , + opacity .code:n = + { + \fp_compare:nTF { #1 = 1 } + { \bool_set_false:N \l_chemmacros_orbital_opacity_bool } + { \bool_set_true:N \l_chemmacros_orbital_opacity_bool } + \fp_set:Nn \l_chemmacros_orbital_opacity_fp { #1 } + } + } + +\keys_define:nn { chemmacros / orbital / type } + { + s .code:n = { \chemmacros_orbital_type_s: } , + p .code:n = { \chemmacros_orbital_type_p: } , + sp .code:n = { \chemmacros_orbital_type_sp: } , + sp2 .code:n = { \chemmacros_orbital_type_sptwo: } , + sp3 .code:n = { \chemmacros_orbital_type_spthree: } + } + +\NewDocumentCommand \orbital { o m } + { + \group_begin: + \keys_set:nn { chemmacros / orbital / type } { #2 } + \bool_if:NT \l_chemmacros_orbital_type_s_bool + { \chemmacros_orbital_s_draw:n { #1 } } + \bool_if:NT \l_chemmacros_orbital_type_p_bool + { \chemmacros_orbital_p_draw:n { #1 } } + \bool_if:NT \l_chemmacros_orbital_type_sp_bool + { \chemmacros_orbital_sp_draw:n { #1 } } + \bool_if:NT \l_chemmacros_orbital_type_sptwo_bool + { \chemmacros_orbital_sptwo_draw:n { #1 } } + \bool_if:NT \l_chemmacros_orbital_type_spthree_bool + { \chemmacros_orbital_spthree_draw:n { #1 } } + \group_end: + } + +% --------------------------------------------------------------------------- % +% setup +\NewDocumentCommand \chemsetup { o m } + { + \IfNoValueTF { #1 } + { \keys_set:nn { chemmacros } { #2 } } + { \keys_set:nn { chemmacros / #1 } { #2 } } +% \tex_unskip:D + } + +% --------------------------------------------------------------------------- % +% load old definitions: +\bool_if:NT \l_chemmacros_version_one_bool + { + \input { chemmacros-version1 . cfg } + } + +\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 +% --------------------------------------------------------------------------- % \ No newline at end of file -- cgit v1.2.3