1

Consider the minimal example:

\documentclass[12pt]{article}                                              

\usepackage{tikz}                                                          
\usepackage{chemfig}                                                       

\begin{document}                                                           

\begin{tikzpicture}                                                        

\path node(A){\chemfig{                                                    
 @{N1}N(-[::90,0.4,,,draw=none]H)-[::-30](<[::-60]CH_2-[::0]OH)-[::60](=[::60]O)-[::-60]-[,0.3,,,draw=none]
 @{N2}N(-[::-90,0.4,,,draw=none]H)-[::30](<:[::60]CH_2-[::0]OH)-[::-60](=[::-60]O)-[::60]-[,0.3,,,draw=none]
 @{N3}N(-[::90,0.4,,,draw=none]H)-[::-30](<[::-60]CH_2-[::0]OH)-[::60](=[::60]O)-[::-60]-[,0.3,,,draw=none]
}};                                                                        

\end{tikzpicture}                                                          

\begin{tikzpicture}[remember picture,overlay]                              
\draw[red,very thick](N1)--(N3);                                           
\end{tikzpicture}                                                          

\end{document}              

molecules with a red line between 2 atoms

Is there a way to put all in one tikzpicture and avoid the need to compile twice? And more important: How can I define variables that allow to do something like this??:

\documentclass[12pt]{article}

\usepackage{tikz}
\usepackage{chemfig}

\def\sera#1{@{N#1}N(-[::90,0.4,,,draw=none]H)-[::-30](<[::-60]CH_2-[::0]OH)-[::60](=[::60]O)-[::-60]}
\def\serb#1{@{N#1}N(-[::-90,0.4,,,draw=none]H)-[::30](<:[::60]CH_2-[::0]OH)-[::-60](=[::-60]O)-[::60]}

\begin{document}

\begin{tikzpicture}

\path node(A){\chemfig{
 \sera{1}-[,0.3,,,draw=none]
 \serb{2}-[,0.3,,,draw=none]
 \sera{3}-[,0.3,,,draw=none]
}};

\end{tikzpicture}

\begin{tikzpicture}[remember picture,overlay]
\draw[red,very thick](N1)--(N3);
\end{tikzpicture}

\end{document}

with let to the error

Package pgf Error: No shape named N1 is known

I figure out that the error come from the expansion of the variables.... but is not in my understanding yet how this work, and I appreciate any help.

Note: I want to handle different chemfig with tikzpicture, therefore the straightforward way with a standalone \chemfig and then a \chemmove is not convenient for my needs.

Thanks

2

As for your second question, you have it basically ok. Just modify these lines as following (treat them as submolecules):

\path node(A){\chemfig{
 !{\sera{1}}-[,0.3,,,draw=none]
 !{\serb{2}}-[,0.3,,,draw=none]
 !{\sera{3}}-[,0.3,,,draw=none]
}};

Compiling it with pdflatex should do the work.

| improve this answer | |
  • Wonderful! The second question was the main one, and this works perfectly. Thank you very much. – alexis Dec 4 '14 at 14:59

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.