% _________________________________________________________________ % | | % | | % | ChemFig Documentation | % | | % | January 08, 2011 | % | | % |_________________________________________________________________| % % This is chemfig_doc_en.tex, the LaTeX code of the chemfig English % documentation. Translation by Theo Hopman (hopman.theo@gmail.com). % % Maintainer: Christian Tellechea % E-mail : unbonpetit@gmail.com % Comments, bug reports and suggestions are welcome. % Licence : Released under the LaTeX Project Public License v1.3c or % later, see http://www.latex-project.org/lppl.txt % Copyright : Christian Tellechea 2010-2011 % % The "chemfig" package consists of the 6 following files: % chemfig.sty % README % chemfig_doc_en.tex, chemfig_doc_en.pdf (english manual) % chemfig_doc_fr.tex, chemfig_doc_fr.pdf (french manual) % % ------------------------------------------------------------------- % This work may be distributed and/or modified under the % conditions of the LaTeX Project Public License, either version 1.3 % of this license or (at your option) any later version. % The latest version of this license is in % % http://www.latex-project.org/lppl.txt % % and version 1.3 or later is part of all distributions of LaTeX % version 2005/12/01 or later. % ------------------------------------------------------------------- % This work has the LPPL maintenance status `maintained'. % % The Current Maintainer of this work is Christian Tellechea % ------------------------------------------------------------------- \documentclass[10pt]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[a4paper,margin=2.5cm,head=5mm,headsep=5mm,footskip=10mm]{geometry} \usepackage[bottom]{footmisc} \usepackage{libertine} \renewcommand*\oldstylenums[1]{{\fontfamily{fxlj}\selectfont #1}} \usepackage[scaled=0.8]{luximono} \usepackage{amsmath} \usepackage{array} \usepackage{longtable} \usepackage{xspace} \usepackage{fancybox} \usepackage{boites} \usepackage{textcomp} \usepackage{enumitem} \usepackage{chemfig} \usetikzlibrary{decorations.pathmorphing} \usepackage{emerald} \usepackage[protrusion=true,expansion,final,babel=true]{microtype} \usepackage{fancyhdr} \fancyhead[L]{\small\bfseries\CF} \fancyhead[C]{} \fancyhead[R]{\scriptsize\slshape \leftmark} \fancyfoot[l]{\tiny \LaTeX ed by Christian \textsc{Tellechea}, the \today.} \fancyfoot[c]{} \fancyfoot[r]{\thepage} \makeatletter \long\def\grab@toks#1\relax{\endgroup\def\right@content{#1}} \newcommand\make@car@active[2]{% \catcode`#1\active \begingroup \lccode`\~`#1\relax \lowercase{\endgroup\def~{#2}}% } \newif\if@exstar \newcommand\exemple{% \begingroup \parskip\z@ \@makeother\;\@makeother\!\@makeother\?\@makeother\:% neutralise frenchb \@ifstar{\@exstartrue\exemple@}{\@exstarfalse\exemple@}} \newcommand\exemple@[2][65]{% \medbreak\noindent \begingroup \let\do\@makeother\dospecials \make@car@active\ { {}}% \make@car@active\^^M{\par\leavevmode}% \make@car@active\,{\leavevmode\kern\z@\string,}% \make@car@active\-{\leavevmode\kern\z@\string-}% \exemple@@{#1}{#2}% } \newcommand\exemple@@[3]{% \def\@tempa##1#3{\exemple@@@{#1}{#2}{##1}}% \@tempa } \newcommand\exemple@@@[3]{% \xdef\the@code{#3}% \endgroup \if@exstar \begingroup \fboxrule0.4pt \let\breakboxparindent\z@ \def\bkvz@bottom{\hrule\@height\fboxrule}% \let\bkvz@before@breakbox\relax \def\bkvz@set@linewidth{\advance\linewidth\dimexpr-2\fboxrule-2\fboxsep}% \def\bkvz@left{\vrule\@width\fboxrule\hskip\fboxsep}% \def\bkvz@right{\hskip\fboxsep\vrule\@width\fboxrule}% \def\bkvz@top{\hbox to \hsize{% \vrule\@width\fboxrule\@height\fboxrule \leaders\bkvz@bottom\hfill \ECFAugie \fboxsep\z@ \colorbox{black}{\kern0.25em\color{white}\footnotesize\lower0.5ex\hbox{\strut#2}\kern0.25em}% \leaders\bkvz@bottom\hfill \vrule\@width\fboxrule\@height\fboxrule}}% \breakbox \kern.5ex\relax \ttfamily\footnotesize\the@code\par \normalfont \kern3pt \hrule height0.1pt width\linewidth depth0.1pt \vskip5pt \rightskip0pt plus 1fill \everypar{{\color{lightgray}\rlap{\vrule height0.1pt width\linewidth depth0.1pt}}\hskip0pt plus 1fill}% \newlinechar`\^^M\everyeof{\noexpand}\scantokens{#3}\par \endbreakbox \endgroup \else \vskip0.5ex \boxput*(0,1) {\fboxsep\z@ \hbox{\ECFAugie\colorbox{black}{\leavevmode\kern0.25em{\color{white}\footnotesize\strut#2}\kern0.25em}}% }% {\fboxsep5pt \fbox{% $\vcenter{\hsize\dimexpr0.#1\linewidth-\fboxsep-\fboxrule\relax \kern5pt\parskip0pt \ttfamily\footnotesize\the@code}% \vcenter{\kern5pt\hsize\dimexpr\linewidth-0.#1\linewidth-\fboxsep-\fboxrule\relax \everypar{{\color{lightgray}\rlap{\vrule height0.1pt width\dimexpr\linewidth-0.#1\linewidth-\fboxsep-\fboxrule depth0.1pt}}}% \footnotesize\newlinechar`\^^M\everyeof{\noexpand}\scantokens{#3}}$% }% }% \fi \medbreak \endgroup } \long\def\if@instr#1#2{% \long\def\if@instr@i##1#2##2\@nil{\ifx\@empty##2\@empty\expandafter\@secondoftwo\else\expandafter\@firstoftwo\fi}% \if@instr@i#1\relax#2\@nil } \long\def\subst@in#1#2#3{% \long\def\subst@in@i##1#2##2\@nil{##1#3##2}% \expandafter\if@instr\expandafter{#1}{#2}% {\expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter\subst@in@i#1\@nil}% \subst@in#1{#2}{#3}% }\relax } \newcommand\falseverb[1]{{\ttfamily\detokenize{#1}}} \long\def\centerverb#1{% \def\centerverb@i##1#1{##1\hfill\null\par\egroup} \bgroup \ttfamily\@noligs \parskip3.5pt\par\hfill \let\do\@makeother\dospecials \@vobeyspaces \centerverb@i} \makeatother \usepackage[english]{babel} \def\degres{\ensuremath{{}^\circ}} \newcommand\CF{{\ECFAugie ChemFig}\xspace} \newcommand\TIKZ{ti\textit kz\xspace} \newcommand\molht[1]{\begingroup\parskip3.5pt\par\hfill\chemfig{#1}\hfill\null\par\endgroup} \newcommand\boxednode[2]{\fbox{$\mathrm{#1}\vphantom{M_1}$}_{#2}} \newcommand\boxedfalseverb[1]{{\fboxsep0pt\fbox{\vphantom|\falseverb{#1}}}} \usepackage[plainpages=false,pdfpagelabels,bookmarks=true,bookmarksopen=true,colorlinks=true,hyperfootnotes=false,filecolor=black,linkcolor=blue,urlcolor=magenta,pdfauthor={Christian TELLECHEA},pdftitle={ChemFig},pdfsubject={Draw 2D molecule with LaTeX},pdfkeywords={ChemFig},pdfcreator={LaTeX}]{hyperref} \csname @addtoreset\endcsname{section}{part} \usepackage{titlesec} \titleformat{\part}[display] {\normalfont\Large\filcenter\sffamily\bfseries}% {\LARGE\MakeUppercase{\partname~\thepart}}% {1pc}% {\titlerule\vspace{1pc}\Huge} \newcommand*\nouveau[1][0pt]{\leavevmode\llap{\footnotesize\itshape\bfseries\color{red}New\kern\dimexpr15pt+#1\relax}} \begin{document} \begin{titlepage} \catcode`!12 \begin{tikzpicture}[remember picture,overlay] \filldraw[blue!75](current page.south west) rectangle ([yshift=2cm,xshift=-3cm]current page.center); \shade [left color=blue!75,right color=white]([yshift=2cm,xshift=-3cm]current page.center) rectangle ([xshift=3cm]current page.south); \filldraw[black](current page.north west) rectangle ([yshift=7cm]current page.east); \shade[top color=black,bottom color=blue]([yshift=7cm]current page.east)rectangle([yshift=2.5cm]current page.west); \filldraw[black!55!blue!100]([yshift=2.5cm]current page.east)rectangle([yshift=2cm]current page.west); \end{tikzpicture} \begin{center} \color{white}\ECFAugie\fontsize{50pt}{50pt}\selectfont\CF\par \Large v\csname CF@ver\endcsname\par\bigskip \footnotesize\csname CF@en@date\endcsname\par \normalsize Christian Tellechea\par\vskip1.5cm \huge A \LaTeX{} package for drawing molecules% \end{center} \vskip4cm \begin{center} \scriptsize \setatomsep{3em}% \chemfig{-[::-30](-[5])(-[7])-[::+60]-[::-60]O-[::+60](=[::-45]O)-[::+90]HN>:[::-60](-[::+60]**6(------))-[::-30](<:[2]OH)-[::-60](=[6]O)-[::+60]O>:[::-60]*7(---?(<[::-120]OH)-(<|[1]CH_3)(<:[::-90]CH_3)-(-[1](<[::+80]HO)-[0](=[::+60]O)-[7](<|[::+130]CH_3)(-[::+75](<|[2]OH)-[::-60]-[::-60](<[::+30]O-[::-90])-[::-60](<[::+90])(<:[::+30]O-[7](-[6]CH_3)=[0]O)-[::-60])-[6]-[5,1.3]?(<:[7]O-[5](=[::-60]O)-[6]**6(------)))=(-[2]CH_3)-)}% \par {\ECFAugie\small Taxotere}% \end{center} \vskip1.5cm \hfill \hbox to 0pt{\hss \scriptsize \setbondoffset{1pt} \setatomsep{2em} \chemfig{(-[:-150]R')(-[:-30]R)=[2]N-[:30]OH}% \kern-1em \chemrel[\chemfig{\chemabove{H}{\kern10pt\oplus}}]{<>}% \kern-0.5em \chemfig{(-[@{a0}:-150]R')(-[:-30]R)=[2]@{a1}N-[@{b0}:30]@{b1}\chemabove{O}{\oplus}H_2}% \chemmove[red,-stealth,shorten <=2pt]{% \draw(a0)..controls +(135:2mm) and +(215:4mm).. (a1); \draw(b0)..controls +(120:2mm) and +(180:3mm).. ([yshift=7pt]b1.180); } \kern-1.5em \chemrel[\chemfig{{-}H_2O}]{<>}% $\left[\begin{tabular}{c} \chemfig{R'-N=@{a1}\chemabove{C}\oplus-R}\\ \tikz\draw[stealth-stealth](0,3mm)--(0,-3mm);\\ \chemfig{R'-\chemabove{N}\oplus~C-R} \end{tabular}\right]$% \chemrel[\chemfig{H_2@{a0}\lewis{0:2:,O}}]{<>}% \chemmove[red,-stealth,shorten <=3pt]{% \draw(a0)..controls+(90:10mm)and+(45:10mm)..([yshift=6pt]a1.45); }% \chemfig{*6(R\rlap{$'$}-N=(-R)-\chemabove{O}\oplus H_2)}% \chemrel[\chemfig{{-}\chemabove{H}{\kern10pt\oplus}}]{<>}% \chemfig{*6(R\rlap{$'$}-N=(-R)-OH)}% \chemrel{-stealth}% \chemfig{*6(R\rlap{$'$}-\chembelow{N}{H}-(-R)(=[2]O))}\par\bigskip \hss}\hfill\null \begin{center} \ECFAugie\small The Beckmann rearrangement% \end{center} \end{titlepage} \parindent0pt\pagestyle{fancy} \tableofcontents \parskip\medskipamount \vspace{2cm} \setitemize{leftmargin=3em,topsep=0pt,parsep=0pt,itemsep=0pt} \part{Introduction} \section{New in version 0.3} \nouveau Here's what's new in version 0.3, in response to requests from users and to gaps that needed filling anyway: \begin{enumerate} \item Improvements to the command \verb-\definesubmol- which now accepts control sequences as aliases. An alias can also be set up so that the substitution is different depending on the orientation of the bond which arrives at it. See page~\pageref{definesubmol}; \item The character ``\verb-|-'' forces the end of an atom. Thus if one writes ``D|ef'', \CF will see two atoms ``D'' and ``ef''. Read page~\pageref{decoupage.atomes}; \item The character ``\verb-#-'' is recognized when it follows a bond character. It must be followed by an argument between parentheses which contains the shortening of the start and end which will be applied to this bond. See page~\pageref{modif.retrait}; \item The macro \verb-\chemfig- accepts optional arguments which are passed to the ``tikzpicture'' environment in which it is drawn. Read page ~\pageref{arguments.optionnels}; \item Addition of representation of electron movement and reaction mechanisms with the syntax ``\verb-@{}-'' before an atom or ``\verb-@{,}-'' at the beginning of the argument of a bond.\par This syntax allows placement of a node (in the \TIKZ sense) which will become the tip of any arrows draw. The layout of the arrows is done by the macro \verb-\chemmove- whose optional argument becomes that of the ``tikzpicture'' environment in which the arrows are drawn. Read page~\pageref{mecanismes-reactionnels}; \item For the vertical alignment mechanism to get atoms on the same horizontal line, the macro \verb-\chemskipalign- allows this mechanism to be ignored for the group of atoms in which it is written. See page~\pageref{chemskipalign}; \item The commands \verb-\chemname- allows a name to be displayed underneath a molecule and \verb-\chemnameinit- sets the alignment of the names. See page~\pageref{chemname}; \item The commands \verb-\hflipnext- and \verb-\vflipnext- horizontaly or verticaly flip the next molecule drawn. See page~\pageref{retournement}; \item Drawing of the decorations which carry our the command \verb-\lewis- have been improved; \item Bug fixes and code optimization. \end{enumerate} \section{Foreword} This package has seen the light of day thanks to the assistance of Christophe \textsc{Casseau}, who had the idea after being confronted with the complexity of the syntax of the \href{http://www.ctan.org/tex-archive/help/Catalogue/entries/ppchtex.html}{\texttt{\textbf{ppchtex}}} package. Throughout the writing of the code, he helped me find interesting features. He always encouraged me to write more advanced features even though I was sometimes (nearly always?) reluctant; if \CF has the features it does, it is in large part thanks to him. I thank him as well for his testing of beta versions of this package, and for his contributions to the writing of this manual.\medskip \begingroup \leftskip0.1\linewidth \rightskip0.1\linewidth \itshape\small Experience shows that is it has been difficult to combine drawing of molecules with the typographic quality of a program like \LaTeX, leaving little choice for the user who wishes to have a vector format for these drawings. After having abandoned the \emph{ppchtex} package (developed for con\TeX t and available under \LaTeX) because of the complexity of its syntax, I turned to the world of programs outside \LaTeX. The difficulty in this case is finding a compromise between quality and price. After many unsuccessful attempts I found the only option was a new package, and I would like to thank Christian \textsc{Tellechea} for bringing it to life. To meet my requirements, \CF needed to be easy to use but still have advanced features, something well nigh impossible. Yet he was able to put together a very flexible \TeX{} code which makes it a pleasure for me to write my molecules. I hope it will be the same for you readers looking for a package useful in the field of chemistry.\smallskip \hfill Christophe \textsc{Casseau}\kern0.1\linewidth \endgroup\medskip Finally, I wish to warmly thank Theo \textsc{Hopman} for offering to translate this manual into English. \section{Presenting \CF} To use this package, start by adding the following code to the preamble: \centerverb/\usepackage{chemfig}/ \smallskip The most important command for drawing molecules is \verb|\chemfig{}|. The argument \verb|code| is a set of characters describing the structure of the molecule according to the rules which are described in this manual. Care has been taken to make it possible to draw the greatest possible number of molecular configurations, while maintaining a simple, flexible, and intuitive syntax. Despite this, the \verb-- which describes the 2D structure of the molecule increases in complexity in proportion to that of the molecule being drawn. The command \verb|\chemfig| draws a molecule using the commands provided by the \TIKZ package, placed inside a \verb|tikzpicture| environment. The choice of \TIKZ implies that: \begin{itemize} \item the user has a choice of compilation method: pdf\LaTeX{} can be used equally well in dvi mode (tex $\longrightarrow$ dvi $\longrightarrow$ ps $\longrightarrow$ pdf) or in pdf mode (tex $\longrightarrow$ pdf). In effect \TIKZ, via the underlying pgf, gives identical graphical results in the two modes; \item the bounding box is automatically calculated by \TIKZ and the user need not worry about any overlap with the text. However, care must be taken with alignment when the molecule is drawn in a paragraph. In the following example, we have drawn the bounding box for the molecule: {\fboxsep0pt \fbox{\chemfig{H_3C-C(-[:-30]OH)=[:30]O}}}. \CF always places the first atom of the molecule on the baseline of the preceding code. \end{itemize} \newpage \part{\CF for the impatient} This part is a non-exhaustive overview of the features of \CF. The goal is to introduce the basic ideas, allowing the user to get started drawing molecules as quickly as possible. This part does not go into detail; advanced use and a more formal approach to \CF commands will be discussed in the following parts. \section{Syntax} The command \verb|\chemfig| is used in the following way: \centerverb/\chemfig{[,,,,]}/ \begin{itemize} \item \verb-- is the bond angle between the two atoms; \item \verb-- is a coefficient multiplying the default bond length; \item \verb-- and \verb-- are the numbers of the departure and arrival atoms of the bond; \item \verb-- is additional options concerning the colour or style of a bond. \end{itemize} \medskip Each bond takes optional arguments which are placed in square brackets. These arguments can adjust everything one needs for the bond. Each argument has a default value, so one can simply write: \exemple{The water molecule}|\chemfig{H-O-H}| In all the examples, the grey line represents the baseline. \section{The different types of bonds} For \CF, bonds between two atoms are one of nine types, represented by the characters \boxedfalseverb-, \boxedfalseverb=, \boxedfalseverb~, \boxedfalseverb>, \boxedfalseverb<, \boxedfalseverb{>:}, \boxedfalseverb{<:}, \boxedfalseverb{>|} and \boxedfalseverb{<|} :\label{types.liaisons} \begin{center} \begin{tabular}{>{\centering\arraybackslash}m{1.7cm}>{\centering\arraybackslash}m{3cm}>{\centering\arraybackslash}m{2cm}m{4cm}} \hline Bond \#&Code &Result &Bond type\\\hline 1 &\verb+\chemfig{A-B}+ &\chemfig{A-B} &Single\\ 2 &\verb+\chemfig{A=B}+ &\chemfig{A=B} &Double\\ 3 &\verb+\chemfig{A~B}+ &\chemfig{A~B} &Triple\\ 4 &\verb+\chemfig{A>B}+ &\chemfig{A>B} &right Cram, plain\\ 5 &\verb+\chemfig{A:B}+&\chemfig{A>:B}&right Cram, dashed\\ 7 &\verb+\chemfig{A<:B}+&\chemfig{A<:B}&left Cram, dashed\\ 8 &\verb+\chemfig{A>|B}+&\chemfig{A>|B}&right Cram, hollow\\ 9 &\verb+\chemfig{A<|B}+&\chemfig{A<|B}&left Cram, hollow\\\hline \end{tabular} \end{center} \label{setdoublesep}The command \verb-\setdoublesep{}- adjusts the spacing between the lines in double or triple bonds. This spacing is 2pt by default. \section{Different types of diagrams} \subsection{Complete structural diagram} \exemple{Ethane}|\chemfig{C(-[2]H)(-[4]H)(-[6]H)-C(-[2]H)(-[6]H)-H}| Each bond takes several optional arguments. The first optional argument defines the \verb-- of the bond. Angles increase counterclockwise. If no angle is give then its default value is 0\degres. Note: the parentheses allow multiple bonds from the same atom; see ``Branched molecules'', page~\pageref{molecules.ramifiees}. There are many ways of specifying the angle of a bond. \begin{description} \item[Predefined angles] When the optional argument contains a whole number, this represents the angle that the bond makes with the horizontal, in multiples of 45\degres. \exemple{Predefined angles}|\chemfig{(-[1]1)(-[2]2)(-[3]3)(-[4]4)(-[5]5)(-[6]6)(-[7]7)-0}| \item[Absolute angle] To give an angle in degrees relative to the horizontal, the optional argument must take this form: \verb-[:]-. The \verb-- may be positive or negative, and may have decimal places. It is reduced to the interval $[0,360)$. \item[Relative angle] It is often useful to give the bond angle relative to the preceding bond. In this case, the following syntax must be used:\verb-[::]-. The \verb-- may be positive or negative, and may have decimal places. \end{description} \subsection{Condensed structural diagram} \exemple{Hex-1-ene}|\chemfig{H_3C-{{(CH_2)}_3}-CH=CH_2}| It is sometimes useful to change the length of a bond. In the preceding example, the first two bonds need to be lengthened; they are too short compared to the double bond. To do this, the \verb|| is needed in the optional arguments. \exemple{Hex-1-ene}|\chemfig{H_3C-[,1.5]{{(CH_2)}_3}-[,1.5]CH=CH_2}| Notes: \begin{itemize} \item in the notation \verb|[,1.5]|, the comma indicates that the value placed in brackets corresponds to the second argument (\verb|coeff|). To give a value for the fourth argument one would write \verb|[,,,2]|; \item characters between braces are not interpreted by \CF, which allows (for example) groupings of atoms to be written inside parentheses without having them treated as part of a branched molecule (see page~\pageref{molecules.ramifiees}). \end{itemize} \subsection{Cram representation} Another way of showing the bond angle between two atoms. \exemple{Methane}|\chemfig{C(-[5]H)(-[2]H)(<[:-70]H)(<:[:-20]H)}| \subsection{Skeleton diagram} The simplest input, only covalent bonds are listed with their possible settings. \exemple{But-2-ene}|\chemfig{-[:30]=[:-30,,,,red]-[:30]}| The double bond lines are drawn on either side of where the single bond line would be. To keep graphical consistency between skeleton diagrams of various compounds it is useful to shift the second double bond line above or below the single bond line. Just follow the \verb-=- symbol with \verb-^- or \verb-_-, as shown below: \exemple{Comparison between double bonds and shifted double bonds}/\chemfig{-[:-30]=[:30]-[:-30]} \chemfig{-[:-30]=^[:30]-[:-30]}\par \chemfig{=[:-30]-[:30]=[:-30]} \chemfig{=_[:-30]-[:30]=^[:-30]}/ \subsection{Lewis diagrams} The syntax is as follows: \centerverb/\lewis{,}/ \smallskip The electron states can be a lone pair, an empty electron slot, or a single electron. By default the electron state is a lone pair. A single electron is represented by the character \boxedfalseverb. and an empty slot by \boxedfalseverb|. \exemple{Chloromethane and water}|\chemfig{C(-[2]H)(-[4]H)(-[6]H)-\lewis{260,Cl}}\hspace{1cm} \chemfig{[:40]H-\lewis{13,O}-[::-80]H}| Note: the positions take whole number values between 0 and 7. \exemple{Positions}/\lewis{0.2.4.6.,C}\hspace{1cm} \lewis{0|2.46.,C}\hspace{1cm} \lewis{1357,Ar}/ \section{Branched molecules}\label{molecules.ramifiees} To indicate a branch, simply follow the atom holding the branch with a \verb-- in parentheses. This \verb-- is the code of the submolecule which will be attached to the atom. Multiple branches can be attached to the same atom, and these can be nested. \exemple{Alkanes}|\chemfig{H_3C-CH(-[2]CH_3)-CH_3} \hspace{.5cm}\chemfig{-(-[2])(-[6])-}| In this type of representation it is sometimes necessary to connect to distant atoms. To do this, the character \verb|?| is used, which creates a hook between two atoms. The function \centerverb/?[,,]/ takes three arguments: the name of the hook, the bond type, and tikz code. The following example shows how to make two different hooks. \exemple*{Cocaine}|\chemfig{H_2C(-C?[a]H-[:-30]CH_2-[:30]C?[b]H-O-CO-C_6H_5) -[2]CH_2-[,1.7]CH(-[3]N?[a]-[3]H_3C)(-[,1.35]C?[b]H-CO-OCH_3)}| \section{Rings} \CF can easily draw regular polygons. The syntax is the following: \centerverb/\chemfig{*n()}/ \smallskip \exemple{Some rings}| \chemfig{*3(---)}\hspace{.5cm} \chemfig{*5(-=-=-)}\hspace{.5cm} \chemfig{*6(-=-=-=)}| Branches are used in the same way as before. \exemple{Rings and branches}|\chemfig{*4(-(--[1]*4(----))---)}| Note: a ring does not start or finish with the atom or group of atoms with which one wants to close the ring. The chemical entity on which the ring is based must be outside the ring definition. \exemple{Proper coding}|\chemfig{A*4(-B-C-D-)}| \exemple{Bad coding}|\chemfig{*4(A-B-C-D-)}\hspace{1cm} \chemfig{*4(-B-C-D-A)}| \section{Ions} The \verb|chemfig| commands enters the math mode\footnote{There is a problem with the placement of groups of atoms containing exponents or subscripts. See page~\pageref{alignement.vertical}.} of \TeX, so it is very simple to write an ion. A negative charge ($-$) must always be enclosed in braces to avoid \CF confusing it with the symbol for a single bond. \exemple{Acetate ion}|\chemfig{-(-[1]O^{-})=[7]O}| For purists it is possible to circle the charge of an ion by using the commands \verb|\ominus| and \verb|\oplus|. To meet all requirements, there are two other commands \verb|\chemabove| and \verb|\chembelow| which allow placement of charges above or below the current atom. \exemple{Some ions}|\chemfig{-(-[1]O^{\ominus})=[7]O} \hspace{1cm} \chemfig{\lewis{35,O}=\lewis{26,Cl}-\chemabove {\lewis{026,O}}{\ominus}} \vskip5pt \chemfig{-\chemabove{N}{\scriptstyle\oplus}(=[1]O)-[7]O^{\ominus}}| For those who are extremely picky, the commands \verb|\chemabove| and \verb|\chembelow| accept an optional argument which sets the distance between the charge and the atom. \exemple{Charge position}|\chemfig{\lewis{35,O}=C-\chemabove [3pt]{\lewis{246,O}}{\hspace{.5cm}\ominus}}| \section{Chemical equations} Here is an example of a chemical reaction: \exemple*{Chemical reaction}/\chemfig{**6(------)} \hspace{.5cm} + \hspace{.5cm} \chemfig{H_3C-Cl} \hspace{.5cm} $\xrightarrow{catalyst}$ \hspace{.5cm} \chemfig{**6(---(-)---)} \hspace{.5cm} + \hspace{.5cm} \chemfig{H-Cl}/ \CF adds two new commands \verb-\chemsign- and \verb-\chemrel- which slightly simplify the preceding syntax. \exemple*{Using the \CF commands}|\setchemrel{0pt}{1.2em}{6em} \chemfig{**6(------)}\chemsign[0.5cm]+\chemfig{H_3C-Cl} \chemrel[\itshape\tiny Catalyst]{->} \chemfig{**6(---(-)---)}\chemsign[0.5cm]+\chemfig{H-Cl}| \newpage \part{Operation of \CF} This part is devoted to describing the most common features of \CF. The outline of this description far exceeds that of ``\CF for the impatient``, but the user will find here explanations sufficient to draw most molecules. The presentation of features is done from a theoretical angle, and the goal of this part is not to draw real molecules but to give the user a formal description of the functionality of \CF. The ``Advanced usage'', page~\pageref{utilisation.avancee}, will be more practical and will illustrate advanced features for the most demanding uses. It will also highlight methods of building real molecules, page~\pageref{exemples.commentes}. Finally, the last part will give examples of molecules and the code used to draw them. \section{Groups of atoms} Drawing a molecule consists inherently of connecting groups of atoms with lines. Thus, in the molecule \chemfig{O=O}, there are two groups of atoms, each consisting of a single atom ``O''. {\fboxsep1pt However, in this molecule \molht{H_3C-C(-[:-30]OH)=[:30]O} there are four groups of atoms: ``$\mathrm{H_3C}$'', ``C'', ``O'' and ``OH''. For reasons which we shall see later, \CF splits each group into single atoms. Each atom extends up to the next capital letter or one of these special characters: {\ttfamily \boxedfalseverb{-} \boxedfalseverb{=} \boxedfalseverb{~} \boxedfalseverb{(} \boxedfalseverb{!} \boxedfalseverb{*} \boxedfalseverb{<} \boxedfalseverb{>} \boxedfalseverb{@}}. \CF ignores all characters inside braces when splitting groups into atoms. Therefore the first group of atoms ``$\mathrm{H_3C}$'' is split into two atoms: $\boxednode{H_3}{}$ and $\boxednode C{}$. In terms of chemistry, of course, these are not real atoms; $\mathrm{H_3}$, for example, consists of three hydrogen atoms. In what follows the word atom refers to \CF's definition. Thus \CF sees the preceding molecule as follows: \renewcommand*\printatom[1]{\fbox{\ensuremath{\mathrm{#1}}}} \molht{H_3C-[,1.75]C(=[:30,1.5]O)(-[:-30,1.5]OH)}} \section{Different types of bonds} As we have already seen (see page~\pageref{types.liaisons}), bonds can be one of nine types, each corresponding to the characters \boxedfalseverb-, \boxedfalseverb=, \boxedfalseverb~, \boxedfalseverb>, \boxedfalseverb<, \boxedfalseverb{>:}, \boxedfalseverb{<:}, \boxedfalseverb{>|} and \boxedfalseverb{<|}. \label{longueur.liaison}We must understand that when a bond is made between two atoms, these atoms are contained within invisible rectangular boxes. The centres of these two rectangles are separated by an adjustable distance $\Delta$ called the ``interatomic distance''. Furthermore, bonds do not connect to the exact edges of the rectangles: a length $\delta$, also adjustable, separates the edges of the rectangles and the beginning and end of the bond line. The rectangular boxes are made visible in the diagram below to help understanding. \begin{center} \begin{tikzpicture}[every node/.style={anchor=base,inner sep=1.5pt,outer sep=0pt,minimum size=0pt},baseline] \node[draw] at(0,0)(aa){\huge A}; \node[draw]at(4,0)(bb){\huge B}; \path[shorten <=5pt,shorten >=5pt,draw](aa)--(bb)coordinate[pos=0](al) coordinate[pos=1](bl); \node[draw,circle,fill,blue,minimum size=1.5pt,inner sep=0pt]at(al){}; \node[draw,circle,fill,blue,minimum size=1.5pt,inner sep=0pt]at([xshift=5pt]al){}; \node[draw,circle,fill,blue,minimum size=1.5pt,inner sep=0pt]at(bl){}; \node[draw,circle,fill,blue,minimum size=1.5pt,inner sep=0pt]at([xshift=-5pt]bl){}; \draw[blue,dash pattern=on 1pt off 1pt](bl)--([yshift=0.7cm]bl); \draw[blue,dash pattern=on 1pt off 1pt]([xshift=-5pt]bl)--([xshift=-5pt,yshift=0.7cm]bl); \draw[<->]([yshift=0.6cm]bl.center)--([xshift=-5pt,yshift=0.6cm]bl.center) node [midway,above,draw=none]{$\delta$}; \draw[blue,dash pattern=on 1pt off 1pt](al)--([yshift=0.7cm]al); \draw[blue,dash pattern=on 1pt off 1pt]([xshift=5pt]al)--([xshift=5pt,yshift=0.7cm]al); \draw[<->]([yshift=0.6cm]al.center)--([xshift=5pt,yshift=0.6cm]al.center) node [midway,above,draw=none]{$\delta$}; \node[draw,circle,fill,red,minimum size=2pt,inner sep=0pt]at(aa){}; \node[draw,circle,fill,red,minimum size=2pt,inner sep=0pt]at(bb){}; \draw[<->]([yshift=1cm]aa.center)--([yshift=1cm]bb.center) node [midway,above,draw=none] {$\Delta$} ; \draw[red,dash pattern=on 2pt off2pt](aa.center)--([yshift=1.1cm]aa.center); \draw[red,dash pattern=on 2pt off2pt](bb.center)--([yshift=1.1cm]bb.center); \end{tikzpicture} \end{center} \label{setatomsep}The macro \verb-\setatomsep{}- adjusts the interatomic distance $\Delta$. If the \verb-- is empty, it takes the default value of 3em. This command, like all other settings commands, affects all the following molecules. \exemple{Interatomic distance}|\setatomsep{2em}\chemfig{A-B}\par \setatomsep{50pt}\chemfig{A-B}| \label{setbondoffset}The command \verb-\setbondoffset{}- sets the spacing $\delta$ between the bond line and the atom. If the \verb-- is empty, $\delta$ takes the default value of 2pt. \exemple{Trimming bonds}|\setbondoffset{0pt}\chemfig{A-B}\par \setbondoffset{5pt}\chemfig{A-B}| If one bond is followed immediately by another, then \CF inserts an empty group \verb-{}-. Around this empty group the separation $\delta$ is zero: \exemple{Empty groups}/\chemfig{A-B=-=C}/ \nouveau\label{modif.retrait} The spacing $\delta$ for just one bond can be specified with the character \verb-#-. This character must be placed \emph{immediately} after the bond symbol and has one required argument between parentheses of the form ``\verb-#(,)-'', where \verb-- is the spacing $\delta$ at the beginning of the bond and \verb-- is the that at the end. If \verb-- is omitted, the spacing at the end of the bond takes the value of $\delta$ in effect at that time. One can see in the example how the shortening, set to 4pt to be more visible, is nullified for the bond arriving at ``B'', then for the one leaving ``B'', and finally for both: \begingroup \catcode`\#12 \exemple{Fine adjustment of bond shortening}/\setbondoffset{4pt} \chemfig{A-B-C}\par \chemfig{A-#(,0pt)B-C}\par \chemfig{A-B-#(0pt)C}\par \chemfig{A-#(,0pt)B-#(0pt)C}/ \endgroup By default, all atoms within groups of atoms are typeset in math mode (spaces are ignored). They may therefore contain math mode specific commands such as subscripts or superscripts\footnote{There is a problem with the placement of groups of atoms containing exponents or subscripts. See page~\pageref{alignement.vertical}.}: \exemple{Math mode}|\chemfig{A_1B^2-C _ 3 ^ 4}| There are settings specifically for Cram bonds. This syntax is used: \label{setcrambond} \centerverb/\setcrambond{}{}{}/ \smallskip Any empty argument takes its default value. The three arguments are: \begin{itemize} \item \verb-- is the size of the base of the triangle, and is 1.5pt by default; \item \verb-- is the thickness of the dots, and is 1pt by default; \item \verb-- is the spacing between the dots, and is 2pt by default. \end{itemize} Here is an example where the three dimensions are changed: \exemple{Modified Cram bonds}-\setcrambond{10pt}{0.4pt}{1pt} \chemfig{A>B>:C>|D}- \section{Bond angle} Each bond takes an optional argument in brackets. This optional argument can adjust every aspect of a bond, and consists of five optional fields separated by commas. The first of these fields defines the bond angle. Angles increase counterclockwise, and are relative to the horizontal. If the angle field is empty, the angle takes its default value of 0\degres. We will see later how to change this default. There are several ways of specifying the bond angle. \subsection{Predefined angles} When the angle field contains an integer, this represents the angle the bond makes relative to the horizontal, in multiples of 45\degres. For example, \verb-[0]- specifies an angle of 0\degres, \verb-[1]- is 45\degres, and so on up to \verb-[7]- which specifies an angle of 315\degres. The integer may lie outside the interval $[0,7]$, in which case the angle is reduced to the interval $[0,360)$. \exemple{Predefined angles}|\chemfig{A-B-[1]C-[3]-D-[7]E-[6]F}| These angles remain valid if the atoms are empty, and this is the case for all the features we will see below: \exemple{Predefined angles with empty groups}|\chemfig{--[1]-[3]--[7]-[6]}| \subsection{Absolute angles} If one wishes to specify an angle in degrees relative to the horizontal, then the optional angle field must take this form: \verb-[:]-. If necessary, the \verb-- is reduced to the interval $[0,360)$: \exemple{Absolute angles}/\chemfig{A-[:30]B=[:-75]C-[:10]D-[:90]>|[:60]-[:-20]E-[:0]~[:-75]F}/ \subsection{Relative angles}\label{angle.relatif} It is often useful to specify a bond angle relative to the preceding bond. This syntax must be then be used: \verb-[::]-. The sign of the \verb-- can be omitted if it is a \verb-+-. Here is a molecule where the first bond has an absolute angle of $-5\degres$, and the rest of the bond angles are incremented by 20\degres: \exemple{Result of relative angles}|\chemfig{A-[:-5]-[::+20]-[::20]B-[::+20]-[::20]C-[::20]}| One can ``break'' a chain of relative angles by putting an absolute or predefined angle where desired. Here, atom ``B'' is followed by a bond at an absolute angle of 315\degres. \exemple{Result of relative angles followed by absolute}|\chemfig{A-[:-5]-[::20]-[::20]B-[7]-[::20]C-[::20]}| \section{Length of a bond} Rather than speaking of length of a bond, we should use the term interatomic spacing. If effect, only the interatomic spacing is adjustable with \verb-\setatomsep- as we have seen on page~\pageref{longueur.liaison}. Once this parameter is set, the length of a bond depends on the content of atoms and, to a lesser extent, the angle the bond makes with the horizontal. It should be obvious that two ``slimmer'' atoms will have larger edge separations than two which are larger. This can be seen easily in the following example where an ``I'' atom is narrower than an ``M'' atom, which means that the bond between the ``I'' atoms is longer than that between the ``M'' atoms: \exemple{Influence of the size of atoms}|\chemfig{I-I}\par \chemfig{M-M}| This aspect of the size of atoms becomes particularly acute when the atom involves subscripts or superscripts. In this example, the bond is extremely short, to the point of confusion with a negative sign $-$: \exemple{Too-short bond}|\chemfig{A^{++}_{2}-B^{-}_3}| It is important to note that the exponent \verb+-+ is \emph{put inside braces}. If this were not done, \CF would stop the atom on this character, which is a bond character. The atom would then be ``\verb-B^-'', which would lead to unexpected results. We see in the example above that is it sometimes necessary to increase (or perhaps reduce) the interatomic distance associated with a bond. For this, the optional argument to bonds is actually made up of several comma-separated fields. As we have seen, the first field specifies the angle. The second field, if it is not empty, is a coefficient which multiplies the default interatomic distance $\Delta$. Thus, writing \verb+-[,2]+ asks that this bond have the default angle (first field is empty) and that the atoms it connects be separated by twice the default distance. \exemple{Modified bond length}/\chemfig{A^{++}_{2}-[,2]B^{-}_3}\par \chemfig{A-B-[,2]C=[,0.5]D}\par \chemfig{-=[,1.5]-[,0.75]=[:-20,2]}/ We can change the size of molecules by altering the font size or the argument of \verb-\setatomsep-, possibly on both \footnote{You can also use the second optional argument of \texttt{\string\chemfig}, see page~\pageref{arguments.optionnels}.}, being careful to confine these changes within a group if we want to limit the scope: \exemple{How to modify the size of molecule}/\normalsize \chemfig{H-[:30]O-[:-30]H}\par \setatomsep{2.5em}\chemfig{H-[:30]O-[:-30]H}\par \small \chemfig{H-[:30]O-[:-30]H}\par \footnotesize \chemfig{H-[:30]O-[:-30]H}\par \scriptsize \chemfig{H-[:30]O-[:-30]H}\par \tiny \chemfig{H-[:30]O-[:-30]H}/ \section{Departure and arrival atoms} A group of atoms can contain several atoms. Suppose we want to connect the group ``ABCD'' to the group ``EFG'' with a bond. \CF calculates which atom of the first group and which of the second group are to be connected by looking at the angle of bond relative to the horizontal. If the angle is between (but not including) $-90\degres$ and 90\degres{} (modulo 360\degres) then the bond is made between the last atom of the first group and the first atom of the second group. In all other cases, the bond is made between the first atom of the first group and the last atom of the second group. Here are some examples where the bond is in the interval $(-90,90)$, and where the bond is made between D and E: \exemple{Default atom connections}|\chemfig{ABCD-[:75]EFG}\quad \chemfig{ABCD-[:-85]EFG}\quad \chemfig{ABCD-[1]EFG}| In the following examples, the angles are in the interval $[90,270]$ and so the bond is made between A and G: \exemple[60]{Default atom connections}|\chemfig{ABCD-[:100]EFG}\quad \chemfig{ABCD-[:-110]EFG}\quad \chemfig{ABCD-[5]EFG}| One may sometimes want the bond partners to be atoms other than those determined by \CF. The departure and arrival atoms can be set with the optional bond argument by writing: \centerverb/[,,,]/ \smallskip where \verb-- and \verb-- are the numbers of the desired departure and arrival atoms. These atoms must exist, otherwise an error message will be given. \exemple{Specified atom connections}|\chemfig{ABCD-[:75,,2,3]EFG}\qquad \chemfig{ABCD-[:75,,,2]EFG}\qquad \chemfig{ABCD-[:75,,3,2]EFG}| \section{Customization of bonds} There is a fifth and last optional argument for bonds which is found after the fourth comma: \centerverb/[,,,,]/ \smallskip This \verb-- is passed directly to \TIKZ when the bond is drawn. There one can put characteristics such as colour (\verb-red-), dash type (\verb-dash pattern=on 2pt off 2pt-), thickness (\verb-line width=2pt-), or even decoration if the \TIKZ decoration library has been loaded. A bond can be made invisible by writing ``\verb-draw=none-''. To set several attributes, the syntax of \TIKZ is used, separating them by a comma: \exemple{Passing tikz code}|\chemfig{A-[,,,,red]B}\par \chemfig{A-[,,,,dash pattern=on 2pt off 2pt]B}\par \chemfig{A-[,,,,line width=2pt]B}\par \chemfig{A-[,,,,red,line width=2pt]B}| Numerous \TIKZ decoration libraries are available. For example, one can use the ``\verb-pathmorphing-'' library by putting \verb-\usetikzlibrary{decorations.pathmorphing}- in the preamble in order to draw wavy bonds: \exemple{Wavy bonds}|\chemfig{A-[,3,,,decorate,decoration=snake]B}| Cram bonds ignore thickness and dash settings. \section{Default values} At the beginning of each molecule, the default values for the optional arguments are initialized. They are: \begin{itemize} \item 0\degres{} for the bond angle; \item 1 for the length multiplication coefficient; \item \verb-- for the numbers of the departure and arrival atoms, which lets \CF calculate these based on the bond angle; \item \verb-- for the parameters passed to \TIKZ. \end{itemize} These default values can be changed for the whole molecule by beginning the molecule code with \centerverb/[,,,,- in parentheses. This \verb-- is the code of the submolecule which will be attached to the atom. In this example, the sub-molecule ``\verb/-[1]W-X/'' will be attached to atom ``B'': \exemple{A branch}|\chemfig{A-B(-[1]W-X)-C}| There can be several sub-molecules which are to be attached to the same atom. Just have several parentheses containing the code for each sub-molecule: \exemple{Multiple branches}|\chemfig{A-B(-[1]W-X)(-[6]Y-[7]Z)-C}| The code of each sub-molecule can define its own default values, which will be valid throughout the whole sub-molecule. Here a sub-molecule ``\verb/[:60]-D-E/'' is attached to atom ``B'', with a default angle of 60\degres{} absolute. A second sub-molecule ``\verb/[::-60,1.5]-X-Y/'' is attached to ``B'' with a default bond angle 60\degres{} less than that of the preceding bond (which will be the one between ``A'' and ``B'') and with an interatomic distance 1.5 times the default value: \exemple{Default values in branches}|\chemfig{A-B([:60]-D-E)([::-30,1.5]-X-Y)-C}| Observe what happens if, at the beginning of the main molecule, one writes ``\verb/[:-45]/'': \exemple{Effect of the default bond angle}|\chemfig{[:-45]A-B([:60]-D-E)([::-30,1.5]-X-Y)-C}| We see that the angle between the bond \verb/B-C/ and the bond \verb/B-X/ stays at 30\degres{} because it is a relative angle for the sub-molecule ``\verb/-X-Y/''. By contrast, the branch ``\verb/-D-E/'' stays inclined at 60\degres{} to the horizontal, and does not follow the rotation given by the $-45\degres$ angle at the beginning; this is expected because ``\verb/-D-E/'' has an absolute angle. It is essential that all the angles be relative in order to rotate the whole molecule. \subsection{Nesting} Sub-molecules may be nested, and the rules seen in the preceding paragraphs stay in force: \exemple{Nested branches}|\chemfig{A-B([1]-X([2]-Z)-Y)(-[7]D)-C}| \subsection{Method} Suppose now that we want to draw an acid anhydride molecule: \chemfig{R-C(=[::+60]O)-[::-60]O-[::-60]C(=[::+60]O)-[::-60]R} The best way to get this is to find the longest chain. Here, for example, we can draw the chain \verb/R-C-O-C-R/ taking into account angles and using only relative angles: \exemple{Acid anhydride structure}|\chemfig{R-C-[::-60]O-[::-60]C-[::-60]R}| To this structure we just have to add two ``\verb/=O/'' sub-molecules to each of the carbon atoms: \exemple{Acid anhydride}|\chemfig{R-C(=[::+60]O)-[::-60]O-[::-60]C(=[::+60]O)-[::-60]R}| Because we used only relative angles, we can rotate this molecule by giving a default angle of e.g. 75\degres: \exemple[70]{Rotation of a molecule}|\chemfig{[:75]R-C(=[::+60]O)-[::-60]O-[::-60]C(=[::+60]O)-[::-60]R}| \section{Connecting distant atoms} We have seen how to connect atoms \emph{which are adjacent in the code}. It is often necessary to connect atoms which are not next to each other in the code. Let's call these particular bonds ``distant bonds''. Let's take this molecule: \exemple{Branched structure}|\chemfig{A-B(-[1]W-X)(-[7]Y-Z)-C}| and suppose that we want to connect the atoms \verb/X/ and \verb/C/. In this case, \CF allows a ``hook'' to be placed \emph{immediately} after the atom of interest. The character used for a hook is ``\verb-?-'' because of its similarity to a hook. So, if one writes \verb/X?/ then the atom \verb/X/ will have a hook. Later in the code, all atoms followed by a \verb-?- will be connected to \verb/X/: \exemple{Distant bond}|\chemfig{A-B(-[1]W-X?)(-[7]Y-Z)-C?}| We could connect other atoms to X by following them with \verb-?-. Here it's the atoms \verb-C- and \verb-Z-: \exemple{Several distant bonds}|\chemfig{A-B(-[1]W-X?)(-[7]Y-Z?)-C?}| Now imagine if we were to leave the distant bonds \verb/X-C/ and \verb/X-Z/while adding another: \verb/A-W/. We must therefore ask for two \emph{different} hooks, one on \verb/A/ and the other on \verb/X/. Fortunately the character \verb/?/ has an optional argument: \centerverb/?[,,]/ \smallskip where each field takes its default value if it is empty: \begin{itemize} \item The \verb-- is the name of the hook: all alphanumeric characters (a\dots z, A\dots Z, 0\dots 9) are allowed\footnote{This is not exactly right. Actually all the characters that can be put between \texttt{\string\csname...\string\endcsname} are allowed.}. The name is \verb-a- by default. In the first occurrence of the hook with this name, only this field is used. \item \verb-- specifies how the atom with the current occurrence of the named hook is to be bonded to the atom with the first occurrence of the hook. There are two ways this can be done. First, this field can be an integer representing the desired bond type: 1=single bond, 2=double bond, etc. (See the table on page~\pageref{types.liaisons} for the bond codes.) Second, the field can be one of the bond character codes, provided that this character is \emph{between braces}. \item \verb-- will be passed directly to \TIKZ as we have seen with regular bonds. \end{itemize} Here is our molecule with the required distant bonds, then with the bond \verb/A-W/ and \verb/X-C/ customized: \exemple{Multiple distant bonds}|\chemfig{A?[a]-B(-[1]W?[a]-X?[b])(-[7]Y-Z?[b])-C?[b]}\par\medskip \chemfig{A?[a]-B(-[1]W?[a,2,red]-X?[b])(-[7]Y- Z?[b,1,{line width=2pt}])-C?[b,{>},blue]}| Several different hooks can be written after an atom. Suppose that in this unfinished pentagon, we wish to connect \verb/A-E/, \verb/A-C/ and \verb/E-C/: \exemple{An incomplete ring}|\chemfig{A-[:-72]B-C-[:72]D-[:144]E}| Then we must do this: \exemple{Multiple distant bonds}|\chemfig{A?[a]-[:-72]B-C?[a]?[b]-[:72]D-[:144]E?[a]?[b]}| \section{Rings} The preceding example shows how to draw a regular polygon, but the method used is tedious because the angles depend on the number of sides of the polygon. \subsection{Syntax} \CF can easily draw regular polygons. The idea is to attach a ring to an \verb// outside the ring with this syntax: \centerverb/*()/ \smallskip \verb// is the number of sides of the polygon and the \verb// describes the bonds and groups of atoms which make up its edges and vertices. This code \emph{must} begin with a bond because the atom is outside the ring. Here is a 5-ring, attached to the atom ``\verb/A/'': \exemple{5-ring}|\chemfig{A*5(-B=C-D-E=)}| A ring can also be drawn with one, several, or all the groups of atoms empty, as is the case for diagrams outside rings: \exemple{5-ring with empty groups}|\chemfig{*5(-=--=)}| A ring can be incomplete: \exemple{Incomplete 5-ring}|\chemfig{*5(-B=C-D)}| If a ring has a code which contains too many bonds and atom groups for the given number of vertices, all the bonds and groups over the maximum allowed are ignored: \exemple{Truncated 5-ring}|\chemfig{A*5(-B=C-D-E=F-G=H-I)}| It is possible to draw a circle or an arc in the inside of a ring. To do so, the following syntax is used: \centerverb/**[,,]()/ \smallskip where each field of the optional argument takes its default value if it is empty: \begin{itemize} \item \verb// and \verb// are the absolute angles of the start and finish of the arc. These default to 0\degres{} and 360\degres{} respectively so that a circle is drawn by default; \item \verb// is the code that will be passed to \TIKZ for drawing the arc. \end{itemize} \exemple{Rings and arcs}|\chemfig{**6(------)}\quad \chemfig{**[30,330]5(-----)}\quad \chemfig{**[0,270,dash pattern=on 2pt off 2pt]4(----)}| \subsection{Angular position} \subsubsection{At the start} As can be seen in the examples above, the rule is that the attachment atom ``\verb/A/'' is always at the south-west of the ring. Furthermore, the ring is always constructed counterclockwise, and the last bond descends vertically onto the attachment atom: \exemple{Angular position of rings}|\chemfig{A*4(-B-C-D-)}\qquad\chemfig{A*6(------)}| If this angular position is not convenient, it is possible to specify another angle using the optional argument at the beginning of the molecule. Here is a 6-cycle which has been rotated by $+30\degres$, by $-30\degres$, and lastly by $+60\degres$: \exemple[55]{Rotation of rings}|\chemfig{[:30]A*6(------)}\qquad \chemfig{[:-30]A*6(------)}\qquad \chemfig{[:60]A*6(------)}| \subsubsection{After a bond} When a ring does not begin a molecule and one or more bonds have already been drawn, the default angular position changes: the ring is drawn is such a way that the bond ending on the attachment atom bisects the angle formed by the first and last sides of the ring. Here is a simple case: \exemple{Bond ending on a ring}|\chemfig{A-B*5(-C-D-E-F-)}| The rule remains valid, whatever the angle of the preceding bond: \exemple{Bonds ending on a ring}|\chemfig{A-[:25]B*4(----)}\vskip5pt \chemfig{A=[:-30]*6(=-=-=-)}| \subsection{Branches on a ring} To have branches attached to the vertices of a ring, we use the syntax we have already seen: \centerverb/()/ \smallskip where the \verb// is that of the sub-molecule and the \verb-- is at the vertex. Unique to rings, the default angle of the sub-molecule is not 0\degres{} but is calculated so that it will bisect the sides leaving the vertex: \exemple{Branch on a ring}|\chemfig{X*6(-=-(-A-B=C)=-=-)}| A sub-molecule can be attached to the first vertex of a ring, just like the other vertices: \exemple{Ring and branches}|\chemfig{*5((-A=B-C)-(-D-E)-(=)-(-F)-(-G=)-)}| If one wants the bond leaving a vertex not to be the bisector of its sides, one can tinker with the optional global parameter or the optional bond parameter: \exemple[50]{Branches at specified angles}|\chemfig{*5(---([:90]-A-B)--)}\qquad \chemfig{*5(---(-[:90]A-B)--)}\qquad \chemfig{*5(---([::+0]-A-B)--)}| It is worth noting that in the third example, where a relative angle of 0\degres{} was given, the bonds of the branch are drawn in line with the preceding bond in the ring. This is the rule on page~\pageref{angle.relatif} which specified that the reference angle was that of the bond last drawn. We can now connect together rings with bonds: \exemple{Connected rings}|\chemfig{*6(--(-*5(----(-*4(----))-))----)}| \subsection{Nested rings} To ``glue'' two rings together, the syntax is only slightly different: the vertex is specified where the other ring is going to start. Simply follow this vertex by the usual syntax for a ring. Here for example is a 5-ring which is attached to the second vertex of a 6-ring: \exemple{Nested rings}|\chemfig{A*6(-B*5(----)=-=-=)}| Note that the ring which is going to be attached to the main ring has an angular position such that two of the rings' sides coincide. In addition, the 5-ring has only four bonds ``\verb/----/''. In effect, the fifth will be useless because it is the second side of the 6-ring, which has already been drawn. It is quite possible to glue multiple rings together: \exemple{Multiple nested rings}|\chemfig{*5(--*6(-*4(-*5(----)--)----)---)}| There is a case where a trick must be used. It can be seen in this example that the fourth side of the second 5-ring just passes through the centre of atom ``\verb-E-''. \exemple{Flawed drawing}|\chemfig{A-B*5(-C-D*5(-X-Y-Z-)-E-F-)}| This is normal because the second 5-ring (which is attached to atom ``\verb-D-'') is drawn \emph{before} \CF knows about atom ``\verb-E-''. In this case, it is necessary to use two hooks to draw the bond \verb/Z-E/: \exemple{Distant bond and ring}|\chemfig{A-B*5(-C-D*5(-X-Y-Z?)-E?-F-)}| We could also use a \verb-\phantom{E}- at the last vertex of the 5-ring: \exemple{Using \string\phantom}/\chemfig{A-B*5(-C-D*5(-X-Y-Z-\phantom{E})-E-F-)}/ \subsection{Rings and groups of atoms} Some care must be taken with rings when one or more vertices are made up of groups of atoms: \exemple{Ring and groups of atoms}|\chemfig{AB*5(-CDE-F-GH-I-)}| In order for the ring to have a regular shape, it is necessary to override the \CF mechanism which automatically calculates the departure and arrival atoms of bonds. Here, \verb/C-F/ and \verb/F-G/ must be connected by using the optional argument of these bonds: \exemple{Forced departure and arrival atoms}|\chemfig{AB*5(-CDE-[,,1]F-[,,,1]GH-I-)}| \section{Representing electron movements}\label{mecanismes-reactionnels} \nouveau Starting with \CF version 0.3, we can represent the movement of electrons in mesomeric effects or reaction mechanisms. This is done by marking the departure and arrival points of the electron movement arrow using the syntax ``\verb-@{}-''. This syntax allows a \TIKZ node to be placed and makes this node accessible outside the argument of the \verb-\chemfig- command thanks to the ``\texttt{remember picture}'' option which is passed to all the ``tikzpicture'' environments. It is assumed that the viewer supports ``picture remembering'' and that the compilation is done twice. Two types of diagrams can arise, so we can ask for: \begin{itemize} \item a zero size node on a bond using the syntax ``\verb-@{,}-'' 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 ``\verb--'' and the \verb--, which must be between 0 and 1, determines where the node is located on the bond. If ``\verb-@{}-'' is used, the \verb-- is set to 0.5 by default, which means that the node is placed halfway along the bond; \item a node on an atom using the syntax ``\verb-@{}-'' 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. \end{itemize} Once the \verb-\chemfig- command has drawn the molecule(s) and has placed the nodes with the syntax described above, we can connect these nodes to each other with \TIKZ instructions. These instructions are placed in the argument of the command \verb-\chemmove-\footnote{Actually, the \texttt{\string\chemmove} command puts its argument in a ``tikzpicture'' environment with the options ``\texttt{remember picture, overlay}''.} and has the following syntax if (for example) we need to connect a node named ``\verb--'' to the node named ``\verb--'': \centerverb|\chemmove[]{\draw[]()();}| \smallskip The optional argument \verb-- of the \verb-\chemmove- command will be added to the argument of the tikzpicture environment in which the links between the nodes will be drawn. The \verb-- and \verb-- instructions are describe in detail in the documentation of the \TIKZ package. \subsection{Mesomeric effects} To make these concepts concrete, let's take the example of a mesomeric effect involving a double bond and non-bonding lone pair conjugate. Let's begin with the possible delocalization of electrons from the double bond. We will place a node named ``db'' (double bond) in the middle of the double bond and a node named ``a1'' on the end of the double bond. \exemple{Mesomeric effect 1}/\chemfig{@{a1}=_[@{db}::30]-[::-60]\lewis{2,X}} \chemrel{<->} \chemfig{\chemabove{\vphantom{X}}{\ominus}-[::30]=_[::-60] \chemabove{X}{\scriptstyle\oplus}} \chemmove{\draw[->](db).. controls +(80:8mm) and +(145:8mm).. (a1);}/ As noted above, there is no comma after the node placed in the optional arguments of a bond; we write ``\verb|=_[@{db}::30]|'' and not ``\verb|=_[@{db},::30]|'' as one might be tempted to do. To link the nodes ``db'' and ``a1'' we have used the following syntax: \centerverb|\chemmove{\draw[->](db)..controls +(80:8mm) and +(145:8mm)..(a1);}| \medskip In this example we ask for an arrow (\verb/[->]/) and we use two control points\footnote{To find all the ways of connecting two nodes with \TIKZ, read the documentation for that package.}. These will be located using polar coordinates at 80\degres{} and 8~mm from ``db'' for the first and at 145\degres{} and 8~mm from ``a1'' for the second. Though this syntax may seem complicated at first reading, one need not be alarmed because its use will usually be a matter of copying and pasting. Only the names and coordinates of the control points need be changed, as can be verified from the example below, where an arrow has been added from the lone pair (node ``dnl'' to the single bond (node ``sb''). \exemple{Mesomeric effect 2}/\chemfig{@{a1}=_[@{db}::30]-[@{sb}::-60]@{dnl}\lewis{2,X}} \chemrel{<->} \chemfig{\chemabove{\vphantom{X}}{\ominus}-[::30]=_[::-60] \chemabove{X}{\scriptstyle\oplus}} \chemmove{ \draw[->](db)..controls +(100:5mm) and +(145:5mm)..(a1); \draw[->](dnl)..controls +(90:4mm) and +(45:4mm)..(sb);}/ For our new arrow we have set the control points as follows: 4~mm at an angle of 90\degres{} from ``dnl'' and 4~mm at an angle of 45\degres{} from ``sb''. But we are not completely satisfied, since we would like the arrow not to touch the line segment representing the lone pair. To do this we will add some options to our arrow. \exemple{Mesomeric effect 3}/\chemfig{@{a1}=_[@{db}::30]-[@{sb}::-60]@{dnl}\lewis{2,X}} \chemrel{<->} \chemfig{\chemabove{\vphantom{X}}{\ominus}-[::30]=_[::-60] \chemabove{X}{\scriptstyle\oplus}} \chemmove[->]{ \draw(db).. controls +(100:5mm) and +(145:5mm).. (a1); \draw[shorten <=3pt,shorten >=1pt](dnl) .. controls +(90:4mm) and +(45:4mm) .. (sb);}/ The option ``\verb|shorten <=3pt|'' indicates that the tail of the arrow is to be shortened by 3~pt just as ``\verb|shorten >=2pt|'' means that the head of the arrow is shortened by 2~pt. We can use all the power of \TIKZ instructions to modify the style of the arrow. Here we change the head of the arrow leaving the double bound, writing ``\verb|-stealth|'' instead of ``\verb|->|'', and we draw the arrow with a fine dashed red line. We also add the letter $\pi$ above the middle of the arrow: \exemple{Mesomeric effect 4}/\chemfig{@{a1}=_[@{db}::30]-[@{sb}::-60]@{dnl}\lewis{2,X}} \chemrel{<->} \chemfig{\chemabove{\vphantom{X}}{\ominus}-[::30]=_[::-60] \chemabove{X}{\scriptstyle\oplus}} \chemmove{ \draw[-stealth,thin,dash pattern= on 2pt off 2pt,red] (db).. controls +(100:5mm) and +(145:5mm).. node[sloped,above] {$\pi$} (a1); \draw[->, shorten <=3pt, shorten >= 1pt] (dnl).. controls +(90:4mm) and +(45:4mm).. (sb);}/ In the following example, we'll see how to indicate the position of the departure or arrival anchor points of the arrow. If we write \exemple{Departure or arrival anchor point 1}/\chemfig{@{x1}\lewis{1:,X}} \hspace{2cm} \chemfig{@{x2}\lewis{2|,X}} \chemmove{\draw[->,shorten >=4pt] (x1).. controls +(90:1cm) and +(90:1cm).. (x2);}/ Note that the tail of the arrow does not leave correctly from our electrons; it leaves from the middle of the upper edge of the node. Indeed, we chose a departure angle of 90~\degres{} and so \TIKZ makes the arrow leave from the anchor ``x1.90'' which corresponds to the intersection of the ray leaving from the centre of node ``x1'' at a 90\degres{} angle relative to the horizontal and of the edge of the rectangular node. To get the arrow departure angle that we want, we must specify its position. After some trial and error, it is ``x1.57'': \exemple{Departure or arrival anchor point 2}/\chemfig{@{x1}\lewis{1:,X}} \hspace{2cm} \chemfig{@{x2}\lewis{2|,X}} \chemmove{\draw[->,shorten <=4pt,shorten >=4pt] (x1.57).. controls +(60:1cm) and +(120:1cm).. (x2);}/ In some cases it will be easier to use Cartesian coordinated for the control points. Here we use just one control point placed 1~cm to the right of and 1.5~cm above ``x1'': \exemple{A single control point}/\chemfig{@{x1}\lewis{1:,X}} \hspace{2cm} \chemfig{@{x2}\lewis{2|,X}} \chemmove{\draw[->,shorten <=4pt,shorten >=4pt] (x1.57).. controls +(1cm,1.5cm).. (x2);}/ All the graphics drawn by means of the command \verb|\chemmove| are superimposed and will not be included in the bounding boxes. We can see this in the preceding example. \subsection{Reaction mechanisms} Thanks to the option \verb|remenber picture| which is passed to all the ``tikzpicture'' environments we can easily draw arrows indicating reaction mechanisms. Let's take for example the first step of the esterification reaction. \exemple{Esterification: step 1}/\setatomsep{7mm} \setchemrel{}{}{5mm} \chemfig{R-@{dnl}\lewis{26,O}-H} \chemsign{+} \chemfig{R-@{atoc}C([6]-OH)=[@{db}]O} \chemrel[\chemfig{@{atoh}\chemabove{H}{\scriptstyle\oplus}}]{<>} \chemmove[->,shorten <=2pt]{ \draw[shorten >=2pt](dnl).. controls +(90:1cm) and +(north:1cm).. (atoc); \draw[shorten >=6pt](db).. controls +(north:5mm) and +(100:1cm).. (atoh);}/ The use of the \verb|\chemabove{}{}| command does not change the dimensions of the bounding box of \verb||. For this reason we can run into some difficulty in pointing to the symbol representing the charge carried ($\oplus$ or $\ominus$). In the example above the solution is to create a control point with an angle of 110\degres{} at 1~cm from ``atoh'' and to shorten the arrow by 6pt. In the following example, the second step of the esterification reaction, we can see that the arrow can take more complicated forms without complicating the code. \exemple{Esterification: step 2}/\setatomsep{7mm} \setchemrel{}{}{5mm} \chemfig{R-O-C(-[2]R)(-[6]OH)-@{dnl}\lewis{26,O}H}\hspace{1cm} \chemfig{@{atoh}\chemabove{H}{\scriptstyle\oplus}} \chemmove{ \draw[->,shorten <=2pt, shorten >=7pt] (dnl).. controls +(south:1cm) and +(north:1.5cm).. (atoh);}/ The rest is left as an exercise to the reader\dots. \section{Writing a name under a molecule}\label{chemname} For convenience, \CF can write the name of a molecule underneath it with the command \centerverb/\chemname[]{\chemfig{}}{}/ \smallskip The \verb--, which is 1.5ex by default, will be inserted between the baseline of the molecule and the top of the letters of the \verb--. The \verb-- will be centred relative to the molecule, but the \verb-- may not contain multiple paragraphs. As we see in this example: \chemname{\chemfig{H-O-H}}{\scriptsize\bfseries The water molecule: $\mathrm{\mathbf{H_2O}}$}, the \verb-- which is displayed under the molecule is taken into account only for the vertical size of the bounding box. The horizontal size of \verb-- is always zero. Here is a reaction with the names under the molecules: \exemple*{Displaying names of molecules}/ \chemname{\chemfig{R-C(-[:-30]OH)=[:30]O}}{Carboxylic acid} \chemsign{+} \chemname{\chemfig{R'OH}}{Alcohol} \chemrel{->} \chemname{\chemfig{R-C(-[:-30]OR')=[:30]O}}{Ester} \chemsign{+} \chemname{\chemfig{H_2O}}{Water}/ There are some limitations to this command. Suppose we switch the acid and the alcohol on the left side: \exemple*{Name alignment 1}/ \chemname{\chemfig{R'OH}}{Alcohol} \chemsign{+} \chemname{\chemfig{R-C(-[:-30]OH)=[:30]O}}{Carboxylic acid} \chemrel{->} \chemname{\chemfig{R-C(-[:-30]OR')=[:30]O}}{Ester} \chemsign{+} \chemname{\chemfig{H_2O}}{Water}/ In fact, to draw the \verb-- the command \verb-\chemname- inserts 1.5ex${}+{}$\emph{the largest of the depths\footnote{In \TeX{} terms, the depth is the dimension which extends vertically below the baseline.} of the molecules thus far} below the baseline of each molecule (light grey for the examples in this manual). The macro \verb-\chemnameinit{}- initializes this largest depth with the \verb--. Therefore one should: \begin{itemize} \item write \verb-\chemnameinit{}- before using the \verb-\chemname- command in a reaction, unless the reaction begins with the deepest molecule; \item write \verb-\chemnameinit{}- after having written all the names in a chemical reaction lest the greatest depth in this reaction interfere with a future reaction. \end{itemize} Thus the correct code uses \verb-\chemnameinit- before and after the reaction: \exemple*{Name alignment 2}/ \chemnameinit{\chemfig{R-C(-[:-30]OH)=[:30]O}} \chemname{\chemfig{R'OH}}{Alcohol} \chemsign{+} \chemname{\chemfig{R-C(-[:-30]OH)=[:30]O}}{Carboxylic acid} \chemrel{->} \chemname{\chemfig{R-C(-[:-30]OR')=[:30]O}}{Ester} \chemsign{+} \chemname{\chemfig{H_2O}}{Water} \chemnameinit{}/ Finally, to write a name on multiple lines, the command \verb-\\- encountered in a \verb-- causes a line break\footnote{Conversely, the command \texttt{\textbackslash par} is forbidden and causes a compilation error.}: \exemple*{Name on 2 lines}/ \chemname{\chemfig{R-C(-[:-30]OH)=[:30]O}}{Carboxylic\\acid} \chemsign{+} \chemname{\chemfig{R'OH}}{Alcohol} \chemrel{->} \chemname{\chemfig{R-C(-[:-30]OR')=[:30]O}}{Ester} \chemsign{+} \chemname{\chemfig{H_2O}}{Water} \chemnameinit{}/ \newpage \part{Advanced usage}\label{utilisation.avancee} \section{Separating atoms}\label{decoupage.atomes} \nouveau The atom separating mechanism described previously extends each atom until the next capital letter or one of the characters {\ttfamily \boxedfalseverb{-} \boxedfalseverb{=} \boxedfalseverb{~} \boxedfalseverb{(} \boxedfalseverb{!} \boxedfalseverb{*} \boxedfalseverb{<} \boxedfalseverb{>} \boxedfalseverb{@}} In certain cases this automatic separation produces incorrect atoms which can translate into an imperfect diagram. Consider this example molecule, noting that the ``\texttt('' character is placed between braces so that \CF doesn't incorrectly create a branch: \exemple*{Alkene}/\chemfig{CH_3CH_2-[:-60,,3]C(-[:-120]H_3C)=C(-[:-60]H)-[:60]C{(}CH_3{)}_3}/ We find that the bond which arrives at the carbon atom in the upper right is too short. This happens because, if we apply the \CF rules for separating atoms to the upper right group, the atoms are split in this way: ``\texttt{\detokenize{C{(}}}'', ``\texttt{\detokenize{C}}'', ``\texttt{\detokenize{H_3{)}_3}}''. We now realize that the first atom contains a parenthesis and thus has too great a depth in math mode; we can see this by making the bounding boxes visible: \begin{center} \fboxsep=0pt \renewcommand*\printatom[1]{\fbox{\ensuremath{\mathrm{#1}}}}% \chemfig{CH_3CH_2-[:-60,,3]C(-[:-120]H_3C)=C(-[:-60]H)-[:60]C{(}CH_3{)}_3}% \end{center} The character ``|'' forces splitting of the atom when it is encountered. Thus we can write \texttt{C\textcolor{red}{|}\detokenize{{(CH_3)_3}}} to ensure that \CF separates just two atoms here: ``\texttt{\detokenize{C}}'' and ``\texttt{\detokenize{{(CH_3)_3}}}''. The problem of the too-short bond is thus solved: \exemple*{Alkene}/\chemfig{CH_3CH_2-[:-60,,3]C(-[:-120]H_3C)=C(-[:-60]H)-[:60]C|{(CH_3)_3}}/ \section{Displaying atoms}\label{perso.affichage} Once a molecule has been split into atoms, the macro \verb-\printatom- is called internally by \CF in order to display each atom. Its sole argument is the code of the atom to be displayed (e.g. ``\verb-H_3-''). By default, this macro enters math mode and displays its argument with the math font family ``rm''. It is defined by the following code: \hfill\verb-\newcommand*\printatom[1]{\ensuremath{\mathrm{#1}}}-\hfill\null One can modify the code of this macro to customize how atoms are displayed. In the following example, we redefine \verb-\printatom- so that each atom will be enclosed in a rectangular box: \exemple{Redefinition of \string\printatom}/\fboxsep=1pt \renewcommand*\printatom[1]{\fbox{\ensuremath{\mathrm{#1}}}} \chemfig{H_3C-C(=[:30]O)(-[:-30]OH)}/ Here is how to redefine it to use the ``sf'' font family of math mode: \exemple{Atoms displayed with ``sf'' font family}/\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}} \chemfig{H_3C-C(=[:30]O)(-[:-30]OH)}/ \section{Optional arguments}\label{arguments.optionnels} \nouveau The \verb-\chemfig- command takes two optional arguments; their syntax is as follows: \centerverb|\chemfig[][]{}| \smallskip The first optional argument \verb-- contains \TIKZ instructions which will be passed to the tikzpicture environment in which the molecule is drawn. The second optional argument \verb-- contains \TIKZ instructions which will be executed when each node\footnote{These instructions are added to the end of the argument of \texttt{every node/.style\{\}}. This argument contains by default the following instructions: ``{\ttfamily anchor=base,inner sep=0pt,outer sep=0pt,minimum size=0pt}''.} is drawn. With the use of the first optional argument one can, for example, choose the global colour or thickness of lines: \exemple{Style choice}/\chemfig{A-B-[2]C}\par\medskip \chemfig[line width=1.5pt]{A-B-[2]C}\par\medskip \chemfig[red]{A-B-[2]C}/ With the second optional argument, one can choose the colour of nodes drawn by \TIKZ, change the angle of the drawing or its scale: \exemple{Style choices}/\chemfig{A-B-[2]C}\par\medskip \chemfig[][red]{A-B-[2]C}\par\medskip \chemfig[dash pattern=on 1pt off 2pt][red]{A-B-[2]C}\par\medskip \chemfig[][rotate=20]{A-B-[2]C}\par\medskip \chemfig[][scale=0.5]{A-B-[2]C}/ \section{Vertical alignment}\label{alignement.vertical} In some cases with condensed structural diagram of molecules having horizontal bonds, the placement of groups of atoms is incorrect. Careful study of the following example shows that the groups of atoms are not correctly aligned on the baseline: \exemple*{Vertical placement}/\Huge\setatomsep{2em} \chemfig{A^1-B-C-D}\qquad \chemfig{E_1-F-G-H}/ Surprisingly, the second atom is correctly aligned while the last two undergo a vertical shift which seems to be the results of the different height of the bounding box of the atoms ``\verb-A^1-'' and ``\verb-E_1''-. In order to understand this phenomenon, we need to consider how \CF places groups of atoms relative to each other. Let us limit ourselves to the case of horizontal bonds in order to simplify terminology, although the algorithm is the same for other bonds. A horizontal bond leaves from the middle of the right side of the bounding box of the departure atom of this bond. The arrival atom is positioned in such a way that the middle of the left side of its bounding box is at the end of the bond. It follows that the vertical placement of the arrival atom depends on the height of the departure atom. To limit this phenomenon, \CF adds to each arrival atom the \verb-\vphantom- of the departure atom, but does not include it in the contents of the arrival atom; this \verb-\vphantom- is not intended to affect the following atoms. The atoms remaining in each group are aligned so that their baseline coincides with the baseline of the preceding atom. The defective alignment can thus be explained. The atoms ``\verb-B-'' and ``\verb-F-'' are aligned correctly as they reflect the height of the atoms before them because of their \verb-\vphantom-. For the atoms ``\verb-C-'' and ``\verb-F-'', the heights of the immediately preceding atoms are taken into account, but those of the atoms ``\verb-A^1-'' and ``\verb-E_1-'' are ignored! It follows that these atoms are a little too high or too low, depending on the height of these bonds. We can show this by making visible the bounding boxes of the atoms; one sees clearly that the atoms ``\verb-B-'' and ``\verb-F-'' have bounding boxes that reflect the heights of the immediately preceding atoms: \exemple*{Vertical placement and bounding boxes}/\Huge\setatomsep{2em} \fboxsep=0pt \renewcommand\printatom[1]{\fbox{\ensuremath{\mathrm#1}}} \chemfig{A^1-B-C-D}\qquad \chemfig{E_1-F-G-H}/ Since there is no satisfactory manual solution, this problem can be worked around manually by putting \emph{inside} the third atom a \verb-\vphantom- having the same height as the first, so that the height affects the following atoms: \exemple*{Vertical placement workaround}/\Huge\setatomsep{2em} \chemfig{A^1-B-{\vphantom{A^1}C}-D}\qquad \chemfig{E_1-F-{\vphantom{E_1}G}-H}/ \nouveau \label{chemskipalign}For any group of atoms it is possible to temporarily deactivate the alignment adjustment mechanism and thus neutralize the \verb-\vphantom-. Simply place the \verb-\chemskipalign- command in the group of atoms; the alignment will resume in the following group of atoms as if the group of atoms containing \verb-\chemskipalign- had never existed. The following example shows the effects of this instruction: the reference point of the box containing the first atom is placed at the level of the bond which arrives from the left. The bounding boxes of the atoms are drawn in the second line. \exemple[60]{Deactivation of the alignment mechanism}/\large \chemfig{A-.-B}\quad \chemfig{A-\chemskipalign.-B}\par\bigskip \fboxsep=0pt \renewcommand\printatom[1]{\fbox{\ensuremath{\mathrm{#1}}}} \chemfig{A-.-B}\quad \chemfig{A-\chemskipalign.-B}/ This command is to be used with caution lest the alignment of atoms in the next group be disrupted. In general, all will be well if the group of atoms featuring \verb-\chemskipalign- contains \emph{a single atom} whose height and depth are \emph{less} than those of the preceding and following atoms, and if the preceding and following atoms have identical heights and depths. Here is an example of the mess that results when the group of atoms contains two atoms, here ``\verb-\chemskipalign.-'' and ``\verb-B-'': \exemple{Consequence of the \string\chemskipalign command}/\large \fboxsep=0pt \renewcommand\printatom[1]{\fbox{\ensuremath{\mathrm{#1}}}} \chemfig{A-\chemskipalign.B-C}/ This feature can sometimes be useful. Suppose we want to draw the following molecule \begin{center} \catcode`;12 \def\emptydisk{\chemskipalign\tikz\draw(0,0)circle(2pt);}% \def\fulldisk{\chemskipalign\tikz\fill(0,0)circle(2pt);}% \chemfig{A-#(,0pt)\emptydisk-#(0pt,0pt)\fulldisk-#(0pt)B}% \end{center} We can define commands which will draw the empty and full disks with \TIKZ. To ensure that these disks are at the right height, namely the height of the bond arriving at them, we will use the command \verb-\chemskipalign-. In the second line below the bonds are ``stuck'' to the disks by using the ability to change the bond shortening with the ``\verb-#-'' character, a feature seen on page~\pageref{modif.retrait}. \begingroup\catcode`;12 \catcode`#12 \exemple{Use of \string\chemskipalign\ and #}/ \begingroup \def\emptydisk{\chemskipalign\tikz\draw(0,0)circle(2pt);} \def\fulldisk{\chemskipalign\tikz\fill(0,0)circle(2pt);} \chemfig{A-\emptydisk-\fulldisk-B}\par \chemfig{A-#(,0pt)\emptydisk-#(0pt,0pt)\fulldisk-#(0pt)B} \endgroup/\endgroup \section{Shifted double bonds} All double bonds are made up of two line segments, and these segments are drawn on either side of the imaginary line along which a single bond would be drawn. It is possible to shift a double bond so that one of the line segments lies on the imaginary line. The other segment is then shifted above or below the bond. Actually, it is more correct to say ``left'' or ``right'' of the imaginary line, as the bond is traversed in the direction of drawing. To shift the bond to the left, write ``\verb-=^-'' and to shift it to the right, write ``\verb-=_-'': \exemple{Shifted double bonds}/\chemfig{A-=-B}\par \chemfig{A-=^-B}\par \chemfig{A-=_-B}/ In rings, double bonds are automatically shifted to the left. However, they can be shifted to the right by specifying it with ``\verb-=_-'': \exemple{Shifted double bonds and rings}/\chemfig{*6(-=-=-=)}\qquad \chemfig{*6(-=_-=_-=_)}/ Shifted bonds are particularly useful in drawing skeleton diagrams of molecules consisting of carbon chains with double bonds. They give a continuous zig-zag path, whereas the path will be broken with regular double bonds: \exemple{Shifted bonds and skeleton diagrams}/\chemfig{-[:30]=[:-30]-[:30]=[:-30]-[:30]}\par \chemfig{-[:30]=^[:-30]-[:30]=^[:-30]-[:30]}\par \chemfig{-[:30]=_[:-30]-[:30]=_[:-30]-[:30]}/ \section{Delocalized double bonds} It is sometimes necessary to draw a double bond so that one line segment is dashed while the other is solid\footnote{Thanks to Andreas \textsc{Bröermann} who suggested this feature and who gave me the solution to this problem.}. This feature is not hard-coded into \CF; instead \TIKZ, its ``decorations'' library and its programmable styles make it possible. First of all, after having loaded the ``decorations'' library by putting \verb-\usetikzlibrary{decorations}- in the preamble, a decoration named ``ddbond'' (for Dashed Double Bond) is defined (lines 1 to 14) and then two \TIKZ styles called ``lddbond'' and ``rddbond'' (lines 15 and 16). For the former, the dashed line segment is on the left of the solid middle segment; for the latter it is on the right. These styles can be called with the fifth optional argument of bonds: \exemple*{Custom decorations}|\pgfdeclaredecoration{ddbond}{initial} { \state{initial}[width=4pt] { \pgfpathlineto{\pgfpoint{4pt}{0pt}} \pgfpathmoveto{\pgfpoint{2pt}{2pt}} \pgfpathlineto{\pgfpoint{4pt}{2pt}} \pgfpathmoveto{\pgfpoint{4pt}{0pt}} } \state{final} { \pgfpathlineto{\pgfpointdecoratedpathlast} } } \tikzset{lddbond/.style={decorate,decoration=ddbond}} \tikzset{rddbond/.style={decorate,decoration={ddbond,mirror}}} \setatomsep{4em} \chemfig{[:-30]R-C-[::60]C(-[::60,,,,rddbond]O)-[,,,,lddbond]N(-[::-60]H)-[::60]C-R}| \section{Saving a sub-molecule}\label{definesubmol} \CF is capable of saving a \verb-- as an alias for reuse in a more compact form in the code of a molecule. This is particularly useful when the \verb-- appears several times. To do this, one gives the command \centerverb|\definesubmol{}{}| \smallskip which saves the \verb// for recall in the code of the molecule via the shortcut ``\verb/!{name}/''. This \verb-- can be: \begin{itemize} \item a sequence of characters: all the alphanumeric characters able to be between \texttt{\string\csname} and \texttt{\string\endcsname} are accepted; \item \nouveau[30pt] a control sequence. \end{itemize} In all cases, if the alias is already defined you should not overwrite it with a new definition using \verb-\definesubmol-. A warning will be issued to the user that the old alias will be overwritten by the new one. To override the definition of an alias made previously, use:\label{redefinesubmol} \centerverb|\redefinesubmol{}{}| \smallskip Here is a code which draws the pentane molecule. An alias ``\verb/xy/'' was defined beforehand for the code \verb/CH_2/: \exemple{Pentane}|\definesubmol{xy}{CH_2} \chemfig{H_3C-!{xy}-!{xy}-!{xy}-CH_3}| In this case the technique is not very interesting because ``\verb/!{xy}/'' is just as long to type as the code it replaces. But in certain cases, this feature saves a lot of space in the code of the molecule and increases readability. In the following example, we draw the complete structural diagram of butane. We will define an alias with the control sequence ``\verb/\xx/'' for the sub-molecule $\mathrm{CH_2}$. If we use only relative angles, it is possible to rotate the entire molecule to any given angle by using the optional global angle parameter which specifies the default bond angle of the main molecule. It is set to 15\degres{} here: \exemple{Butane}|\definesubmol\xx{C(-[::+90]H)(-[::-90]H)} \chemfig{[:15]H-!\xx-!\xx-!\xx-!\xx-H}| \nouveau The \verb-\definesubmol- command takes an optional argument; its syntax is as follows: \centerverb/\definesubmol{}[]{code2}/ \medskip When the optional argument is present, the alias ``\verb-!-'' will be replaced by \verb'' if the bond which arrives at the alias comes from the right, i.e., if the angle which the arriving bond makes is between but is not equal to 90\degres{} and 270\degres{}. For all the other cases where the bond arrives from the left of vertically, the alias will be replaced by \verb--. We will define a control sequence \verb-\Me- pour ``methyl'' so that the alias ``\verb-!\Me-'' will be replaced by ``\verb-H_3C-'' when the bond arrives from the right and by ``\verb-CH_3-'' when it arrives from the left. We can observe in the example that with this alias we need no longer worry about the angle: \exemple{Dual alias}/\definesubmol\Me[H_3C]{CH_3} \chemfig{*6((-!\Me)=(-!\Me)-(-!\Me)=(-!\Me)-(-!\Me)=(-!\Me)-)}/ \section{Decorations} \subsection{Lewis diagrams}\label{lewis} The macro \verb+\lewis+ allows placement of pairs of electrons, of single electrons, or of empty slots. This syntax is used: \centerverb|\lewis{...,}| \smallskip where the \verb--\dots\verb-- represent the desired positions (in multiples of 45\degres) around the \verb--. These whole numbers must be between 0 and 7. This command can also be used inside the argument of \verb-\chemfig-: \exemple{The \string\lewis\ macro}|\lewis{0246,A}\par\medskip \lewis{1357,B}\par\medskip \chemfig{H-\lewis{26,O}-S(=[2]\lewis{13,O}) (=[6]\lewis{57,O})-\lewis{26,O}-H}| If one wishes to draw two electrons instead of a line, follow the integer with a ``\verb-:-''. If one wishes to draw a single electron, follow it with a ``\verb-.-''. To draw a lacuna, follow it with a ``\verb-|-'': \exemple{Lewis diagrams}*\lewis{0:2:4:6:,C}\qquad\lewis{1:3:5:7:,C}\par\bigskip \lewis{0.2.4.6.,C}\qquad\lewis{1.3.5.7.,C}\par\bigskip \lewis{0:2.4|,X}\par\bigskip Hydronium ion: \chemfig{H-\lewis{5|7,O^+}(-[2]H)-H}* All the decorations drawn by \verb-\lewis- are not included in the bounding box of the atom; they are drawn afterwards. A consequence of this is seen in the two examples above, where the frame does not appear to be properly fitted to the drawing of the molecule, which extends downward slightly. This will be seen more often in this the ``Decorations'' chapter, which presents commands which do not change the bounding box. This can be seen more clearly by drawing an \verb-\fbox- around decorated atoms: \exemple{Bounding box and the \string\lewis\ macro}*\fboxsep0pt \fbox{\lewis{0.2.4.6.,A}}\par\medskip \fbox{\lewis{13,B}}* \label{setlewis}Several parameters can be set with the help of the macro \centerverb|\setlewis[dim1]{}{}{}| \smallskip If an argument is empty, it takes its default value. \begin{itemize} \item \verb-- is the width of the rectangle which represents the empty slot obtained whith the character ``|''; \item \verb-- is the distance between the bounding box and the decoration. It is 0.2ex by default; \item \verb-- is the length of the line segment representing a pair of electrons. It is 1.5ex by default; \item \verb-- is code which is passed directly to \TIKZ. This code is empty by default. \end{itemize} \exemple{Parameters for the \string\lewis\ macro}*\setlewis{4pt}{1.5em}{red} \chemfig{A-\lewis{26,B}-C}\par\bigskip \setlewis{}{}{line width=0.4pt} \chemfig{A-\lewis{2|,B}-C}* \subsection{Stacking characters} The macros\label{chemabove} \centerverb|\chemabove[]{}{}| and \centerverb|\chembelow[]{}{}| \smallskip place the \verb-- above and below the \verb-- respectively at a vertical distance \verb--, without changing the bounding box of \verb--. The length \verb-- is 1.5pt by default. These commands are independent of the macro \verb-\chemfig- and can be used either inside or outside its argument. They are especially useful in rings, if care is taken to put braces around the letters A, B, C and D in order to prevent \CF from starting a new atom on these letters: \exemple{Staking in rings}|\chemfig{*5(-\chembelow{A}{B}--\chemabove{C}{D}--)}| They are sometimes useful for placing pseudo-exponents which do not change the bounding box of the atoms, so that the bonds do not end up being too short: \exemple{Hydronium ion}*\chemfig{H-\chemabove{\lewis{5|7,O}}{\quad\scriptstyle+}(-[2]H)-H}* \subsection{Chemical reactions} To write chemical reactions, \CF provides a command for the signs and a command for the arrows. \label{chemsign}The command \verb-\chemsign[]- typesets the \verb--, which is surrounded on both sides by an unbreakable horizontal space \verb-- defaulting to 0.5em. \label{chemrel}The command \verb-\chemrel[][]{}- draws an arrow where the optional arguments \verb-- and \verb-- are placed above and below the arrow respectively, without modifying its bounding box. The \verb-- is passed directly to \TIKZ except when it involves ``\verb/<>/'', which allows two arrows to be drawn one above the other. \exemple{Types of arrows}*A\chemrel{->}B\par A\chemrel{<-}B\par A\chemrel{<->}B\par A\chemrel{<>}B\par A\chemrel{->,red,thick}B* \label{setchemrel}The command \verb-\setchemrel{}{}{}- allows settings of the dimensions used in drawing the arrow: \begin{itemize} \item \verb-- is the vertical spacing between the arrow and the optional text above and/or below it. If the argument is empty, it defaults to 2pt; \item \verb-- is the unbreakable horizontal space inserted before and after the arrow. If the argument is empty, it defaults to 0.7em; \item \verb-- is the length of the arrow. If the argument is empty, if defaults to 4em. \end{itemize} \exemple{Text above arrows}*\setchemrel{1pt}{}{6em} A\chemrel[\footnotesize above][\tiny below]{<->}B* Here is an example of a chemical reaction: \exemple*{Chemical reaction}|\setchemrel{0pt}{1.2em}{6em} \chemfig{**6(------)}\chemsign+\chemfig{H_3C-Cl} \chemrel[\itshape\footnotesize Catalyst]{->} \chemfig{**6(---(-)---)}\chemsign+\chemfig{H-Cl}| And another: \exemple*{Synthesis of phenylacetylene}/\chemfig{*6(-=*6(-(-Br)-(-Br))-=-=)} \chemrel[\chemfig{NaNH_2}][\chemfig{NH_3}]{->} \chemfig{*6(-=(-~)-=-=)}/ \section{Using {\ttfamily\textbackslash chemfig} in the {\ttfamily tikzpicture} environment} It is possible to call the \verb-\chemfig- inside a \verb-tikzpicture- environment: \exemple{\textbackslash chemfig inside tikzpicture}|\begin{tikzpicture}[help lines/.style={thin,draw=black!50}] \draw[help lines] (0,0) grid (4,4); \draw(0,0) -- (2,1); \draw(2,2) circle (0.5); \node at (1,3) {\chemfig{A=B-[:30]C}}; \node[draw,red,anchor=base] at(3,2){\chemfig{X>[2,,,,blue]Y}}; \end{tikzpicture}| \section{Beyond chemistry}\label{style.noeuds} At heart \CF is a tool for drawing graphs, and this tool has been programmed to adapt it for chemistry. In some ways it is possible to return \CF to its roots to draw organization charts or other diagrams represented by graphs. Each atom is contained in a \TIKZ node. By default these nodes have an ``inner sep'' and an ``outer sep'' equal to 0pt. They are rectangular as seen on page~\pageref{longueur.liaison}. These defaults can be overwritten with the macro \verb-\setnodestyle-, the argument of which is passed to \TIKZ and specifies the style of the nodes containing the atoms. In this example we specify only ``draw,inner sep=2pt'', which has the effect of drawing the outline of the nodes and separating the outline and node contents by 2pt. We also specify \verb-\setbondoffset{0pt}- so that the bonds touch the edges of the nodes. The interatomic spacing is increased to 75pt. Finally, the command \verb-\printatom- is made as simple as possible so that math mode is no longer used and spaces are thus preserved. \exemple*{An organization chart}/\setnodestyle{draw,inner sep=2pt} \setbondoffset{0pt} \setatomsep{75pt} \renewcommand\printatom[1]{#1} \chemfig{The boss-[6]Me(-[4]Them(-[6]The others)(-[7,2]Group 1))-You(-[:-120,0.5]Him)(-[:-60,0.5]Her)}/ Here is another organization chart where the nodes are circular and coloured cyan: \exemple*{Family diagram}/\setnodestyle{draw,circle,fill=cyan,minimum size=30pt} \setbondoffset{0pt} \setatomsep{80pt} \renewcommand\printatom[1]{\textsf{#1}} \chemfig{Me(-[:-50,1.2]Brother)(-[:-10]Brother(-[:15]Niece)(-[:-35]Niece)) (-[:-155,0.8]Sister-[:-80]Nephew)(-[:95,1.25]Father(-[:-25,0.8]Uncle)(-[:-65,0.8]Aunt)) (-[:135]Mother-[:-95,0.5]Uncle)}/ \section{Annotated examples}\label{exemples.commentes} In this chapter, several molecules will be drawn, putting into use the methods previously described. The aim here is to show a logical order for putting together a molecule so that the user unfamiliar with \CF will learn how to construct complex molecules. The construction steps will be shown to help with this learning process. In addition, several possibilities --- some intuitive and others less so --- will be shown which give the same graphical results, with the objective being to show that \CF allows some flexibility in encoding molecules. One can see how each is put together and adopt the methods with which one is most comfortable. \subsection{Ethanal} Here we will draw the ethanal (or acetaldehyde) molecule: \chemfig{H-C(-[2]H)(-[6]H)-C(-[7]H)=[1]O} The best method for non-cyclic molecules is to select the longest chain. Here one could take ``\verb|H-C-C=0|'' for example. The bond \verb|C=O| is tilted to 45\degres{} by using the predefined angle ``\verb-[1]-''. This give a ``backbone'' of the molecule to which the branches merely have to be added: \exemple{Backbone of ethanal}|\chemfig{H-C-C=[1]O}| The three hydrogen atoms still have to placed at the correct orientation with the help of predefined angles. The first is at 90\degres{} with the branch ``\verb/(-[2]H)/'', the second at 270\degres{} with ``\verb/(-[6H])/'', and the one on the right at 315\degres{} with ``\verb/(-[7]H)/'': \exemple{Ethanal}|\chemfig{H-C(-[2]H)(-[6]H)-C(-[7]H)=[1]O}| \subsection{2-amino-4-oxohexanoic acid} Here is the molecule to be drawn: \chemfig{-[::+30]-[::-60](=[:-90]O)-[::+60]-[::-60](-[:-90]NH_2)-[::+60](=[:90]O)-[::-60]OH} As is often the case for most molecules, there are several methods and for each several different ways of getting the result. Here we will look at four different methods. \subsubsection{Absolute angles} We will first of all draw the central chain with absolute angles. We set the default angle to $+30\degres$ with the optional argument, and so only the descending bonds need to have their absolute angle set to $-30\degres$: \exemple{Backbone (absolute angles)}|\chemfig{[:30]--[:-30]--[:-30]--[:-30]OH}| The branches ``\verb/(=[6]O)/'', ``\verb/(-[6]NH_2)/'' and ``\verb/(=[2]O)/'' still have to be added to the correct vertices: \exemple{Molecule (absolute angles)}|\chemfig{[:30]--[:-30](=[6]O)--[:-30](-[6]NH_2)-(=[2]O)-[:-30]OH}| \subsubsection{Relative angles} A more general approach uses only relative angles, in this way: \exemple{Structure (relative angles)}|\chemfig{[:30]--[::-60]--[::-60]--[::-60]OH}| then \exemple{Molecule (relative angles)}|\chemfig{[:30]--[::-60](=[::-60]O)--[::-60](-[::-60]NH_2) -(=[::60]O)-[::-60]OH}| \subsubsection{Ring} Since the angles between the bonds are 120\degres{}, it is possible to use a 6-ring, although this method is less natural. Here we take advantage of the fact that a ring can be left unfinished. The ring must be rotated 120\degres{} so that the first vertex is to the south-east of the ring: \exemple{Backbone (ring)}|\chemfig{[:120]NH_2*6(---=O)}| Now the branches must be added to the right vertices: \exemple{Molecule (ring)}|\chemfig{[:120]NH_2*6(-(-(=[::60]O)-[::-60]OH)--(--[::60])=O)}| \subsubsection{Nested rings} Delving deeper into the ring method, we can also consider nesting incomplete 6-rings. We could start with this backbone: \exemple{Backbone (nested rings)}|\chemfig{*6(--*6(--=O))}| And then add the bonds which leave the vertices of these rings. There are no angles to worry about because the bonds leaving the rings are the bisectors of the sides of the ring, exactly what we want here: \exemple{Molecule (nested rings)}|\chemfig{*6((-)-(=O)-*6(-(-NH_2)-(-OH)=O))}| A close look shows that the second line segment of the double bond to the oxygen atom is \emph{inside} the incomplete 6-ring\footnote{This was also true for the preceding method with one ring.} Despite its brevity, this code does not give a perfect drawing. This can of course be corrected by adding a little to the code: \exemple{Molecule (corrected nested rings)}|\chemfig{*6((-)-(=O)-*6(-(-NH_2)-(-OH)(=[::60]O)))}| \subsection{Glucose} The goal here is to represent the glucose molecule according to several different conventions. \subsubsection{Skeleton diagram} The code here looks like that of 2-amino-4-oxohexanoic acid. This gives almost the same structure with absolute angles, except here the default angle is $-30\degres$: \exemple[60]{Backbone}|\chemfig{[:-30]HO--[:30]--[:30]--[:30]-H}| Adding the branches is no problem. We use predefined absolute angles: \exemple[60]{Glucose, skeleton diagram}|\chemfig{[:-30]HO--[:30](<[2]OH)-(<:[6]OH) -[:30](<:[2]OH)-(<:[6]OH)-[:30](=[2]O)-H}| \subsubsection{Fisher projection} The goal is to get the molecule below: \begin{center} \definesubmol{x}{(-[4]H)(-[0]OH)} \definesubmol{y}{(-[0]H)(-[4]OH)} \chemfig{[2]OH-[3]-!x-!x-!y-!x-=[1]O} \end{center} The idea is to begin to draw the longest chain vertically by giving a default angle of ``\verb-[2]-''. Here is the skeleton, where we have added lower case letters at the end of each vertical bond: \exemple{Skeleton}|\chemfig{[2]OH-[3]-a-b-c-d-=[1]O}| Next we define two aliases for the horizontal bonds and the atoms at their ends. Lets choose ``\verb-x-'' which we will put in place of the lower case a, c and d, and ``\verb-y-'' which will replace the letter c. Since these alias are just one character, we do not need braces and can write ``\verb-!x-'' instead of ``\verb-!{x}-'': \exemple{Glucose (Fisher projection)}|\definesubmol{x}{(-[4]H)(-[0]OH)} \definesubmol{y}{(-[0]H)(-[4]OH)} \chemfig{[2]OH-[3]-!x-!x-!y-!x-=[1]O}| \subsubsection{``Chair'' representation} We will depict the $\alpha$-D-glucose molecule: \chemfig{?(-[:190]OH)-[:-50](-[:170]OH)-[:10](-[:-55,0.7]OH)-[:-10](-[6,0.7]OH)-[:130]O-[:190]?(-[:150,0.7]-[2,0.7]OH)} To do this, we will first of all draw five sides of the chair and link the first vertex to the last with a hook ``\verb-?-''. We will use the following absolute angles, running counterclockwise: $-50\degres$, $10\degres$, $-10\degres$, $130\degres$, $190\degres$. \exemple{Structure}| \chemfig{?-[:-50]-[:10]-[:-10]-[:130]O-[:190]?}| Now we simply add the branches inside parentheses. The angles are chosen to give the best impression of perspective, and some bonds are shortened by a factor of 0.7: \exemple{Chair representation}|\chemfig{?(-[:190]OH)-[:-50](-[:170]OH)-[:10](-[:-55,0.7]OH) -[:-10](-[6,0.7]OH)-[:130]O-[:190]?(-[:150,0.7]-[2,0.7]OH)}| \subsubsection{Haworth projection} The goal is to depict this D-glucopyranose molecule: {\setcrambond{2pt}{}{} \chemfig{HO-[2,0.5,2]?<[7,0.7](-[2,0.5]OH)-[,,,,line width=2pt](-[6,0.5]OH)>[1,0.7](-[6,0.5]OH)-[3,0.7]O-[4]?(-[2,0.3]-[3,0.5]OH)}} First of all we will choose the longest chain, which starts at the ``HO'' group on the left and continues through fives sides of the ring. The ring will be closed with a hook. For the vertical bond which leaves from the first ``HO'' group, we need to specify that it will leave from the second atom using the optional argument. Furthermore, it will be shortened with a coefficient of 0.5. Its optional argument will thus be ``\verb/[2,0.5,2]/''. Next, to give the impression of perspective to the ring, the diagonal bonds will be shortened by a coefficient of 0.7. For the bold diagonal lines we will use Cram bonds, having redefined the base of the triangles to be 2pt. The bold horizontal bond needs to be drawn with a thickness of 2pt, and so its optional argument will be ``\verb/[0,,,,line width=2pt]/''. Here is the skeleton of the molecule: \exemple{Structure}|\setcrambond{2pt}{}{} \chemfig{HO-[2,0.5,2]?<[7,0.7]-[,,,, line width=2pt]>[1,0.7]-[3,0.7]O-[4]?}| All that needs to be done now is to add the branches at the correct places, giving the right absolute angles and sometimes reducing the length to better give the illusion of perspective: \exemple{Haworth projection}|\setcrambond{2pt}{}{} \chemfig{HO-[2,0.5,2]?<[7,0.7](-[2,0.5]OH)-[,,,, line width=2pt](-[6,0.5]OH)>[1,0.7](-[6,0.5]OH)-[3,0.7] O-[4]?(-[2,0.3]-[3,0.5]OH)}| \subsection{Adrenaline} We want to draw the adrenaline molecule: \chemfig{*6((-HO)-=-(-(<[::60]OH)-[::-60]-[::-60,,,2]HN-[::+60]CH_3)=-(-HO)=)} We are going to use two different methods. \subsubsection{Using one ring} First of all, we start with a 6-ring and we draw the start of the branches which leave it: \exemple[60]{Skeleton of adrenaline}|\chemfig{*6((-HO)-=-(-)=-(-HO)=)}| The branch on the right still needs to be completed using, for example, relative angles: \exemple[60]{Adrenaline, step two}|\chemfig{*6((-HO)-=-(--[::-60]-[::-60] HN-[::+60]CH_3)=-(-HO)=)}| Then we need to add a Cram-bonded \verb-OH- and indicate that the bond which arrives at ``\verb-HN-'' does so on the second atom, i.e., ``N''. We use the fourth optional argument of the bond: \exemple[60]{Adrenaline}|\chemfig{*6((-HO)-=-(-(<[::60]OH)-[::-60]-[::-60,,,2] HN-[::+60]CH_3)=-(-HO)=)}| \subsubsection{Using two rings} This method is less natural, but the goal is to show here how to make a bond invisible. We could improve this code by considering that the drawing of the adrenaline molecule is made of two 6-rings adjacent to each other: \exemple[60]{Adrenaline, two-ring skeleton}|\chemfig{*6((-HO)-=*6(--HN---)-=-(-HO)=)}| Now the first two bonds of the ring on the right need to be made invisible. To do this we use the argument that is passed to \TIKZ, specifying ``\verb-draw=none-''. These bonds will thus have this code: ``\verb/-[,,,,,draw=none]/''. To keep the code readable, we define an alias named ``\verb-&-'' for these bonds: \exemple[60]{Adrenaline, step two}|\definesubmol{&}{-[,,,,draw=none]} \chemfig{*6((-HO)-=*6(!&!&HN---)-=-(-HO)=)}| The rest becomes easy; just add the branches to the right vertices: \exemple[60]{Adrenaline, step three}|\definesubmol{&}{-[,,,,draw=none]} \chemfig{*6((-HO)-=*6(!&!&HN(-CH_3)--(,-''. These two dimensions are the height and depth of the delimiters from the baseline. The mandatory argument of \verb-\makebraces- is the subscript located at the right bottom of the closing delimiter. \exemple*{Polymers}|\newcommand\setpolymerdelim[2]{% \def\delimleft{#1}\def\delimright{#2}} \def\definedelimdim#1,#2\enddefinedelim{\def\delimht{#1}\def\delimdp{#2}} \newcommand\makebraces[2][0pt,0pt]{% \definedelimdim#1\enddefinedelim \chemmove{% \node[at=(opbr),yshift=(\delimht-\delimdp)/2] {\llap{$\left\delimleft\strut\vrule height\delimht depth\delimdp width0pt \right.$}};% \node[at=(clbr),yshift=(\delimht-\delimdp)/2] {\rlap{$\left.\strut\vrule height\delimht depth\delimdp width0pt \right\delimright_{#2}$}};% }% } \setpolymerdelim() Polyethylen: \chemfig{\vphantom{CH_2}-[@{opbr,1}]CH_2-CH_2-[@{clbr,0}]}\makebraces{n} \bigskip Polyvinyl chloride: \chemfig{\vphantom{CH_2}-[@{opbr,1}]CH_2-CH(-[6]Cl)-[@{clbr,0}]} \makebraces[0pt,15pt]{\!\!\!n} \bigskip Nylon 6: \chemfig{\phantom{N}-[@{opbr,1}]{N}(-[2]H)-C(=[2]O)-{(}CH_2{)_5}-[@{clbr,0}]} \makebraces[20pt,0pt]{} \bigskip Polycaprolactame:\setatomsep{2em} \chemfig{[:-30]-[@{opbr,1}]N(-[6]H)-[:30](=[2]O)--[:30]--[:30]--[@{clbr,0}:30]} \makebraces[5pt,5pt]{n} \setpolymerdelim[] Polyphenylen sulfide: \chemfig{\vphantom{S}-[@{opbr,1}]S-(**6(---(-[@{clbr,0}])---))} \makebraces[15pt,15pt]{}| \subsection{Draw the symmetrical of a molecule}\label{retournement} The two commands \verb-\hflipnext- and \verb-\vflipnext- allow to draw the symmetrical of the next molecule about a horizontal or vertical axis. If we want to draw more symmetrical molecules, we need to write these commands before each molecule involved. \exemple{Symmetry}/\chemfig{H_3C-C(=[:30]O)-[:-30]OH}% original \vflipnext \chemfig{H_3C-C(=[:30]O)-[:-30]OH}\medskip \chemfig{H_3C-C(=[:30]O)-[:-30]OH}% original \hflipnext \chemfig{H_3C-C(=[:30]O)-[:-30]OH}/ \section{List of commands} The commands created by \CF are: \begin{center} \begin{longtable}{>\footnotesize l>\footnotesize p{9cm}}\\\hline \hfill\normalsize Commands\hfill\null &\hfill\normalsize Description\hfill\null\\\hline \verb-\chemfig-& draws the molecule whose design is described by the \verb--\\ \verb-\printatom- & displays the atoms within the molecules. It can be redefined to customize the output. See page~\pageref{perso.affichage}\\ \verb-\setnodestyle{