1

Sometimes chemists want to signify that something is attached to a C-ring without specifying the exact position to which it is bound, for example because it's random. Instead they to something like

this

(see the R^1). This could also be attached to the center of the ring or the "aromatic circle" in the bottom left. Can this be done in chemfig?

1 Answers1

4

(Since chemfig v1.56, center of a ring can be easily referenced as a node name. See update near the end of this answer.)

Yes chemfig can do this, with some tricks (or advanced usage?).

\documentclass{article}
\usepackage{chemfig}

\begin{document} \chemfig{6(-=-=-=)} \qquad \chemfig{6(-=(-[:150])-=-=)} \qquad \chemfig{6(-=(-[:150]-[:120]-[:120]R^1)-=-=)} \qquad \chemfig{6(-=(-[:150]-[:120,.5]-[:120]R^1)-=-=)} \qquad \chemfig{*6(-=(-[:150,,,,white]-[:120,.5,,,draw=none]-[:120]R^1)-=-=)}

\begin{enumerate} \item Start. \item Draw a bond to center with syntax \verb|-[<angle>]|. \item Draw two more bonds to get to the right angle, and add desired atom. \item Adjust bond length using syntax \verb|-[<angle>,<length scale>]|. \item Hide intermediate bonds by specifying a white drawing color, using syntax \verb|-[<angle>,<length scale>,,,<tikz code>]|. \end{enumerate} \end{document}

enter image description here

Update

In the following example, an arc inside ring is named A, so the center of ring is (A.center). I do not know how to draw a chemfig bond starting at arbitrary coordinate, so I use insert path.

Limitation: Angle needs to be explicitly specified, like the 36 in (36:5pt).

\documentclass{article}
\usepackage{chemfig}

\usetikzlibrary{calc}

\begin{document} \chemfig{% **[,,draw=none, local bounding box=A]% 5(-----% [,,,,{insert path={ ([shift={(36:5pt)}]A.center) -- +(36:1cm) node[anchor=center, right] {X} }}]% )% } \end{document}

enter image description here

Update 2

With chemfig v1.56 (or newer), the center of ring can be referred by node name centrecycle<n>, see the chemfig manual, sec. 12.6 for more detail. Thanks to Christian Tellechea, author of chemfig.

The following example contains two \chemfig drawings.

  • In the first one, drawing commands among cycle center is added by the following \chemmove, which won't extend the bounding box of previous \chemfig and might overlap with surrounding text.
  • The second one moves those drawing commands among cycle center to tikz option execute at end picture, which do extends the bounding box.
\documentclass{article}
\usepackage{chemfig}
\usepackage{lipsum}

\tikzset{ % helper style show bounding box/.style={ execute at end picture={ \draw[blue, #1] (current bounding box.north west) rectangle (current bounding box.south east); } } }

\begin{document} \lipsum[23]

Example from \verb|chemfig| manual, sec.@ 12.6. Note \verb|\chemmove| won't extend the bounding box.

text \chemfig[chemfig style={show bounding box}]{*6(-=-=-=)}% \chemmove{ \node[at=(cyclecenter1)] {.+} node[at=(cyclecenter1), shift=(120:1.75cm)] (end) {\printatom{R^1}}; \draw[-, shorten <=.5cm] (cyclecenter1) -- (end); } text

Using \verb|execute at end picture|, the bounding box is correctly extended.

\tikzset{ cycle center staff/.style={ execute at end picture={ \path (cyclecenter1) node[anchor=center] {.+} +(120:1.75cm) node[inner sep=2pt] (end) {\printatom{R^1}}; \draw (cyclecenter1) +(120:.5cm) -- (end); } } }

text \chemfig[chemfig style={ cycle center staff, show bounding box }]{*6(-=-=-=)} text

\lipsum[23] \end{document}

enter image description here

Update 3

To simplify user input, a new command \chempremove is defined. With this new command,

\chempremove{<tikz drawing code>}
\chemfig{...}

is equivalent to

\chemfige[chemfig style={execute at end picture={<tikz drawing code>}}]{...}

Full implementation:

\documentclass{article}
\usepackage{chemfig}
\usepackage{lipsum}
\usepackage{xpatch}

\tikzset{ % helper style show bounding box/.style={ execute at end picture={ \draw[blue, #1] (current bounding box.north west) rectangle (current bounding box.south east); } } }

% new command \chempremove{<tikz code executed at end picture>} \catcode`_=11\relax

\defKV[chemfig]{% at end picture = \def\CF_atendpic_once{#1}, at end picture append = \CF_addtomacro\CF_atendpic_once{#1} } \setKVdefault[chemfig]{% at end picture = {} }

\newcommand{\chempremove}[1]{% \setKV[chemfig]{at end picture append={#1}}% \ignorespaces }

\xpatchcmd\CF_chemfigb {baseline,} {baseline,% execute at end picture={\unexpanded\expandafter{\CF_atendpic_once}},} {}{\fail}

\xpatchcmd\CF_chemfigb {\let\CF_flipstate\CF_zero} {\let\CF_flipstate\CF_zero\let\CF_atendpic_once\empty} {}{\fail}

\catcode`_=8\relax

\begin{document} \lipsum[23]

Example from \verb|chemfig| manual, sec.@ 12.6. Note \verb|\chemmove| won't extend the bounding box.

\chempremove{ % show bounding box \draw[blue] (current bounding box.north west) rectangle (current bounding box.south east); }

text \chemfig[chemfig style={show bounding box}]{*6(-=-=-=)}% \chemmove{ \node[at=(cyclecenter1)] {.+} node[at=(cyclecenter1), shift=(120:1.75cm)] (end) {\printatom{R^1}}; \draw[-, shorten <=.5cm] (cyclecenter1) -- (end); } text

Using \verb|\chempremove|, the bounding box is correctly extended.

\chempremove{ \path (cyclecenter1) node[anchor=center] {.+} +(120:1.75cm) node[inner sep=2pt] (end) {\printatom{R^1}}; \draw (cyclecenter1) +(120:.5cm) -- (end); % show bounding box \draw[blue] (current bounding box.north west) rectangle (current bounding box.south east); }

text \chemfig{*6(-=-=-=)} text

\lipsum[23]

\end{document}

enter image description here

muzimuzhi Z
  • 26,474