4

I have the following code:

\documentclass[12pt]{report}
\usepackage{chemfig}

%these for bonds in chemfig
\setdoublesep{0.35700 em}  % 'Bond Spacing'
\setatomsep{1.78500 em}    % 'Fixed Length'
\setbondoffset{0.18265 em} % 'Margin Width'
\newcommand{\bondwidth}{0.06642 em} % 'Line Width'
\setbondstyle{line width = \bondwidth}

%Drawing parentheses around polymers
\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{#3}}
      $};
  }%
}

%
%----------------------------end of preamble---------------------------------
%
\begin {document}

\setpolymerdelim() \chemfig{[:-30]*6((-C(-[:240]Cl 
[@{op,.25}]
)(=[:120]O))=-=(-C(-[:300]OCH_2CH_2-O-[@{cl,.25}]H)(=[:60]O))-=-)} \makebraces(35pt,15pt){$\!\!{\rm n}$}{op}{cl}


\end {document}

Which gives me this image:

enter image description here

If anyone is familiar with parenthesis in chemfig, please run the code and see if you could answer for me? I would be much obliged!

Could I get some help tidying up the position of the left hand bracket and getting rid of the little box after the Cl?

Thanks for the responses but to clarify,, what I am trying to achieve is the following

enter image description here

Jeff
  • 43

2 Answers2

4

Perhaps something like this is what you want:

\documentclass[12pt]{report}
\usepackage{chemfig}

%these for bonds in chemfig
\setdoublesep{0.35700 em}  % 'Bond Spacing'
\setatomsep{1.78500 em}    % 'Fixed Length'
\setbondoffset{0.18265 em} % 'Margin Width'
\newcommand{\bondwidth}{0.06642 em} % 'Line Width'
\setbondstyle{line width = \bondwidth}

%Drawing parentheses around polymers
\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{#3}}
      $};
  }%
}

%
%----------------------------end of preamble---------------------------------
%
\begin {document}

\setpolymerdelim() \chemfig{[:-30]*6((-C(-[:240]Cl-[@{op,0.2},,,,draw=none]
)(=[:120]O))=-=(-C(-[:300]OCH_2CH_2-O-[@{cl,.25}]H)(=[:60]O))-=-)} \makebraces(45pt,15pt){$\!\!\textrm{n}$}{op}{cl}

\end {document}

enter image description here

Gonzalo Medina
  • 505,128
4

You typed \chemfig{...Cl[@{op,.25}]...} which implies an optional argument to the »Cl« atom. There are no optional arguments to atoms, though! This means chemfig interprets the quare brackets as atoms, i.e., it typesets them. This leads to the “little box” you see.

There are two legal places for the @{...} syntax:

  • a zero size node on a bond using the syntax “@{<name>,<coeff>}” placed at the beginning of the optional argument of the relevant bond, without being followed by a comma if there is a first optional argument. In this case, the node takes the name “<name>” and the <coeff>, which must be between 0 and 1, determines where the node is located on the bond. If “@{<name>}” is used, the <coeff> is set to 0.5 by default, which means that the node is placed halfway along the bond;
  • a node on an atom using the syntax “@{<name>}” immediately before the relevant atom. In this case, the node has exactly the same footprint as the atom, but may be empty and therefore have zero dimensions.

So with \chemfig{...Cl[@{op,.25}]...} you have effectively marked the closing square bracket.

Solution: add a bond in front of the square brackets \chemfig{...Cl-[@{op,.25}]...}.

The rest is fine (it looks like the macros copied from the documentation). You'll only have to play with the <coeff> and the values of the (#1,#2) argument to \makebraces.

Also have a look at How to draw parentheses inside chemfig?

enter image description here

\documentclass[12pt]{report}
\usepackage{chemfig}

%these for bonds in chemfig
\setdoublesep{0.35700 em}  % 'Bond Spacing'
\setatomsep{1.78500 em}    % 'Fixed Length'
\setbondoffset{0.18265 em} % 'Margin Width'
\newcommand{\bondwidth}{0.06642 em} % 'Line Width'
\setbondstyle{line width = \bondwidth}

%Drawing parentheses around polymers
\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{#3}}
      $};
  }%
}

%
%----------------------------end of preamble---------------------------------
%
\begin {document}

\setpolymerdelim()

\chemfig{
  [:-30]*6(
    (-C
      (-[@{op,.7}:225,2]Cl)
      (=[:120]O)
    )=-=(-C
      (-[:300]OCH_2CH_2-O-[@{cl,.25}]H)
      (=[:60]O)
    )-=-
  )
}

\makebraces(45pt,15pt){$\!\!{n}$}{op}{cl}

\end {document}
cgnieder
  • 66,645