4

I was tinkering with chemfig package. I created the macros

\documentclass{article}
\newcommand{\lmethyl}{C(-[2]H)(-[4]H)(-[6]H)}
\newcommand{\rmethyl}{C(-[2]H)(-[6]H)-H}
\newcommand{\tmethyl}{C(-[2]H)(-[4]H)-H}
\newcommand{\bmethyl}{C(-[4]H)(-[6]H)-H}
\usepackage{chemfig}
\begin{document}
\chemfig{\lmethyl-\rmethyl}
\end{document}

I thought I would be able to create the code of methane using this. I know the macros are all run at the same time and hence creates the following. enter image description here

7

What you're looking for is the \definesubmol{name}{code} command. You can insert a sub-molecule inside a chemfig command with !{name}.

\definesubmol{rmethyl}{C(-[0]H)(-[2]H)(-[6]H)}
\chemfig{R-!{rmethyl}}

There are some other things you can do with that command, such as defining different code depending on what direction the bond comes from (so H_3C and CH_3 can be handled by one sumbol).

For more details, see section 4.7 of the chemfig manual.

| improve this answer | |
8

You should use chemfig's \definesubmol instead of \newcommand:

\documentclass{article}

\usepackage{chemfig}
\definesubmol{\lmethyl}{C(-[2]H)(-[4]H)(-[6]H)}
\definesubmol{\rmethyl}{C(-[2]H)(-[6]H)-H}
\definesubmol{\tmethyl}{C(-[2]H)(-[4]H)-H}
\definesubmol{\bmethyl}{C(-[4]H)(-[6]H)-H}

\begin{document}
\chemfig{!\lmethyl-!\rmethyl}
\end{document}

enter image description here

| improve this answer | |
  • Thats what I wanted! Just one more question, what does the ! do in \chemfig{!\lmethyl-!\rmethyl} – nichas Oct 20 '12 at 7:40
  • 1
    The ! is the operator that tells chemfig to insert a submol. You may also define a submol without backslash: \definesubmol{Et}{CH_3-CH_2}. Then you need to use it like \chemfig{!{Et}-H} – cgnieder Oct 20 '12 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.