8

For my Thesis I use the chemmacros Package to typeset my analysis. Unfortunatetly it is common in our group to have a different position when talking about H and C-NMRs. At the moment I have the following output, when compiling the code below:

1H-NMR: δ = 123 (H-10) 13C-NMR: δ = 123 (C-10)

What I would like to have is something like

1H-NMR: δ = 123 (10-H) 13C-NMR: δ = 123 (C-10)

I found that with version 4.3 you are able to define the atom position with the argument \@firstofone, but even with this information I was not able to achieve the goal, since I coudn't quite figure out what kind of argument this is. I also tried the solution proposed here Chemmacros Experimental Environment Superscript

But I also couldnt get the desired output. Thanks in advance!

\documentclass{article}

\usepackage{chemmacros}

\chemsetup[nmr]{use-equal,format=\bfseries,pos-number=side}

\DeclareChemNMR\HNMR{1,H}
\DeclareChemNMR\CNMR{13,C}

\chemsetup[nmr]{use-equal,format=\bfseries,pos-number=side}

\begin{document}

\begin{experimental}

  \HNMR \val{123} (\pos{10})    
  \CNMR \val{123} (\pos{10})

\end{experimental}

\end{document}
  • 1
    Hi and welcome to teX.SX. Do want this to aplly to only H? – Johannes_B Sep 15 '14 at 9:08
  • 2
    Welcome to TeX.sx! This is not implemented in chemmacros as of now. I'll post an answer how to solve this as soon as I have the time. – clemens Sep 15 '14 at 9:10
  • Thanks for welcoming me, and yes for the H would be sufficient. The reasoning behind is, that H's are attached to the numbers whereas the C's are the numbers in the molecule. @cgnieder Thanks for your reply too, and if I put it in two environments, would that be possible then? – danleich Sep 15 '14 at 9:19
8

For this to work you'll need to redefine \chemmacros_nmr_position:n. Below I propose a solution that checks if the current nucleus is H and typesets the position accordingly. (But it leaves the pos-number option to have no effect any more.)

\documentclass{article}

\usepackage{chemmacros}

\NewChemNMR\HNMR{1,H}
\NewChemNMR\CNMR{13,C}

\chemsetup[nmr]{use-equal,format=\bfseries,pos-number=side}

\ExplSyntaxOn
\tl_const:Nn \c_danleich_hydrogen_tl {H}
\cs_set_protected:Npn \chemmacros_nmr_position:n #1
  {
    \tl_if_eq:NNTF
      \g__chemmacros_nmr_element_tl
      \c_danleich_hydrogen_tl
      {
        \__chemmacros_nmr_position:n {#1}
        -
        \chemmacros_chemformula:V \g__chemmacros_nmr_element_tl
      }
      {
        \chemmacros_chemformula:V \g__chemmacros_nmr_element_tl
        -
        \__chemmacros_nmr_position:n {#1}
      }
  }
\ExplSyntaxOff

\begin{document}

\begin{experimental}
  \HNMR \val{123} (\pos{10})    
  \CNMR \val{123} (\pos{10})
\end{experimental}

\end{document}

enter image description here

BTW: if you always put parentheses around \pos you could include them in the definition:

\ExplSyntaxOn
\tl_const:Nn \c_danleich_hydrogen_tl {H}
\cs_set_protected:Npn \chemmacros_nmr_position:n #1
  {
    \tl_if_eq:NNTF
      \g__chemmacros_nmr_element_tl
      \c_danleich_hydrogen_tl
      {
        (\__chemmacros_nmr_position:n {#1}
        -
        \chemmacros_chemformula:V \g__chemmacros_nmr_element_tl)
      }
      {
        (\chemmacros_chemformula:V \g__chemmacros_nmr_element_tl
        -
        \__chemmacros_nmr_position:n {#1})
      }
  }
\ExplSyntaxOff

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.