# Chemfig multiple brackets on the same bond

I'd like to draw the following copolymer structure using \chemfig.

But it turns out that I can't put the right bracket and the next left one within the same bond. All I found on the internet were some workarounds which I quite didn't understand.

The closest I got was

\documentclass{article}
\usepackage{chemfig}

\begin{document}

\newcommand\setpolymerdelim[2]{\def\delimleft{#1}\def\delimright{#2}}
\def\makebraces[#1,#2]#3#4#5{%
\edef\delimhalfdim{\the\dimexpr(#1+#2)/2}%
\edef\delimvshift{\the\dimexpr(#1-#2)/2}%
\chemmove{%
\node[at=(#4),yshift=(\delimvshift)]
{$\left\delimleft\vrule height\delimhalfdim depth\delimhalfdim width0pt\right.$};%
\node[at=(#5),yshift=(\delimvshift)]
{$\left.\vrule height\delimhalfdim depth\delimhalfdim width0pt\right\delimright_{\rlap{$\scriptstyle#3$}}$};}}
\setpolymerdelim()

\chemfig{H_2N-[:30](-[:90])-[:-30]-[@{L1,.75}:30]O-[:-30]-[:30](-[:90])-[@{R1}:-30]O(@{L2})-[:30]-[:-30]-[@{R2}:30]@{L3}O-[:-30]-[:30](-[:90])-[@{R3}:-30]NH_2}
\makebraces[20pt,20pt]{\!\!\!x}{L1}{R1}
\makebraces[20pt,20pt]{\!\!\!y}{L2}{R2}
\makebraces[20pt,20pt]{\!\!\!z}{L3}{R3}

\end{document}


which gives

As you see I can't displace the brackets that are on the Oxygen atom. I'd care to get everything lined up as well.

Thanks for any help!

EDIT

After checking How to draw parentheses inside chemfig as Bobyandbob told me so, I adapted the code a bit and got closer to what I want, but now I need the brackets to be bigger.

\documentclass{article}
\usepackage{chemfig}

\begin{document}

\def\L1{\llap{$\left(\strut\right.$\kern2pt }}
\def\Rx{\rlap{$\kern60pt \left.\strut\right)_x$}}
\def\Ry{\rlap{$\kern60pt \left.\strut\right)_y$}}
\def\Rz{\rlap{$\kern60pt \left.\strut\right)_z$}}

\chemfig{H_2N-[:30](-[:90])-[:-30]-[:30] \L1 \Rx O-[:-30]-[:30](-[:90])-[:-30] \L1 \Ry O-[:30]-[:-30]-[:30] \L1 \Rz O-[:-30]-[:30](-[:90])-[:-30]NH_2}

\end{document}


Any suggestions?

• Welcome to TeX.SX! Have you checked How to draw parentheses inside chemfig? I think it solves your problem. – Bobyandbob Aug 25 '18 at 11:37
• Hey, thanks! I just did, but still I can't get it done. The syntax seems to be a bit more clear though. The problem is putting two brackets in the same bond. – Lucas Vieira Aug 25 '18 at 13:00

I ended up finding a way of getting it round.

\documentclass{article}
\usepackage{chemfig}

\begin{document}

\def\L{\llap{$\left(\rule{0pt}{20pt}\right.$\kern0pt }}
\def\Ly{\llap{$\left(\rule{0pt}{20pt}\right.$\kern-78pt }}
\def\Rx{\rlap{$\kern60pt \left.\rule{-2pt}{20pt}\right)_x$}}
\def\Ry{\rlap{$\kern140pt \left.\rule{-2pt}{20pt}\right)_y$}}
\def\Rz{\rlap{$\kern60pt \left.\rule{-2pt}{20pt}\right)_z$}}

\chemfig{H_2N-[:30](-[:90])-[:-30]-[:30] \L \Rx \Ly \Ry O-[:-30]-[:30](-[:90])-[:-30]O-[:30]-[:-30]-[:30] \L \Rz O-[:-30]-[:30](-[:90])-[:-30]NH_2}

\end{document}


Honestly I think it still could be better. The x, y and z are too far away from their respective right brackets, but I can live with that.

Anyway, if anyone happen to find a more professional solution I'd be glad to hear it!

Thanks!!

• Forgot to say, all I did was change \strut to \rule. I'm really new to LaTex, but it seems to me that with \rule I have more control over the size and position of the brackets. – Lucas Vieira Aug 25 '18 at 18:50
• you can move the subscripts closer if you replace _x with _{\!x} for example – clemens Oct 19 at 9:34

I found an older question with a similar problem, of which the answer may also be a solution for you.

It makes use of a macro defined in the polymers module.

\documentclass{article}
\usepackage{chemfig}

\newcommand{\makemypolymerdelims}[7][]{%
\chemmove{\path (#6) -- node[pos=#4] {$\left(\vrule height#2 depth#3 width0pt\hspace{#5}\right)_#1$} (#7);}%
}

\begin{document}

\chemfig{H_2N-[:30](-[:90])-[:-30]-[@{a}:30]O-[:-30]-[:30](-[:90])-[@{b}:-30] O-[:30]-[:-30]-[@{c}:30]O-[:-30]-[:30](-[:90])-[@{d}:-30]NH_2}
\makemypolymerdelims[x]{8pt}{8pt}{.55}{60pt}{a}{b}
\makemypolymerdelims[y]{8pt}{8pt}{.55}{60pt}{b}{c}
\makemypolymerdelims[z]{8pt}{8pt}{.55}{60pt}{c}{d}

\end{document}


• Vertical fine-tuning can be achieved by adding a yshift like in \makemypolymerdelims[y]{8pt}{8pt}{.55,yshift=-.5pt}{60pt}{b}{c} . – Jasper Habicht Aug 27 '18 at 14:09