0

I have the following code (which I found somewhere around this page) to make polymer figure

\usepackage{chemfig}
\usepackage{mhchem}

 \makeatletter
  \newcommand*\setpolymerdelim[2]{\def\polymer@delimleft{#1}\def\polymer@delimright{#2}}

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

 \begin{document}

  \setpolymerdelim[]

 \chemfig{-[@{b1},1.5]C(-[2]H)(-[6]H)-C(-[2]Cl)(-[6]H)-[@{b2},1.5]}
 \makepolymerbraces{40pt}{40pt}{$n$}{b1}{b2}

   \end{document}

No matter what I try it always gives me this error: !Missing $ inserted. !Extra } !pacakage PFG math error: unknown function '@b1 !pacakage PFG math error: unknown function '@b2

Everything in the line where the command \chemfig{-[@{b1},1.5]C(-[2]H)(-[6]H)-C(-[2]Cl)(-[6]H)-[@{b2},1.5]} Can anyone help me and tell me what I'm doing wrong? I'm using Texmaker and I just took any basic polymer as an example. I would appreciate any help.

1
  • 1
    Welcome to TeX.SX! I get no error from your code. What TeX distribution are you using?
    – egreg
    Oct 1, 2015 at 22:37

1 Answer 1

1

To compile the document (pdfTeX, Version 3.14159265-2.6-1.40.16 (MiKTeX 2.9)) I had to complete the preamble by \documentclass{article} and voilà

enter image description here

Invoking mhchem was not necessary for this. As a side-note, in my daily use I call it by \usepackage[version=3]{mhchem}.

Second remark: Of course you may use chemfig. But if you want to depict many chemical structures, like for a report in lab classes, there are easier ways to obtain such representations. The documentation of the chemstyle bundle describes some of them. For reports, for example, or while exchanging with other colleagues (perhaps less chem-savy than you) it is more efficient and much faster to create them with a molecular editor and export them for example as *.eps / *.pdf into a designated folder within your working project.

If you work at a university, perhaps your department provides access to Chemdraw. If your are student, ChemDoodle may be an alternative with a considerably lesser price tag (and in difference to the former, working on Win/Mac/Linux). (For a comparison of several molecular editors, consider this review here,) The advantage is not only that you may draw once the structure and adapt them quickly for a publication in a journal or a poster or slide talk. As outlined in chemscheme, you may add indicators as "hidden tags" in graphic that eventually allow you to comfortably label by number your compounds. This is very beneficial in lengthier reports where you simply call these labels (similar as you would do while citing a literature reference); eventually your compound marked by 2 in the scheme is referenced by the same 2 in the running text.

3
  • I think that Chemfig is a very bad solution. As seen in the chemscheme manual that seems to be your reference, chemfig is not even mentioned. Finally, the only advantage of chemfig is its price, but that does not matters in comparison to the ease of use of commercial and paying software.
    – unbonpetit
    Oct 2, 2015 at 5:26
  • @unbonpetit What?!
    – yo'
    Oct 31, 2015 at 23:35
  • @unbonpetit What, unbonpetit?! I thought you are (one of) the creator of chemfig...
    – pisoir
    Jan 30, 2016 at 12:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .