# Using \chemabove/\chembelow with \vflipnext

I have a molecule with a \chemabove command in it, and I'd like to mirror it vertically with \vflipnext. Everything is flipped just fine except for the atom positioned with the \chemabove command, which just keeps its position above the other atom. Is there a way to have this atom flipped as well?

MWE:

\documentclass{article}
\usepackage{chemfig}

\begin{document}
% Dimethylamine
\definesubmol{mol}{%
-[::30]\chemabove{N}{H}-[::-60]%
}

% Normal orientation
\chemfig{!{mol}}
\par
% Flipped orientation with wrongly positioned H
\vflipnext
\chemfig{!{mol}}
\end{document}


## 1 Answer

The molecules are drawn differently depending on the value of \CF@split@state which usually is 0. \hflipnext sets \CF@split@state to 1 and \vflipnext sets \CF@split@state to 2 for the next molecule only. It is reset to 0 during the parsing of the molecule.

Below I define the commands \chemflipbelow and \chemflipabove that default to \chembelow and \chemabove but change roles if \CF@split@state is set to 2:

\documentclass{article}
\usepackage{chemfig}

\makeatletter
\def\chemflipabove{%
\ifnum\CF@split@state=\tw@
\expandafter\chembelow
\else
\expandafter\chemabove
\fi
}
\def\chemflipbelow{%
\ifnum\CF@split@state=\tw@
\expandafter\chemabove
\else
\expandafter\chembelow
\fi
}
\makeatother

\definesubmol{mol}{%
-[::30]\chemflipabove{N}{H}-[::-60]%
}

\begin{document}

\chemfig{!{mol}}

\vflipnext\chemfig{!{mol}}\par\vskip5ex

\chemfig{R-\chemflipabove{C}{H}-\chemflipbelow{C}{H}-R}\par\vskip5ex

\vflipnext\chemfig{R-\chemflipabove{C}{H}-\chemflipbelow{C}{H}-R}

\end{document}


• Thanks! As with 90% of your chemfig answers, I wonder why they aren't the package default already. :) – runiq Jul 30 '13 at 8:50
• I (almost) never use \vflipnext so this has never been an issue for me :) – clemens Jul 30 '13 at 8:52