# Modify part of an environment from a package: experimental environment of chemmacros

General Question: How do I use an environment from a package and modify one or more commands but keep all the functionality of the the others? Sorry if I should know that this isn't possible or viable and it's just easier to make the environments yourself from scratch (which would be beyond my skills).

Specific question: How do I use the experimental environment from chemmacros but modify for example the \NMR, \pos and maybe \J commands? And is it possible to still make \\#{} work with a renewed \NMR command?

For our reports we need to present NMR data like shown in the picture.

Renewing the \NMR command works well for use in the experimental environment and outside. But renewing the other commands doesn't work. And just \newcommand for example for \J{}{}{} works but only outside the environment.

\documentclass[12pt,a4paper]{scrartcl}
\usepackage{textgreek}
\usepackage{siunitx}
\usepackage{chemmacros}
\chemsetup{modules={all},greek=textgreek}

\renewcommand{\NMR}[6]{\noindent\textbf{$\mathbf{^{#1}#2}$-NMR (#3)} (#4~MHz, #5~K, \ch{#6}, $\delta/\si{ppm}$):}   %\nmr{MZ}{Kern}{Nummer}{Frequenz}{Temperatur}{Lsm}
\renewcommand{\J}[3]{$^{{\textsl{##1}}}J_{\mathrm{##2}} = ##3~\mathrm{Hz}$} %\J{Bindungen}{koppelnde Kerne}{Frequenz}
\renewcommand{\pos}[1]{\textbf{##1}}    %Zuordnung

\begin{document}
\begin{experimental}
\NMR{1}{H}{prakt\_AC.999}{400}{298}{CDCl3} \val{1.11--2.22} (d, 4 H, \J{4}{HH}{6.66}, \pos{7})
\end{experimental}
\end{document}


And renewing the environment "deletes" all the other commands, like for example the \val{} command or the \J command.

\renewenvironment{experimental}{
\renewcommand{\NMR}[6]{\noindent\textbf{$\mathbf{^{##1}##2}$-NMR (##3)} (##4~MHz, ##5~K, \ch{##6}, $\delta/\si{ppm}$):} %\nmr{MZ}{Kern}{Nummer}{Frequenz}{Temperatur}{Lsm}
\renewcommand{\pos}[1]{\textbf{##1}}    %Zuordnung
\renewcommand{\#}[1]{\textbf{##1}}  %Anzahl Kerne
}{}

• don't ask me why they want the assignment in bold, which is totally not the norm and why they want numbers slanted for coupling bonds; they luckily didnt care for that yet so i just used the already provided \J(){} command with nonslanted numbers – Wulfram May 13 '17 at 17:04
• Of course, you have to store the old definition of experimental first before if you still want to have its basic behaviour. And of course, the redefinitions are breaking the old style – user31729 May 13 '17 at 17:24
• For specific customizations of bold etc. output of the NMR etc. commands see section 7 of current chemmacros, p. 55 f. – user31729 May 13 '17 at 17:32
• »How do I use an environment from a package and modify one or more commands but keep all the functionality of the the others?« – an XY problem! Your real question probably is »How do I change the layout of all the different parts from chemmacros' experimental environment?« – cgnieder May 14 '17 at 12:28

The macros \pos, \J, and \# are set up through the experimental environment. They don't have a meaning outside -- at least not from chemmacros. For each of them there exists an internal command which in case of pos can easily be redefined as the example below shows.

Here's a way to get the desired output (apart from the italic nuclei subscript – I suspect the example has this rather by chance than on purpose…)

\documentclass[12pt,a4paper]{scrartcl}
\usepackage{textgreek}
\usepackage{siunitx}
\usepackage{chemmacros}

\chemsetup{
modules = spectroscopy ,
greek   = textgreek ,
}

\ExplSyntaxOn
\chemmacros_define_keys:nn {spectroscopy}
{ atom-number-space .skip_set:N = \l__chemmacros_nmr_space_skip }
\cs_set_protected:Npn \chemmacros_nmr_position:n #1
{ \textbf {#1} }
\ExplSyntaxOff

\chemsetup{
spectroscopy/format = \bfseries ,
spectroscopy/coupling-pos = sub ,
spectroscopy/atom-number-space = 0pt
}

\begin{document}

\begin{experimental}
\data{\NMR*{1,H} (ac\_prakt 12345)}
(\SI{250}{\mega\hertz}, \SI{298}{\kelvin}, \ch{CDCl3}, $\delta$/ppm):
\val{8.71} (d, \#{1}, \J(3;HH){4.4}, \pos{2})
\val{7.66} (d, \#{1}, \J(3;HH){7.7}, \pos{4})
\val{7.38} (dd, \#{1}, \J(3;HH){4.5}, \J(3;HH){7.8}, \pos{3})
\val{3.03} (t, \#{2}, \J(3;HH){5.99}, \pos{8})
\val{2.81} (t, \#{2}, \J(3;HH){5.98}, \pos{10})
\val{2.2} (p, \#{2}, \J(3;HH){6.11}, \pos{9})
\end{experimental}

\end{document}


• Tyvm! I hoped it's somehow possible with simple renewcommands... However, when i copy+paste your code and compile it I get errors. Line 12: ! Undefined control sequence. \chemmacros_define_keys:nn Line 12: ! LaTeX Error: Missing \begin{document}.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... \chemmacros_define_keys:nn {s Line 12: ! Undefined control sequence. ...skip_set:N = \l__chemmacros_nmr_space_skip Line 22: ! LaTeX error: "kernel/key-unknown"!! The key 'chemmacros/spectroscopy/atom-number-space' is unknown ... – Wulfram May 14 '17 at 16:23
• @Wulfram Then you probably have an outdated version and should update your TeX distribution… – cgnieder May 14 '17 at 16:48
• true, after running the MikTeX updater it works; sorry for bothering with that – Wulfram May 14 '17 at 19:27
• Where do I read about how to do those modifications that go beyond of what is in the documentation? (like here how to change the \pos{} command). All I did till now is using packages with the provided options and the occasional newcommands. – Wulfram May 14 '17 at 19:37
• @Wulfram the option atom-number-space is documented but didn't work on my system – I need to check the sources. I am thinking of adding more options for customization. Regarding redefining code level macros – in an ideal world that wouldn't be necessary and at least for this question I'll add enough options. – cgnieder May 14 '17 at 19:42