Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

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.

share|improve this answer
add comment

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

share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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