\morecolors
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Polices %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\fontfam[Linux Libertine]
\fontfam[Source Pro]
\margins/1 a4 (1.5,1.5,1.5,1.5)cm
\enlang
\hyperlinks\Purple\Purple
\def\CF{{\sans\rm chem\sans\it fig}}
\def\scriptsize{\typoscale[850/]}
\def\tiny{\typoscale[750/]}
\def\ttfam{\Sourcepro\typoscale[875/800]\mono\medium\rm}
\def\texttt#1{{\ttfam#1}}
\long\def\emph#1{{\it#1\/}}
\def\eme#1{\number#1 \raise1ex \hbox{\typoscale[650/]\ifcase#1\relax\or st\or nd\else th\fi}}
\newif\ifttangle
\ttangletrue
\long\def\def_active#1{%
	\catcode`#1=13
	\begingroup
		\lccode`\~`#1
		\lowercase{\endgroup\long\def~}%
}
\everyintt{%
	\ttfam
	\no_ligs
	\ifttangle
		\def_active\<{\begingroup$\langle$\it}%
		\def_active\>{\/$\rangle$\endgroup}%
		\def_active\Y{\string<}%
		\def_active\Z{\string>}%
	\else
		\do\<%
		\do\>%
	\fi
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%% Chargement de chemfig, librairies tiks %%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mathsboff
\input{chemfig.tex}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{matrix}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%% la macro \CFcode %%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\nolig_list{\do\`\do\,\do\'\do\-}
\def\no_ligs{%
	\def\do##1{\def_active##1{\leavevmode\kern1sp \char\number`##1\relax}}%
	\nolig_list
}
\def\CFcode{\expandafter\CFcode_i\string}
\def\CFcode_i#1{%
	\begingroup
		\par\smallbreak\nobreak\parindent0pt
		\parskip=0pt
		\leftskip2.5em
		\rightskip0pt
		\nofrenchpunct
		\no_ligs
		\def_active\<{\begingroup$\langle$\it}%
		\def_active\>{\/$\rangle$\endgroup}%
		\def_active\Y{\string<}%
		\def_active\Z{\string>}%
		\def\do##1{\catcode`##1=12\relax}%
		\dospecials
		\catcode`\|12
		\ttfam
		\typoscale[875/1250]%
		\def_active\^^I{\space\space\space\space}%
		\def_active\^^M{\par\noindent}%
		\def_active\ {\space}%
		\catcode`#1=12
		\def\CFcode_ii##1#1{%
			##1\par\medbreak
	\endgroup}%
	\CFcode_ii
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%% la macro \exemple %%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\DarkGrey{\setgreycolor{.4}}
\def\exemple{%
	\begingroup
	\parindent0pt
	\parskip0pt
	\bigbreak\nobreak\noindent
	\futurelet\nxt_tok\exemple_a
}
\newif\ifexemple_vertical
\def\gobble_star*{%
	\exemple_b[60]%
}
\def\exemple_a{%
	\nofrenchpunct
	\ifx*\nxt_tok
		\exemple_verticaltrue
		\let\do_next\gobble_star
	\else
		\exemple_verticalfalse
		\ifx[\nxt_tok
			\let\do_next\exemple_b
		\else
			\def\do_next{\exemple_b[60]}%
		\fi
	\fi
	\begingroup
		\do_next
}
\def\exemple_b[#1]#2{%
		\def\do##1{\catcode`##1=12\relax}\dospecials
		\catcode`\|12
		\catcode`\_12
		\def_active\ {\space}%
		\def_active\^^M{\par\quitvmode\noexpand\Black\noexpand\rm}%
		\def_active\^^I{\space\space\space\space}%
		\def_active\%{\noexpand\it\noexpand\Grey\char37 }%
		\no_ligs
		\exemple_c{#1}{#2}%
}
\def\exemple_c#1#2#3{%
		\def\__tempa##1#3{\exemple_d{#1}{#2}{##1}}%
		\__tempa
}

\def\exemple_d#1#2#3{%
		\xdef\the_code{#3}%
	\endgroup
	\frboxsep=3mm
	\frboxrule=0.4pt
	\ifexemple_vertical
		\breakbox{#2}%
			\begingroup
				\ttfam
				\typoscale[725/850]%
				\the_code\par
			\endgroup
			\kern\frboxsep
			\hrule height\frboxrule
			\vskip\frboxsep
			\typoscale[800/950]%
			\rightskip 0pt plus 1fill
			\everypar{{\LightGrey\rlap{\vrule height0.1pt width\hsize depth0.1pt}}\hskip0pt plus 1fill\relax}%
			\catcode`\_8\relax
			\newlinechar`\^^M
			\scantextokens{#3}\par
		\endbreakbox
	\else
		\frbox{#2}{% boite insécable pleine largeur
			$%
			\vcenter{
				\hsize\dimexpr0.#1\hsize-\frboxsep-\frboxrule\relax
				\ttfam
				\typoscale[725/850]%
				\the_code\par
				}
			\vcenter{
				\hsize\dimexpr\hsize-0.#1\hsize-\frboxsep-\frboxrule\relax
				\typoscale[800/950]%
				\everypar{{\LightGrey\rlap{\vrule height0.1pt width\hsize depth0.1pt}}}%
				\catcode`\_8
				\newlinechar`\^^M
				\scantextokens{#3}\par
				}%
			$%
		}%
	\fi
	\medbreak
	\endgroup
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%% \frbox : boite pleine largeur %%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%% insécable encadrée avec titre %%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\frbox#1#2{% #1 = titre #2=contenu
	\hbox{%
		\vrule width\frboxrule% réglure gauche
		\vtop{%
			\vbox{%
				\setbox0\hbox{\titlebox{#1}}%
				\edef\title_lower{\the\dimexpr(\ht0-\dp0)/2\relax}%
				\setbox0\hbox{\lower\title_lower\box0 }% centrage sur ligne de base
				\ht0=0pt\relax \dp0=0pt\relax
				\hbox to\dimexpr\hsize-2\frboxrule{%
					\leaders\hrule height\frboxrule\hfill
					\box0\relax
					\leaders\hrule height\frboxrule\hfill
				}%%
				\kern\dimexpr\frboxsep+\title_lower\relax% espace haut
				\hbox{%
					\kern\frboxsep% espace gauche
					#2% contenu
					\kern\frboxsep% espace droite
					}%
			}%
			\kern\frboxsep% espace bas
			\hrule height\frboxrule% réglure inférieure
		}%
		\vrule width\frboxrule% réglure droite
	}%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%% Macros de mise en forme %%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\defaultitem={--- }
\_def\_printchap #1{\_vfill\_supereject \_prevdepth=0pt
	\_vglue\_medskipamount % shifted by topkip+\medskipamount
	{\_chapfont\_noindent {\vbox to 2.5ex{\vss\hbox{\typosize[40/]\Grey\bf\_printrefnum[@]}}}%
	\quad #1\_nbpar}\_mark{}%
	\_nobreak \_belowtitle{\_bigskip}%
	\_firstnoindent
}
\def\longendatei#1/#2/#3\nil{%
	\ifcase #2
		\or January%
		\or February%
		\or March%
		\or April%
		\or May%
		\or June%
		\or July%
		\or August%
		\or September%
		\or October%
		\or November%
		\or December%
	\fi
	\space\number#3, #1%
}
%
%
\def\cfpage#1{see p.~\pgref[#1]}
\def\longendate{\expandafter\longendatei\CFdate\nil}
\def\TIKZ{{\rm ti{\it k}z}}
\def\centerstuff#1{%
	\smallbreak
	\hbox to\hsize{\hss#1\hss}%
	\medbreak
}
\def\molht#1{\centerstuff{\chemfig{#1}}}
\def\framett#1{\frame{\texttt{\strut\detokenize{#1}}}}
\def\boxednode#1{\frame{$\rm#1$}}
% English version: no French punctuation spacing (the macro below is kept as a no-op-like reset)
%
%
%
%
%
\def\nofrenchpunct{%
	\catcode`\:=12
	\catcode`\;=12
	\catcode`\?=12
	\catcode`\!=12
	\catcode`\«=12
	\catcode`\»=12
}
\protected\def\CFkey#1{{\CyanD\ttfam\detokenize{#1}}}
\protected\def\CFval#1{{$\CyanD\langle\hbox{\ttfam\it#1}\rangle$}}
\protected\def\CFkv#1#2{\CFkey{#1}{\CyanD${}={}$}\CFval{#2}}
\def\CFparam#1#2{%
		\CFkey{#1}%
	&%
		\edef\tmp{\detokenize\expandafter\expandafter\expandafter{\useKV[chemfig]{#1}}}%
		\ifx\tmp\empty
			$\langle\hbox{\it empty}\rangle$%
		\else
			\texttt\tmp
		\fi
	&%
		#2%
	\cr
}
\def\Chargeparam#1{%
		\CFkey{#1}%
	&
		\edef\tmp{\detokenize\expandafter\expandafter\expandafter{\useKV[charge]{#1}}}%
		\ifx\tmp\empty
			$\langle\hbox{\it empty}\rangle$
		\else
			\texttt{\tmp}%
		\fi
}
\def\CFdelimparam#1{%
		\CFkey{#1}%
	&
		\edef\tmp{\detokenize\expandafter\expandafter\expandafter{\useKV[CFdelimiters]{#1}}}%
		\ifx\tmp\empty
			$\langle\hbox{\it empty}\rangle$
		\else
			\texttt{\tmp}%
		\fi
}
\def\titlebox#1{% titre dans les boites pleine largeur
	\inoval
		[%
		\roundness=1.5pt
		\fcolor=\DarkGrey
		\lcolor=\Black
		\lwidth=\frboxrule
		\shadow=N
		\overlapmargins=N
		\hhkern=4pt
		\vvkern=-\roundness
		]{\White\lower2.5pt\hbox{\strut\sans\rm\bf\typoscale[800/]#1}}
}
\def\longtable#1#2{% optex tricks
	\goodbreak \medbreak \bgroup\tablinespace=0pt \let\_zerotabrule=\empty
	\setbox0=\table{#1}{\strutT\relax #2}
	\setbox1=\vbox{\unvbox0 \setbox2=\vbox{}\revertbox}
	\setbox2=\vbox{\unvbox2 \global\setbox4=\lastbox\unskip \global\setbox5=\lastbox\unskip}
	\whatfree4 \advance\tmpdim by-.8pt \ifdim\tmpdim<\baselineskip \vfil\break \fi
	\offinterlineskip \crule\center4\crule\center5 \printboxes
	\center5\crule \egroup \goodbreak
}
\def\whatfree#1{\tmpdim=\dimexpr\vsize-\pagetotal-\prevdepth-.4pt-\ht#1 -\dp#1-\ht5 \relax}
\def\revertbox {%
	\setbox0=\lastbox\unskip
	\ifvoid0 \else \global\setbox2=\vbox{\unvbox2\box0} \ea\revertbox\fi
}
\def\printboxes{%
	\setbox2=\vbox{\unvbox2 \global\setbox0=\lastbox\unskip}
	\ifvoid0 \else \whatfree0
		\ifdim\tmpdim<0pt \center5\crule\vfil\break \crule\center4\crule\center5 \fi
		\center0 \nobreak \printboxes \fi
}
\def\crule{\centerline{\hbox to\wd4{\hrulefill}}\nobreak}
\def\center#1{\centerline{\copy#1}\nobreak}
\def\strutT {\the\tabstrut} % strut for the title
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%       Boites pleine largeur        %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%  sécables et encadrées avec titre  %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newdimen\frboxsep
\newdimen\frboxrule
\catcode`\@11
\newbox\bk_boxa
\newbox\bk_boxb
\newbox\bk_box
\newdimen\bk_dima
\newdimen\bk_dimb
\newif\ifbk_continue
\def\bk_before_breakbox{\ifhmode\par\fi\nobreak}
\def\bk_left{\vrule width\frboxrule\hskip\frboxsep}
\def\bk_right{\hskip\frboxsep\vrule width\frboxrule}
\def\bk_top{\hrule height\frboxrule}
\def\bk_bottom{\hrule height\frboxrule}
\def\bk_set_hsize{\advance\hsize -2\dimexpr\frboxrule+\frboxsep\relax}
\def\breakbox#1{% basé sur la package « boites »
	\def\bk_title{#1}%
	\bk_before_breakbox
	\setbox\bk_boxb\vbox\bgroup
		\bk_set_hsize
		\parindent0pt
}
\def\endbreakbox{%
	\egroup
	\begingroup
		\noindent
		\bk_continuetrue
		\splittopskip0pt
		\baselineskip0pt
		\lineskiplimit0pt
		\lineskip0pt
		\vfuzz\maxdimen
		\bk_split
		\bk_addfsepht
		\bk_addskipdp
		\ifvoid\bk_boxb
			\def\bk_fstln{%
				\bk_addfsepdp
				\vbox{\bk_singleline}%
			}%
		\else
			\def\bk_fstln{%
				\vbox{\bk_firstline}%
				\hfil
				\loop
					\bk_split
					\bk_addskipdp
					\leavevmode
					\ifvoid\bk_boxb
						\bk_continuefalse
						\bk_addfsepdp
						\vtop{\bk_lastline}%
					\else
						\bk_middleline
					\fi
					\hfil
					\ifbk_continue\repeat
			}%
		\fi
		\leavevmode\bk_fstln\par
	\endgroup
	\medbreak
}
\def\bk_split{%
	\bk_dimb\ht\bk_boxb
	\advance\bk_dimb\dp\bk_boxb
	\setbox\bk_boxa\vsplit\bk_boxb to0pt
	\setbox\bk_boxa\vbox{\unvbox\bk_boxa}%
	\setbox\bk_box\vbox{\copy\bk_boxa\copy\bk_boxb}%
	\advance\bk_dimb-\ht\bk_box
	\advance\bk_dimb-\dp\bk_box
}%
\def\bk_addfsepht{%
	\setbox\bk_boxa\vbox{\vskip\frboxsep\box\bk_boxa}%
}
\def\bk_addfsepdp{%
	\bk_dima\dp\bk_boxa
	\advance\bk_dima\frboxsep
	\dp\bk_boxa\bk_dima
}
\def\bk_addskipdp{%
	\bk_dima\dp\bk_boxa
	\advance\bk_dima\bk_dimb
	\dp\bk_boxa\bk_dima
}
\def\bk_line{%
	\hbox to \hsize{%
		\bk_left
		\box\bk_boxa
		\hfil
		\bk_right
	}%
}

\def\bk_singleline{%
	\bk_top
	\bk_line
	\bk_bottom
}
\def\bk_firstline{%
	\bk_top
	\bk_line
}
\def\bk_middleline{%
	\bk_line
}
\def\bk_lastline{%
	\bk_line
	\bk_bottom
}
\frboxrule0.4pt
\def\bk_bottom{\hrule height\frboxrule}%
\def\bk_left{\vrule width\frboxrule\hskip\frboxsep\relax}%
\def\bk_right{\hskip\frboxsep\vrule width\frboxrule\relax}%
\def\bk_top{%
	\hbox to \hsize{%
		\vrule width\frboxrule height\frboxrule\relax
		\leaders\bk_bottom\hfill
		\titlebox\bk_title
		\leaders\bk_bottom\hfill
		\vrule width\frboxrule height\frboxrule\relax
	}%
}%
\catcode`\@12
\mathsbon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%  Page de titre %%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Libertine
\typosize[10/12]
\novspaces
\parindent0pt
\footline{}
\begingroup
	\leftskip=0pt plus 1 fill
	\rightskip=\leftskip
	\leavevmode\vskip2.5cm
	{\typosize[25/30]The \TeX{} package}
	\bigbreak
	{\typosize[45/50]\CF}
	\bigbreak
	{\bf v\CFver\vskip5pt}
	\longendate\vskip2cm
	{\typoscale[1500/]\bf User's manual}\par
	\vskip1cm
	{\bf Christian \caps \bf Tellechea}\smallbreak
	{\Sourcepro\typoscale[800/800]\mono\bolder\rm\ulink[mailto:unbonpetit@netc.fr]{unbonpetit@netc.fr}}\par
\endgroup
\vfill
\centerstuff{%
	\tikzset{obrace/.style={left delimiter={[},inner sep=3pt},
		cbrace/.style={right delimiter={]},inner sep=3pt},
		braces/.style={left delimiter={[},right delimiter={]},inner sep=3pt}}
	\setchemfig{atom sep=2em}
	\schemestart
		\chemfig{H-C(=[:60]O)-[:-60]O-H}
		\arrow(--M1[obrace]){-U>[\scriptsize\chemfig{H_2SO_4}][\scriptsize\chemfig{HSO_4^\ominus}][][.25]}[,1.5]
		\chemfig{H-@{a2}C(-[:60]O-H)(-[:30,.5,,,draw=none]{\scriptstyle\oplus})-[:-60]O-H}
		\arrow(--[cbrace]){<->}
		\chemfig{H-C(=[:60]\chemabove{O}{\scriptstyle\oplus}-H)-[:-60]O-H}
		\arrow(@M1--){<=>[*{0}\scriptsize\chemfig{H-[:120]@{a1}O-[:60]CH_3}][*{0}\tiny addition]}[-90,1.33]
		\chemfig{H-C(-[2]O-[:30]H)(-\chemabove{O}{\scriptstyle\oplus}(-[:60]CH_3)-[:-60]H)-[6]O-[:-30]H}
		\arrow{<=>[\tiny protolysis]}[180]
		\chemfig{H-C(-[2]O-[:30]H)(-O-CH_3)-[@{b1}6]@{a3}\chemabove{O}{\kern-4mm\scriptstyle\oplus}(-[:-150]H)-[:-30]H}
		\arrow(--[obrace]){<=>[*{0}\scriptsize\chemfig{{-}H_2O}][*{0}\tiny elimination]}[-90,,shorten >=6pt]
		\chemfig{H-C(-[:60]O-H)(-[,.5,,,draw=none]{\scriptstyle\oplus})-[:-60]O-CH_3}
		\arrow(--[cbrace]){<->}
		\chemfig{H-C(=[:60]\chemabove{O}{\scriptstyle\oplus}-H)-[:-60]O-CH_3}
		\arrow{-U>[\scriptsize\chemfig{HSO_4^\ominus}][\scriptsize\chemfig{H_2SO_4}][][.25]}[,1.5]
		\chemfig{H-C(=[:60]O)-[:-60]O-CH_3}
		\arrow(@M1--[yshift=-5pt]){0}[180,.5]{\tiny protolysis}
		\chemmove[red,shorten <=3pt,shorten >=1pt]{
			\draw(a1)..controls +(0:1.5cm)and+(0:3cm).. (a2);
			\draw(b1)..controls +(0:5mm)and+(20:5mm)..(a3);}
	\schemestop
}%
\par\vfill
\break
\maketoc\vfill
\break
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%% Texte du manuel %%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\parskip3pt plus 1.25pt minus 1pt
\verbchar|
\tabstrut={\vrule width0pt height3ex depth1.5ex}
\footline{\hss\_rmfixed \folio}

\chap The \code{\\chemfig} command
To use the “\CF” package, one must execute:
\begitems
	* |\input chemfig.tex| or |\input{chemfig.tex}| when using (pdf)(Xe)(lua)\TeX;
	* |\usepackage{chemfig}| in the preamble when using (pdf)(Xe)(lua)\LaTeX.
\enditems

The packages \texttt{\ulink[https://www.ctan.org/pkg/tikz]{tikz}} and \texttt{\ulink[https://www.ctan.org/pkg/simplekv]{simplekv}} are required and are loaded if this has not already been done.

This package was made possible thanks to the help of Christophe~{\caps\rm Casseau}, who had the idea for it. I thank him for the help he gave me before the code was written, as well as for the tests he carried out.

I would also like to warmly thank Evys {\caps\rm Ancede Gallardo}, who spontaneously sent me this English translation. Here are a few words from him for the readers of this manual: {\it Note: this English manual is an unofficial translation of the French manual of version 1.83. The author of \CF\ no longer provides an English manual; in case of doubt, the French manual is authoritative.}

\sec New in version \CFver
The changes in version \CFver\ are listed below; for earlier changes, see the end of the manual, page~\pgref[changelogs].
\begitems\style n
	* The manual is available in English, thanks to Evys {\caps\rm Ancede Gallardo}
	* A few errors have been corrected in the manual
\enditems

\sec Syntax
The macro |\chemfig| is used with this syntax:

\CFcode/\chemfig[<keys>=<values>]{<molecule code>}/

The optional argument in square brackets specifies the parameter settings that will be used to draw the molecule. These parameters apply {\it only to the current molecule} and are restored to their previous values once the molecule is drawn. To change parameters for the rest of the document, one must execute

\CFcode|\setchemfig{<keys>=<values>}|

The |<molecule code>| contains the instructions to draw the molecule, according to a syntax that will be explained in this document. There is no a priori restriction on the characters accepted in this code:
\begitems
	* all characters of catcode 11 or 12, that is upper- or lowercase letters, digits, mathematical operators (\texttt+ \texttt- |*| \texttt/ \texttt=), punctuation signs, active or not (|.| |,| |;| |:| |!| |?| |'| |`| |"| \code{|}-), parentheses and square brackets;
	* more special characters such as “|~|”, “|#|”\fnote{To prevent \texttt{\char`\#} from being doubled when the macro \code{\\chemfig} is in the argument of a macro, one can use \texttt{\char`\\\char`\#} or the macro \code{\\CFhash} instead.} as well as “|^|” and “|_|”, which have their usual math mode properties;
	* spaces, but these are ignored by default since atoms are typeset in math mode;
	* the braces “|{|” and “|}|”, which have their normal behavior as group markers or macro argument delimiters;
	* macros.
\enditems

\sec[setchemfig] Parameters of \code{\\chemfig}
The table below gives all the \CFkv{keys}{values} allowed in the optional argument of |\chemfig| or in the mandatory argument of |\setchemfig|. Each of them will be described more precisely later in the manual:

\tabstrut={\vrule width0pt height2.8ex depth1.4ex}
\longtable{rcp{7.5cm}}{%
	keys & default values & Description \cr\tskip2.5pt
	\CFparam{chemfig style}{style passed to \TIKZ, \cfpage{chemfig.style}}
	\CFparam{use atom strut}{puts the strut of the previous atom in the argument of \code{\\printatom} in order to correct alignment defects between atoms}
	\CFparam{atom style}{style of the nodes containing the atoms, \cfpage{parametres.tikz}}
	\CFparam{bond join}{if \CFval{true}, joins adjacent bonds in a more aesthetic way, \cfpage{raccords.liaisons}}
	\CFparam{<> join angle}{if \CFkv{bond join}{true}, angle difference beyond which a chamfer is drawn to join 2 Cram bonds, \cfpage{raccords.liaisons}}
	\CFparam{-> join angle}{if \CFkv{bond join}{true}, angle difference below which a single bond is not joined to a Cram bond, \cfpage{raccords.liaisons}}
	\CFparam{fixed length}{if \CFval{true}, imposes fixed bond lengths, \cfpage{fixed.length}}
	\CFparam{cram rectangle}{if \CFval{true}, draws Cram bonds as rectangles, \cfpage{types.liaisons}}
	\CFparam{cram width}{width of the base of the Cram bond triangles, \cfpage{types.liaisons}}
	\CFparam{cram dash width}{width of the dashes of Cram bonds, \cfpage{types.liaisons}}
	\CFparam{cram dash sep}{spacing between the dashes of Cram bonds, \cfpage{types.liaisons}}
	\CFparam{atom sep}{spacing between atoms, \cfpage{atom.sep}}
	\CFparam{bond offset}{spacing between the atom and the bond, \cfpage{atom.sep}}
	\CFparam{double bond sep}{spacing between the lines of multiple bonds}
	\CFparam{angle increment}{increment of the bond angle, \cfpage{angle.increment}}
	\CFparam{node style}{style of the atoms, \cfpage{parametres.tikz}}
	\CFparam{bond style}{style of the bonds, \cfpage{bond.style}}
	\CFparam{baseline}{dimension or node name to set the vertical position of the molecule, \cfpage{baseline}}
	\CFparam{debug}{if \CFval{true}, displays the boundaries of the drawn elements and the names of the atoms}
	\CFparam{cycle radius coeff}{coefficient of the circle or arc drawn in rings}
	\CFparam{stack sep}{vertical spacing for the arguments of the macros \code{\\chemabove} and \code{\\chembelow}, \cfpage{chemabove.chembelow}}
	\CFparam{show cntcycle}{displays the ring numbers}
	\CFparam{autoreset cntcycle}{resets the ring counter to 0 at each execution of \code{\\chemfig}}
	\CFparam{gchemname}{if \CFval{true}, makes the assignment of the greatest depth global for the placement of molecule names}
	\CFparam{save}{if \CFval{true}, saves in a file the \TIKZ\ instructions generated by the macro \code{\\chemfig}, \cfpage{save}}
	\CFparam{save name}{specifies the name of the file, \cfpage{save}}
}%

The macro |\resetchemfig| restores all keys to their default values.

\chap Atoms and bonds
\sec Atoms and groups of atoms
Intrinsically, drawing a chemical molecule consists of connecting atoms with lines of different types. Thus, in the molecule \chemfig{O=O}, there are 2 groups of atoms, each made up of a single atom “O”.

\begingroup
	\vvkern1pt \hhkern1pt
	But in this molecule
		\molht{H_3C-C(-[:-30]OH)=[:30]O}
	there are 4 groups of atoms: “$\rm H_3C$”, “C”, “O” and “OH”. For reasons we will see later, \CF\ examines each group of atoms and splits it into atoms. Each atom extends until an uppercase letter or one of these special characters is encountered:
	\centerstuff{\framett{-} \framett{=} \framett{~} \framett{(} \framett{!} \framett{*} \framett{<} \framett{>} \framett{@}}

	For \CF, all characters between braces are ignored when splitting into atoms.

	Consequently, the first group of atoms “$\rm H_3C$” is split into 2 atoms: $\boxednode{H_3}{}$ and $\boxednode C{}$. Chemically, these are sometimes not real atoms since $\rm H_3$, for example, is made up of 3 hydrogen atoms. By abuse of language, we will nevertheless speak of atoms from now on. Consequently, \CF{} sees the previous molecule like this:
	\def\printatom#1{\frame{$\rm#1$}}
	\molht{H_3C-C(=[:30]O)(-[:-30]OH)}
\endgroup

\sec[premieratome]Role of the first atom
It is important to understand that the placement of the whole molecule depends on the first atom placed, that is, the first atom of the first group of atoms. For this first atom, the \TIKZ\ anchor “|base east|” is placed on the baseline of the current line (shown in gray in the examples of this manual).

\exemple{Influence of the first atom}/\chemfig{A-B}\qquad
\chemfig{-B}\qquad
\chemfig{A^1-B}/

To specify an arbitrary vertical shift or to place an atom on the baseline, use the key \CFkey{baseline} (see page~\pgref[baseline]).

\sec[types.liaisons] Bonds between groups of atoms
For \CF, there are 9 types of bonds between 2 groups of atoms, corresponding to the characters \framett-, \framett=, \framett~, \framett>, \framett<, \framett{>:}, \framett{<:}, \framett{>|} and \framett{<|}:
\centerstuff{%
	\table{clll}{\crl
	  & Code                  &Result        &Bond type\crl
	1 & \code{\\chemfig{A-B}} &\chemfig{A-B} &Single\cr
	2 & \code{\\chemfig{A=B}} &\chemfig{A=B} &Double\cr
	3 & \code{\\chemfig{A~B}} &\chemfig{A~B} &Triple\cr
	4 & \code{\\chemfig{A>B}} &\chemfig{A>B} &Right Cram, plain\cr
	5 & \code{\\chemfig{A<B}} &\chemfig{A<B} &Left Cram, plain\cr
	6 & \code{\\chemfig{A>:B}}&\chemfig{A>:B}&Right Cram, dashed\cr
	7 & \code{\\chemfig{A<:B}}&\chemfig{A<:B}&Left Cram, dashed\cr
	8 & \code{\\chemfig{A>|B}}&\chemfig{A>|B}&Right Cram, hollow\cr
	9 & \code{\\chemfig{A<|B}}&\chemfig{A<|B}&Left Cram, hollow\crl
	}%
}

The following keys set the appearance of the bonds:
\begitems
	* \CFkv{double bond sep}{dim} sets the spacing between the lines of double or triple bonds. This spacing is 2pt by default;
	* \CFkv{cram rectangle}{boolean} draws Cram bonds as rectangles when \CFval{true};
	* \CFkv{cram width}{dim} specifies the width of the base of the Cram bond triangles;
	* \CFkv{cram dash width}{dim} and \CFkv{cram dash sep}{dim} define the width of the dashes and their spacing in Cram bonds.
\enditems

When a bond is made between 2 atoms, these atoms are contained in invisible rectangular boxes. The centers of the two rectangles are separated by an adjustable distance $\Delta$, called the “interatomic distance”. Moreover, bonds do not exactly connect the boundaries of the rectangles: a distance $\delta$, also adjustable, separates the edge of the rectangles from the start and the end of the bond. To help understanding, the rectangular boxes are made visible in this diagram:
\centerstuff{%
\tikzpicture[every node/.style={anchor=base,inner sep=1.5pt,outer sep=0pt,minimum size=0pt},baseline]
	\node[draw] at(0,0)(aa){\typosize[25/30]A};
	\node[draw]at(4,0)(bb){\typosize[25/30]B};
	\path[shorten <=10pt,shorten >=10pt,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=10pt]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=-10pt]bl){};
	\draw[blue,dash pattern=on 1pt off 1pt](bl)--([yshift=0.7cm]bl);
	\draw[blue,dash pattern=on 1pt off 1pt]([xshift=-10pt]bl)--([xshift=-10pt,yshift=0.7cm]bl);
	\draw[stealth-stealth]([yshift=0.6cm]bl.center)--([xshift=-10pt,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=10pt]al)--([xshift=10pt,yshift=0.7cm]al);
	\draw[stealth-stealth]([yshift=0.6cm]al.center)--([xshift=10pt,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[stealth-stealth]([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);
\endtikzpicture
}

The key \CFkv{atom sep}{dim} sets the \label[atom.sep]\wlabel{interatomic distance}interatomic distance $\Delta$ and \CFkv{bond offset}{dim} sets the spacing $\delta$. If two bonds follow each other, \CF\ inserts an empty group |{}|, and around this empty group, the spacing $\delta$ is zero.

\exemple{Bond settings}|Length $\Delta$:
    \chemfig[atom sep=2em]{A-B} and
    \chemfig[atom sep=50pt]{A-B}\par
Length $\delta$:
    \chemfig[bond offset=0pt]{A-B} and
    \chemfig[bond offset=5pt]{A-B}\par
Empty groups: \chemfig{A-B=-=C}|

The spacing $\delta$ can be specified for a single bond with a marker which is, at will, the character |#|, the macro |\#| or |\CFhash|. If the macro |\chemfig| is in the argument of another macro, one {\em must} use the macro |\#| or |\CFhash| instead of the character |#|.

This marker must be placed {\em immediately} after the bond sign and has a mandatory argument between parentheses of the form “|(<dim1>,<dim2>)|”, where |<dim1>| is the spacing $\delta$ at the start of the bond and |<dim2>| the one at the end. If |<dim2>| is omitted, the spacing at the end of the bond takes the value of $\delta$ in force at that moment. In this example one can see how the offset, set to 4pt to be more visible, is made zero for the bond arriving at “B”, then for the one leaving “B” and finally for both at once:
\begingroup
\catcode`\#12
\exemple{Fine tuning of bond offsets}/\setchemfig{bond offset=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

 The key \CFkv{bond style}{tikz code} defines the \label[bond.style]\wlabel{style of the bonds}style of the bonds. The \CFval{tikz code} is empty by default. To customize bonds one by one, \cfpage{perso.liaisons}.
\exemple{Bond style}/\chemfig[bond style={line width=1pt,red}]{A-B=C>|D<E>:F}/

By default, all atoms in the groups of atoms are typeset in math mode, so spaces are ignored. They may therefore contain characters specific to this mode, such as subscripts or superscripts.

\sec Optional argument of a bond
After each bond, an optional argument in square brackets may be written, containing 5 comma-separated fields:
\CFcode|[<angle>,<length>,<departure atom>,<arrival atom>,<tikz code>]|

These fields must be written in this order, but may be omitted if, after a field, none of the following ones is specified.

\secc[angle.increment] Bond angle: predefined angles
When |<angle>| is an integer, the angle the bond makes with the horizontal is 45° multiplied by this integer:
\exemple{Predefined angles}|\chemfig{A-B-[1]C-[3]-[0]D-[7]E-[6]F}
\qquad
\chemfig{--[1]-[3]-[0]-[7]-[6]}|

The key \CFkv{angle increment}{angle} allows choosing an angle other than the default 45°:
\exemple{Changing the predefined angle}/By default (45): \chemfig{-[1]-[-1]-[1]-[-1]}\par
Angle of 30°: \chemfig[angle increment=30]{-[1]-[-1]-[1]-[-1]}/

\secc Bond angle: absolute angles
To specify an angle in degrees with respect to the horizontal, the optional argument must take this form: |[:<angle>]|. If necessary, \CF\ brings |<angle>| back into the interval $[0,360[$:
\exemple{Absolute angles}/\chemfig{A-[:30]B=[:-75]C-[:10]D-[:90]>|[:60]-[:-20]E-[:0]~[:-75]F}/

\secc Bond angle: relative angles
To specify the angle a bond makes with the previous one, use the syntax |[::<angle>]|.

In this example, the bond angles increase by 10° after each one, with a first bond whose absolute angle is $-5°$:
\exemple{Sequence of relative angles}|\chemfig{A-[:-5]-[::+10]-[::10]B-[::+10]-[::10]C-[::10]}|

A sequence of relative angles can be “broken” whenever desired by giving an absolute or predefined angle. Here, it is at atom “B” that the next bond has an absolute angle of $-25°$.
\exemple{Relative angles then an absolute angle}|\chemfig{
	A-[:-5]-[::10]-[::10]B-[:-25]-[::10]C-[::10]
}|

\secc Bond length: influence of the size of atoms
The interatomic distance $\Delta$ can be set with the key \CFkey{atom sep}. Once this parameter is fixed, the length of a bond depends on the contents of the atoms and, to a lesser extent, on the angle the bond makes with the horizontal. Two “narrow” atoms will have the edges of their bounding boxes further apart than in the opposite case. The effect on the bond appears in this example where the atoms “I” are narrower than the atoms “M”, so that the bond between the “I”s is longer than the one between the “M”s. The effect is even more noticeable ---~to the point of being undesirable~--- when an atom has several letters or contains a superscript.
\exemple{Influence of the width of the atom}|\chemfig{I-I}\par
\chemfig{M-M}\par
\chemfig{Mg-Mg}\par
\chemfig{A^{++}-B_2}|

\secc[fixed.length] Fixed bond lengths
The behavior of \CF\ regarding the interatomic space can be changed. Indeed, when the key \CFkey{fixed length} is set to \CFval{true}, the key \CFkey{atom sep} no longer specifies the distance between the centers of the atoms, denoted $\Delta$, but {\em the length of the bonds}. Bonds then have fixed lengths while the distance between the centers of the atoms becomes variable and depends on their size. Here are two diagrams illustrating the boolean values of \CFkey{fixed length}:
\centerstuff{%
	\tikzpicture[every node/.style={anchor=base,inner sep=1.5pt,outer sep=0pt,minimum size=0pt},baseline]
		\node[draw] at(0,0)(aa){\typosize[25/30]A};
		\node[draw]at(4,0)(bb){\typosize[25/30]B};
		\path[shorten <=10pt,shorten >=10pt,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=10pt]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=-10pt]bl){};
		\draw[blue,dash pattern=on 1pt off 1pt](bl)--([yshift=0.7cm]bl);
		\draw[blue,dash pattern=on 1pt off 1pt]([xshift=-10pt]bl)--([xshift=-10pt,yshift=0.7cm]bl);
		\draw[stealth-stealth]([yshift=0.6cm]bl.center)--([xshift=-10pt,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=10pt]al)--([xshift=10pt,yshift=0.7cm]al);
		\draw[stealth-stealth]([yshift=0.6cm]al.center)--([xshift=10pt,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[stealth-stealth]([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);
		\node at([yshift=2ex]current bounding box.north) {\CFkv{fixed length}{false}};
	\endtikzpicture
	\hskip3cm
	\tikzpicture[every node/.style={anchor=base,inner sep=1.5pt,outer sep=0pt,minimum size=0pt},baseline]
		\node[draw] at(0,0)(aa){\typosize[25/30]A};
		\node[draw]at(5,0)(bb){\typosize[25/30]B};
		\path[shorten <=10pt,shorten >=10pt,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=10pt]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=-10pt]bl){};
		\draw[blue,dash pattern=on 1pt off 1pt](bl)--([yshift=0.7cm]bl);
		\draw[blue,dash pattern=on 1pt off 1pt]([xshift=-10pt]bl)--([xshift=-10pt,yshift=0.7cm]bl);
		\draw[stealth-stealth]([yshift=0.6cm]bl.center)--([xshift=-10pt,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=10pt]al)--([xshift=10pt,yshift=0.7cm]al);
		\draw[stealth-stealth]([yshift=0.6cm]al.center)--([xshift=10pt,yshift=0.6cm]al.center) node [midway,above,draw=none]{$\delta$};
		\draw[stealth-stealth]([yshift=1cm]al)--([yshift=1cm]bl) node [midway,above,draw=none] {$\Delta$} ;
		\draw[red,dash pattern=on 2pt off2pt](al)--([yshift=1.1cm]al);
		\draw[red,dash pattern=on 2pt off2pt](bl)--([yshift=1.1cm]bl);
		\node at([yshift=2ex]current bounding box.north) {\CFkv{fixed length}{true}};
	\endtikzpicture
}

\exemple{Fixed-length bonds}/\setchemfig{atom sep=2.5em}
\chemfig{Cl-Cl}\par
\chemfig[fixed length=true]{Cl-Cl}/

So that rings (\cfpage{cycles}) are regular polygons, the default behavior is restored for ring bonds, even if \CFkv{fixed length}{true}.

\secc Bond length: setting with the optional argument
The second field of the optional argument of a bond is a decimal coefficient $k$ indicating by which value the value \CFval{atom sep} must be multiplied for this bond.
\exemple{Length coefficient}/\chemfig{A^{++}-B_2} and \chemfig{A^{++}-[,2]B_2}\par
\chemfig{A-B-[,2]C=[,0.5]D}\par
\chemfig{-=[,1.5]-[,0.75]=[:-20,2]}/

\secc Departure and arrival atoms
In a group of atoms ---~which may contain several~---, the atoms are numbered from left to right starting at 1.

Suppose we want to connect the group “ABCD” to the group “EFG” with a bond. \CF{} computes which atom of the first group and which atom of the second group must be connected depending on the angle the bond makes with the horizontal:
\begitems
	* if the angle is between $-90°$ and $90°$ (modulo $360°$), these values being {\em excluded}, 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 by default between the first atom of the first group and the last atom of the second group.
\enditems

In these cases, the angles are in the interval $]-90°,90°[$, and the bond is therefore made between D and E:
\exemple{Atoms connected by default}|\chemfig{ABCD-[:75]EFG}\quad
\chemfig{ABCD-[:-85]EFG}\quad
\chemfig{ABCD-[1]EFG}|

In these other cases, the angles belong to $[90°,270°]$ and so the bond is made between A and G:
\exemple[60]{Atoms connected by default}|\chemfig{ABCD-[:100]EFG}\quad
\chemfig{ABCD-[:-110]EFG}\quad
\chemfig{ABCD-[5]EFG}|

In some cases, one may want a bond to start from atoms other than those computed by \CF. A departure atom or an arrival atom can be forced with the optional argument of the bond. One must write:
\CFcode|[,,<n1>,<n2>]|

where |<n1>| and |<n2>| are the numbers of the desired departure and arrival atoms. These atoms must exist, otherwise an error message is issued.
\exemple{Forced connected atoms}|\chemfig{ABCD-[:75,,2,3]EFG}\qquad
\chemfig{ABCD-[:75,,,2]EFG}\qquad
\chemfig{ABCD-[:75,,3,2]EFG}|

\secc[perso.liaisons] Customizing a bond
The \eme5 field is passed directly to \TIKZ\ when the bond is drawn. One can put color attributes there such as “|red|”, dash attributes such as “|dash pattern=on 2pt off 2pt|”, thickness such as “|line width=2pt|”, or even decorations if a \TIKZ\ decoration library has been loaded. A bond can also be made invisible by writing “|draw=none|”. To specify several attributes, use the \TIKZ\ syntax, separating them with commas:
\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}|

The many \TIKZ\ decoration libraries are available. For example, one can load the library “|pathmorphing|” by writing |\usetikzlibrary{decorations.pathmorphing}| in the preamble to draw wavy bonds:
\exemple{Wavy bond}|\chemfig{A-[,3,,,decorate,decoration=snake]B}|

\sec[raccords.liaisons] Joins between bonds
By default, the lines representing single bonds are not joined, which can be too visible and unsightly when the line widths are large.

For those who find this “ugly\fnote{See \texttt{\detokenize{http://tex.stackexchange.com/questions/161796/ugly-bond-joints-in-chemfig}}}”, it is now possible to join single bonds together at the cost of a slightly longer compilation time. The boolean key \CFkv{bond join}{boolean}, when \CFval{true}, enables this feature. The default value is \CFval{false}, which is the preferable behavior.

\exemple{Join between single bonds}/\setchemfig{bond style={line width=3pt}}
\chemfig{-[1]-[7]} and
\chemfig[bond join=true]{-[1]-[7]}/

The problem is even more obvious with plain Cram bonds when they connect to a single bond or to another Cram bond. Here again, setting \CFkey{bond join} to \CFval{true} gives more aesthetic joins.

\exemple{Join with Cram bonds}/\chemfig{<[:-20]>[:50]} and
\chemfig[bond join]{<[:-20]>[:50]}
\medbreak
\chemfig{<[:-110]-[:20]>[:-30]} and
\chemfig[bond join]{<[:-110]-[:20]>[:-30]}/

When \CFkv{bond join}{true}, it is important to note that the way two consecutive Cram bonds are joined depends on the angle difference between them. If this angle is too large and becomes greater than the value of the key \CFkey{<> join angle}, which is 100 by default, a chamfer is drawn instead of a pointed join on the outer side of the join. This avoids too large a spatial extension of the join:
\exemple{Cram-Cram join}/Angle of 50°: \chemfig[bond join]{<[:10]>[:60]}
\bigbreak
Angle of 110°: \chemfig[bond join]{<[:20]>[:-90]}/

Furthermore, the join between a single bond and a Cram bond is only made when the angle difference between these two bonds is greater than or equal to a limit angle contained in the key \CFkey{-> join angle}, which is 45 by default.
\exemple{Single-Cram bond join}/Angle of 60°:
\chemfig[bond join]{A->[:60]} and \chemfig[bond join]{A<-[:60]}
\bigbreak
Angle of 40°:
\chemfig[bond join]{A->[:40]} and \chemfig[bond join]{A<-[:40]}/

When the angle between a single bond and a plain Cram bond is less than \CFkey{-> join angle}, it is nevertheless possible to join these 2 bonds. The base of the triangle of the Cram bond must be inside the space delimited by the 2 outer edges of the single bond (assumed thick enough for this to happen). Mathematically, this is the case if $d \cos\alpha>w$ where:
\begitems
	* $d$ is the base of the triangle, which is equal to \CFkey{cram width} increased by the value of |line width| for the Cram bond;
	* $w$ is |line width| for the single bond;
	* $\alpha$ is the angle difference between the 2 bonds.
\enditems

In the example below, since $(6+0.4)\cos40°<5$, the join is made when \CFkv{bond join}{true}:
\exemple{Single-Cram bond join with a small angle}/\setchemfig{cram width=6pt,line width=0.4pt}
\chemfig{-[,,,,line width=5pt]>[:40]}\qquad
\chemfig[bond join]{-[,,,,line width=5pt]>[:40]}
\bigbreak
\chemfig{<-[:40,,,,line width=5pt]}\qquad
\chemfig[bond join]{<-[:40,,,,line width=5pt]}/

\sec Default values for a molecule
At the beginning of each molecule, the default values of the optional fields of the bonds are initialized. They are:
\begitems
	* 0 for the bond angle;
	* 1 for the length multiplication coefficient;
	* |<empty>| for the departure and arrival atom numbers, which leaves \CF\ to compute them according to the bond angle;
	* |<empty>| for the parameter passed to \TIKZ.
\enditems

These default values can be changed for the whole molecule by starting the molecule code with
\CFcode/[<angle>,<coeff>,<n1>,<n2>,<tikz code>]/

Thus, if the molecule code begins with |[:20,1.5]|, then all bonds will have an angle of 20° by default and the interatomic distances will be 1.5 times the default value. These default values can be overridden at any time by specifying an optional argument, as for the bond following atom “C” in this example:
\exemple{Overriding default values}|\chemfig{[:20,1.5]A-B-C-[:-80,0.7]D-E-F}|

If one writes an unlikely |[:30,1.5,2,2,red,thick]|, unless otherwise specified, all bonds will have an angle of 30° with the horizontal, the interatomic distances will be 1.5 times the default value, the bonds will start from and arrive at the second atom of each group and will be red and thick:
\exemple{Default values}|\chemfig{[:30,1.5,2,2,red,thick]ABC-DEF=GHI}|

\sec Branches
\secc Principle
So far, all molecules were linear, which is rare. A molecule can be attached to an atom by following this atom with a |<code>| between parentheses.

In this example, the molecule “|-[1]W-X|” is attached to the atom “|B|”:
\exemple{Branch}|\chemfig{A-B(-[1]W-X)-C}|

Several molecules can be attached to the same atom: simply follow it with several parentheses containing the code of each one:
\exemple{Multiple branches}|\chemfig{A-B(-[1]W-X)(-[6]Y-Z)-C}|

The code of each attached molecule can define its own default values, which will be valid throughout its scope. Here, we attach to “B” a molecule “|[:60]-D-E|” whose default angle is 60° absolute. We also attach to “B” a submolecule “|[::-30,1.5]-X-Y|” whose default angle is 30° less than that of the previous bond (the one going from “A” to “B”) and whose interatomic distance is 1.5 times the default one:
\exemple{Default value in branches}|\chemfig{A-B([:60]-D-E)([::-30,1.5]-X-Y)-C}|

Attached molecules can be nested, and the rules seen in the previous paragraph remain valid:
\exemple{Nested branches}|\chemfig{A-B([1]-X([4]-Z)-Y)(-[7]D)-C}|

\secc Example: the acid anhydride molecule
Let us try to draw the acid anhydride molecule:
\chemfig[atom sep=2em]{O=[::-30]C(-[::-60]R)-[::60]O-[::-60]C(-[::-60]R)=[::60]O}

One method to achieve this is to choose the longest path |O=C-O-C=O|, taking the angles into account and using only relative angles:
\exemple[70]{Structure of the acid anhydride}|\setchemfig{atom sep=2.5em}
\chemfig[atom sep=2.5em]{O=[::-30]C-[::60]O-[::-60]C=[::60]O}|

Starting from this structure, it suffices to attach two “|-R|” to the carbon atoms, specifying a relative angle of $-60°$, since the previous bond already has a relative angle of $-30°$:
\exemple[70]{Acid anhydride}|\setchemfig{atom sep=2.5em}
\chemfig[atom sep=2.5em]{O=[::-30]C(-[::-60]R)-[::60]O-[::-60]C(-[::-60]R)=[::60]O}|

Since only relative angles were used, this molecule can be rotated by specifying a default angle of 15°, for example:
\exemple[70]{Rotating the molecule}|\setchemfig{atom sep=2.5em}
\chemfig[atom sep=2.5em]{[:15]O=[::-30]C(-[::-60]R)-[::60]O-[::-60]C(-[::-60]R)=[::60]O}|

\sec Connecting distant atoms
We have seen how to connect atoms {\em that follow each other in the code}. It is sometimes necessary to connect atoms that do not follow each other in the code. Let us call these particular bonds “distant bonds”.

In this molecule
\exemple{Branched structure}|\chemfig{A-B(-[1]W-X)(-[7]Y-Z)-C}|

suppose we want to connect the atoms |X| and |C|. In this case, \CF\ allows placing a “hook” {\em immediately} after the atom of interest. The character used to place this hook is “|?|”, for its resemblance to a hook. Thus, if one writes |X?|, the atom |X| will carry this hook. Later in the code, all atoms followed by a |?| will be connected to |X|:
\exemple{Distant bond}|Bond X-C: \chemfig{A-B(-[1]W-X?)(-[7]Y-Z)-C?}\bigbreak
Bonds X-C and X-Z: \chemfig{A-B(-[1]W-X?)(-[7]Y-Z?)-C?}|

Now, imagine we have to keep these distant bonds |X-C| and |X-Z|, while adding another one: |A-W|. We must therefore place two {\em different} hooks, one on |A| and the other on |X|. In fact, the character “|?|” has an optional argument:
\CFcode/?[<name>,<bond>,<tikz>]/

where each field takes its default value if it is empty:
\begitems
	* the |<name>| is the name of the hook: all alphanumeric characters (|a..z|, |A..Z|, |0..9|) are allowed\fnote{This is not entirely accurate. In reality, all tokens that can be put between \code{\\csname...\\endcsname} are allowed.}. This name is “|a|” by default. Only this field is taken into account at the first occurrence of the hook bearing this |<name>|.
	* |<bond>| specifies the bond type.

	Two cases are possible; either this field is an integer representing the desired bond type: 1=single bond, 2=double bond, etc. See the table on page~\pgref[types.liaisons] for the bond type numbers.

	Or the |<bond>| consists of the characters coding the bond, provided these characters are {\em between braces};
	* |<tikz>| will be passed directly to \TIKZ\ as we saw with ordinary bonds.
\enditems

Here is our molecule with the required distant bonds, then with the bonds |A-W| and |X-C| customized:
\exemple[70]{Several distant bonds}|\chemfig{A?[a]-B(-[1]W?[a]-X?[b])(-[7]Y-Z?[b])-C?[b]}
\bigbreak
\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 incomplete pentagon we want to connect |A-E|, |A-C| and |E-C|:
\exemple[70]{An incomplete ring}|\chemfig{A-[:-72]B-C-[:72]D-[:144]E}|

Then one must proceed this way:
\exemple[70]{Several distant bonds}|\chemfig{A?[a]-[:-72]B-C?[a]?[b]-[:72]D-[:144]E?[a]?[b]}|

\chap[cycles] Rings
The previous example shows how to draw a regular polygon, but the method is tedious since the angles depend on the number of sides of the polygon.

\sec Syntax
\CF\ can draw regular polygons easily. The idea is to attach a ring to an |<atom>| outside this ring with this syntax:
\CFcode/<atom>*<n>(<code>)/

|<n>| is the number of sides of the polygon and the |<code>| represents the bonds and groups of atoms that make up its vertices and edges. This code {\em must} begin with a bond since the |atom| is outside the ring.

Here is a 5-ring, attached to the atom “|A|”:
\exemple{5-ring}|\chemfig{A*5(-B=C-D-E=)}|

A ring can also be drawn with one, several or all groups of atoms empty, as is the case for drawings outside rings:
\exemple{5-ring with empty groups}|\chemfig{*5(-=--=)}|

A ring may be incomplete:
\exemple{Incomplete 5-ring}|\chemfig{*5(-B=C-D)}|

If the code of a ring contains too many bonds and groups of atoms for the specified number of vertices, all bonds and groups beyond the allowed maximum are ignored:
\exemple{Truncated 5-ring}|\chemfig{A*5(-B=C-D-E=F-G=H-I)}|

A circle or an arc of a circle can be drawn inside a ring. For this, use this syntax:
\CFcode/<atom>**[<angle 1>,<angle 2>,<tikz>]<n>(<code>)/

where each field of the optional argument takes its default value if it is empty:
\begitems
	* |<angle 1>| and |<angle 2>| are the absolute start and end angles of the arc. By default, they are 0° and 360° so that a full circle is drawn by default;
	* |<tikz>| is the code that will be passed to \TIKZ\ to draw the arc.
\enditems

\exemple[60]{Rings and arcs}|\chemfig{**6(------)}\quad
\chemfig{**[30,330]5(-----)}\quad
\chemfig{**[0,270,dash pattern=on 2pt off 2pt]4(----)}|

\sec Angular position
When a ring is at the beginning of a molecule, and as seen in the examples below, the rule is that the attachment atom “|A|” is always at the south-west of the ring. Moreover, the ring is always drawn counterclockwise and the last bond falls 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 suitable, another default angle can be specified with the optional argument at the beginning of the molecule. Here is a 6-ring rotated by $+30°$, by $-30°$ and then by $+60°$:
\exemple[55]{Rotating rings}|\chemfig{[:30]A*6(------)}\qquad
\chemfig{[:-30]A*6(------)}\qquad
\chemfig{[:60]A*6(------)}|

When a ring does not begin a molecule, the default angular position changes: the ring is drawn so that the bond arriving at the attachment atom is the bisector of the first and last sides of the ring:
\exemple{Bond arriving at a ring}|\chemfig{A-B*5(-C-D-E-F-)}\vskip5pt
\chemfig{A-[:25]B*4(----)}\vskip5pt
\chemfig{A=[:-30]*6(=-=-=-)}|

\sec Branches leaving a ring
To start a branch from one of the vertices of the ring, use the syntax already seen:
\CFcode/<atom>(<code>)/

where the |<code>| is that of the submolecule and the |<atom>| occupies the vertex. A particularity of rings is that the default angle of the submolecule is not 0° but is computed so that it is the bisector of the sides leaving the vertex:
\exemple{Branch leaving a ring}|\chemfig{X*6(-=-(-A-B=C)=-=-)}|

A submolecule can start from the first vertex of the ring, as well as from all the other vertices:
\exemple{Ring and branches}|\chemfig{*5((-A=B-C)-(-D-E)-(=)-(-F)-(-G=)-)}|

If the bond leaving a vertex should not be the bisector of its sides, one can use the global optional parameter or the optional parameter of the bond:
\exemple[50]{Branches and specified angles}|\chemfig{*5(---([:90]-A-B)--)}\qquad
\chemfig{*5(---(-[:90]A-B)--)}\qquad
\chemfig{*5(---([::+0]-A-B)--)}|

It is interesting to note in the third example that if a relative angle of 0° is specified, the bond is drawn in the continuation of the previous bond of the ring.

Rings can now be connected to each other by bonds:
\exemple{Connected rings}|\chemfig{*6(--(-*5(----(-*4(----))-))----)}|

\sec Fused rings
To “glue” 2 rings together, the syntax is slightly different: one identifies the vertex from which the other ring will start. It suffices to follow this vertex with the usual ring syntax. Here, for example, is a 5-ring starting from the second vertex of a 6-ring:
\exemple{Nested rings}|\chemfig{A*6(-B*5(----)=-=-=)}|

Note that the ring grafted onto the main ring has an angular position such that two of their sides coincide. Moreover, the 5-ring has only 4 bonds. Indeed, the \eme5 would be useless since it is the second side of the 6-ring, which is already drawn.

It is of course possible to glue several rings together:
\exemple{Several nested rings}|\chemfig{*5(--*6(-*4(-*5(----)--)----)---)}|

Some cases deserve more attention. In this example one can see that the fourth side of the second 5-ring closes on the center of the atom “|E|”.
\exemple{Imperfect drawing}|\chemfig{A-B*5(-C-D*5(-X-Y-Z-)-E-F-)}|

This is normal since the second 5-ring (which starts from the atom “|D|”) is drawn {\em before} \CF\ knows about the atom “|E|”. In this case, two hooks must be used to draw the bond |Z-E|:
\exemple{Distant bond and ring}|\chemfig{A-B*5(-C-D*5(-X-Y-Z?)-E?-F-)}|

One could also have used a |\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-)}/

\sec Groups of atoms in a ring
Care must be taken with rings when one or more vertices consist of several atoms:
\exemple{Ring and groups of atoms}|\chemfig{AB*5(-CDE-F-GH-I-)}|

For the ring to have a regular shape, the \CF\ mechanism that automatically computes the departure and arrival atoms of the bonds must be overridden. Here, |C-F| and |F-G| must be connected by specifying it with the optional argument of these bonds:
\exemple{Imposed departure and arrival atoms}|\chemfig{AB*5(-CDE-[,,1]F-[,,,1]GH-I-)}|

\chap Representing electron movements
Electron movements of mesomeric effects or reaction mechanisms can be represented. This is made possible by marking the starting point and the end point of the arrow used to indicate the migration of electrons, with the syntax “|@{<argument>}|”.

This syntax places a node (in the \TIKZ\ sense) and makes this node accessible outside the argument of the |\chemfig| command thanks to the option “\texttt{remember picture}” which is passed to all “\texttt{tikzpicture}” environments. This assumes that the viewer supports “picture remembering” and that the compilation is run twice.

There are two possible places to define a node:
\begitems
	* a zero-size node on a bond, using the syntax “|@{<name>,<coeff>}|” placed immediately at the beginning of the optional argument of the bond concerned, without being followed by a comma if there is a first optional argument. In this case, the node is named “|<name>|” and the |<coeff>|, between 0 and 1, determines where the node is located on the bond. If the |<coeff>| is omitted, it takes the value 0.5 by default, which means that the node is placed in the middle of the bond;
	* a node on an atom, using the syntax “|@{<name>}|” immediately before the atom concerned. In this case, the node has exactly the same size as the atom; in particular it can be empty and therefore have zero dimensions.
\enditems

Once the |\chemfig| command has drawn the molecule(s) and placed the nodes with the syntax described above, these nodes can be connected with \TIKZ\ instructions. These instructions are placed in the argument of the \label[chemmove]\wlabel{command}command |\chemmove|\fnote{In fact, the command \code{\\chemmove} puts its argument in a “\texttt{tikzpicture}” environment with the options “\texttt{remember picture,overlay}”.} and have the following syntax if, for example, a node named “|<name1>|” must be connected to the node named “|<name2>|”:
\CFcode|\chemmove[<opt>]{\draw[<tikz opt>](<name1>)<tikz link>(<name2>);}|

The optional argument |<opt>| of the |\chemmove| command is added to the argument of the \texttt{tikzpicture} environment in which the links between the nodes are drawn. The instructions |<tikz opt>| and |<tikz link>| are exhaustively described in the documentation of the \TIKZ\ package.

\sec Mesomeric effect
To fix ideas, let us take the example of a mesomeric effect involving a conjugated double bond and lone pair. Let us start with the possible delocalization of the electrons of 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.

The macro |\charge| will be described later in the manual, \cfpage{charge}.

\exemple{Mesomeric effect 1}/\chemfig{@{a1}=_[@{db}::30]-[::-60]\charge{90=\|}{X}}
\chemmove{\draw(db).. controls +(100:5mm) and +(145:5mm).. (a1);}/

To connect the nodes “db” and “a1”, we used the following syntax:
\CFcode|\chemmove{\draw(db)..controls +(100:5mm) and +(145:5mm)..(a1);}|

The default arrow tip style in |\chemmove| is “|CF|”. In this example, we use 2 control points\fnote{To learn all the ways of connecting two nodes with \TIKZ, read the documentation of this package.}. They are located in polar coordinates at 100° and 5~mm from “db” for the first and at 145° and 5~mm from “a1” for the second. This syntax may seem complicated at first reading, but its use reduces in most cases to a simple copy-paste in which only the names of the nodes and the polar coordinates of the control points are modified. This is what we will check right away by adding an arrow from the lone pair (node “|dnl|”) to the single bond (node “|sb|”).
\exemple{Mesomeric effect 2}/\chemfig{@{a1}=_[@{db}::30]-[@{sb}::-60]@{dnl}\charge{90=\|}{X}}
\chemmove{
    \draw(db)..controls +(100:5mm) and +(145:5mm)..(a1);
    \draw(dnl)..controls +(90:4mm) and +(45:4mm)..(sb);}/

For our new arrow we set the control points as follows: an angle of 90° at 4~mm from “dnl” and an angle of 45° at 4~mm from “sb”. But we are not entirely satisfied because we would like the arrow not to touch the line representing the lone pair. For this we will add some options to our arrow.
\exemple{Mesomeric effect 3}/\chemfig{@{a1}=_[@{db}::30]-[@{sb}::-60]@{dnl}\charge{90=\|}{X}}
\chemmove[->]{% change the arrow style
    \draw(db).. controls +(100:5mm) and +(145:5mm).. (a1);
    \draw[shorten <=3pt,shorten >=1pt](dnl) .. controls +(90:4mm)
          and +(45:4mm) .. (sb);}/

The option “\texttt{shorten <=3pt}” indicates that the starting point of the arrow must be shortened by 3~pt and likewise “\texttt{shorten >=2pt}” indicates that the end point must be shortened by 2~pt.

The full power of \TIKZ\ instructions can be used to modify the drawing of the arrow. Here, we change the tip of the arrow leaving the double bond to “|-stealth|”, and draw it dashed, thin and red. We also add the letter $\pi$ above the arrow at its middle:
\exemple{Mesomeric effect 4}/\chemfig{@{a1}=_[@{db}::30]-[@{sb}::-60]@{dnl}\charge{90=\|}{X}}
\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 will see how to indicate the position of the starting or ending anchor. If we write
\exemple{Starting and ending anchors 1}/\chemfig{@{x1}\charge{45=\:}{X}}
\hskip2cm\relax
\chemfig{@{x2}\charge{90=\|}{X}}
\chemmove{
    \draw[shorten >=4pt](x1).. controls +(90:1cm) and +(90:1cm).. (x2);}/

We see that the starting anchor of our arrow does not point correctly at our electrons. The arrow starts from the middle of the upper edge of the node. Indeed, we chose a starting angle of 90° and so \TIKZ\ starts the arrow from the anchor “x1.90”, which corresponds to the intersection of the half-line starting from the center of the node “x1” and making an angle of 90° with the horizontal, with the edge of the node, which is a rectangle. To have the arrow start where we want, we must specify its position. After some trial and error, it is “x1.57”:
\exemple{Starting and ending anchors 2}/\chemfig{@{x1}\charge{45=\:}{X}}
\hskip2cm\relax
\chemfig{@{x2}\charge{90=\|}{X}}
\chemmove[shorten <=4pt,shorten >=4pt]{
    \draw(x1.57).. controls +(60:1cm) and +(120:1cm).. (x2.90);}/

In some cases it will be easier to use Cartesian coordinates for the control points. Here, we use only one control point located 1~cm horizontally and 1.5~cm vertically from “|x1|”:
\exemple{A single control point}/\chemfig{@{x1}\charge{45=\:}{X}}
\hskip2cm\relax
\chemfig{@{x2}\charge{90=\|}{X}}
\chemmove[shorten <=4pt,shorten >=4pt]{
    \draw(x1.57).. controls +(1cm,.8cm).. (x2.90);}/

In this case we place a control point 1~cm horizontally and 2~cm vertically from “x1”. All graphic objects drawn through the |\chemmove| command are overprinted and are not counted in the bounding boxes.

\sec Center of a ring
The center of a ring becomes addressable via |\chemmove| because each ring carries at its center a zero-size node whose name is |cyclecenter<n>| where |<n>| is the number of the ring, it being understood that rings are numbered from 1 in the order in which they are drawn. The number of each ring can be displayed by setting the boolean key \CFkey{show cntcycle} to \CFval{true}.

The boolean key \CFkey{autoreset cntcycle}, \CFval{true} by default, resets the ring counter to 0 at the beginning of each molecule drawn (that is, at each call of |\chemfig|).

\exemple{Ring center}/\chemfig{*5(---(-*3(---))--)}
\chemmove{\draw[red](cyclecenter1)to[out=20,in=-45](cyclecenter2);}
\qquad
\chemfig{*6(-=-=-=)}
\chemmove{%
	\node[at=(cyclecenter1)](){+}
		node [at=(cyclecenter1),shift=(120:1.75cm)](end){$R^1$};
	\draw[-,shorten <=.5cm](cyclecenter1)--(end);
}/

\sec[mecanismes-reactionnels] Reaction mechanisms
Thanks to the option |remember picture| which is passed to all “|tikzpicture|” environments, we can easily draw the arrows indicating reaction mechanisms. Let us take as an example the first step of the esterification reaction.

The macros |\schemestart|, |\schemestop|, |\arrow| and |\+| will be described later in the manual.

\exemple*{Esterification: step 1}/\setchemfig{atom sep=7mm}
\schemestart
	\chemfig{R-@{dnl}\charge{90=\|,-90=\|}{O}-H}
	\+
	\chemfig{R-@{atoc}C([6]-OH)=[@{db}]O}
	\arrow(.mid east--){<->[\chemfig{@{atoh}\chemabove{H}{\scriptstyle\oplus}}]}
\schemestop
\chemmove[shorten <=2pt]{
	\draw(dnl)..controls +(90:1cm)and+(north:1cm)..(atoc);
	\draw[shorten >=6pt](db)..controls +(north:5mm)and+(100:1cm)..(atoh);}/

Using the command |\chemabove{<code>}{<material>}| does not change the dimensions of the bounding box of the |<code>|. For this reason one may have some difficulty pointing at the material indicating the charge ($\oplus$ or $\ominus$). In the example above the solution is to create a control point with an angle of 110° at 1~cm from “atoh” and to shorten the arrow by 6pt. In the following example, the second step of the esterification reaction, one can see that the arrow can take more complicated shapes without necessarily overloading the code.
\exemple{Esterification: step 2}/\setchemfig{atom sep=7mm}
\chemfig{R-O-C(-[2]R)(-[6]OH)-@{dnl}\charge{90=\|,-90=\|}{O}H}\hskip1cm
\chemfig{@{atoh}\chemabove{H}{\scriptstyle\oplus}}
\chemmove{
    \draw[shorten <=2pt, shorten >=7pt]
        (dnl).. controls +(south:1cm) and +(north:1.5cm).. (atoh);}/

We leave it to the reader to write the rest.

\sec[chemname] Writing a name under a molecule
For convenience, \CF\ allows writing the name of a molecule under it with the command
\CFcode/\chemname[<dimension>]{\chemfig{<molecule code>}}{<name>}/

The |<dimension>|, which is |1.5ex| by default, is inserted vertically between the baseline of the molecule and the top of the letters of the |<name>|. The |<name>| is centered with respect to the molecule, but this |<name>| cannot contain several paragraphs. As seen in this example:
\chemname{\chemfig{H-O-H}}{\typosize[8/]\bf The water molecule: $\bf H_2O$},
the |<name>| displayed under the molecule is taken into account in the bounding box, but only as far as its {\em vertical} dimension is concerned. The horizontal size of the |<name>| is always zero.

Here is a reaction with the names under the molecules:
\exemple*{Displaying the names of molecules}/\schemestart
	\chemname{\chemfig{R-C(-[:-30]OH)=[:30]O}}{Carboxylic acid}
	\+
	\chemname{\chemfig{R'OH}}{Alcohol}
	\arrow(.mid east--.mid west)
	\chemname{\chemfig{R-C(-[:-30]OR')=[:30]O}}{Ester}
	\+
	\chemname{\chemfig{H_2O}}{Water}
\schemestop
\chemnameinit{}/

There are some constraints with this command. To become aware of them, suppose we have swapped the acid and the alcohol in the left-hand side:
\exemple*{Alignment of names 1}/\schemestart
	\chemname{\chemfig{R'OH}}{Alcohol}
	\+
	\chemname{\chemfig{R-C(-[:-30]OH)=[:30]O}}{Carboxylic acid}
	\arrow(.mid east--.mid west)
	\chemname{\chemfig{R-C(-[:-30]OR')=[:30]O}}{Ester}
	\+
	\chemname{\chemfig{H_2O}}{Water}
\schemestop
\chemnameinit{}/

In fact, below the baseline of each molecule (in light gray in the examples of this manual), to write the |<name>|, the command |\chemname| inserts 1.5ex${}+{}${\em the greatest of the depths\fnote{In \TeX{} language, the depth is the dimension extending vertically below the baseline.} of the molecules encountered}.

The \label[chemnameinit]\wlabel{macro}macro |\chemnameinit{<argument>}| initializes this greatest depth with the contents of its |<argument>|. One should therefore:
\begitems
	* write |\chemnameinit{<deepest molecule>}| before involving this command in a reaction, unless this reaction begins with the deepest molecule;
	* write |\chemnameinit{}| after having written all the names of a chemical reaction, to prevent the greatest depth found in this reaction from interfering with a future reaction.
\enditems

Note that the assignments concerning the greatest depth are global if \CFkv{gchemname}{true}, which is the default behavior. Otherwise they are local.

The correct code is therefore to use |\chemnameinit| before and after the reaction:
\exemple*{Alignment of names 2}/\chemnameinit{\chemfig{R-C(-[:-30]OH)=[:30]O}}
\schemestart
	\chemname{\chemfig{R'OH}}{Alcohol}
	\+
	\chemname{\chemfig{R-C(-[:-30]OH)=[:30]O}}{Carboxylic acid}
	\arrow(.mid east--.mid west)
	\chemname{\chemfig{R-C(-[:-30]OR')=[:30]O}}{Ester}
	\+
	\chemname{\chemfig{H_2O}}{Water}
\schemestop
\chemnameinit{}/

Finally, to write a name on several lines, the command |\\| encountered in a |<name>| performs a line break\fnote{On the other hand, the command \code{\par} is forbidden and will cause an error at compilation.}:
\exemple*{Name on 2 lines}/\schemestart
	\chemname{\chemfig{R-C(-[:-30]OH)=[:30]O}}{Carboxylic\\acid}
	\+
	\chemname{\chemfig{R'OH}}{Alcohol}
	\arrow(.mid east--.mid west)
	\chemname{\chemfig{R-C(-[:-30]OR')=[:30]O}}{Ester}
	\+
	\chemname{\chemfig{H_2O}}{Water}
\schemestop
\chemnameinit{}/

If one writes |\chemname*{<name>}|, then the macro does not take into account the names encountered previously.

\chap Advanced usage
\sec Splitting atoms
The automatic mechanism for splitting into atoms, already described, makes each atom extend up to the next uppercase letter or one of the characters \framett{-} \framett{=} \framett{~} \framett{(} \framett{!} \framett{*} \framett{<} \framett{>} \framett{@}.

In some cases, this automatic splitting produces incorrect atoms, which can result in an imperfect display. For this molecule, note that the character “\texttt(” is put between braces so that \CF\ does not wrongly understand that a branch is being created:
\exemple*{Alkene}/\chemfig{CH_3CH_2-[:-60,,3]C(-[:-120]H_3C)=C(-[:-60]H)-[:60]C{(}CH_3{)}_3}/

The bond arriving at the carbon atom at the top right is too short. This happens because, if the \CF\ splitting rules are applied to the group of atoms at the top right, the atoms are split this way: “\texttt{\detokenize{C{(}}}”, “\texttt{\detokenize{C}}”, “\texttt{\detokenize{H_3{)}_3}}”. One then understands that in math mode, the first atom, which contains a parenthesis, has too large a depth, as can be seen by making visible the boxes containing the atoms:
\centerstuff{%
\hhkern=1pt \vvkern=1pt
\def\printatom#1{\frame{$\rm#1$}}%
\chemfig{CH_3CH_2-[:-60,,3]C(-[:-120]H_3C)=C(-[:-60]H)-[:60]C{(}CH_3{)}_3}%
}
The character “\texttt{\detokenize{|}}” causes the current atom to be cut where it is encountered. Thus, one can write \texttt{C{\Red\detokenize{|}}\detokenize{{(CH_3)_3}}} so that \CF\ splits only 2 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}}/

\sec[printatom] Formatting atoms
Once the splitting into atoms is done, the macro |\printatom| is called internally by \CF\ to display each atom. Its only argument consists of the tokens read in the molecule code representing the current atom (for example “|H_3|”). This macro switches to math mode and displays its argument with the math font “|rm|”. It is defined by the following code:
\begitems
	* |\def\printatom#1{\ifmmode\rm#1\else$\rm#1$\fi}| when compiling with (pdf)(xe)(lua)\TeX{};
	* |\newcommand*\printatom[1]{\ensuremath{\mathrm{#1}}}| when compiling with (pdf)(xe)(lua)\LaTeX{}.
\enditems

The code of this macro can be modified to customize the display of atoms. In the example below, |\printatom| is redefined so that each atom is contained in a rectangular box, using the Op\TeX\ macro |\frame|:
\exemple{Redefining \string\printatom}/\vvkern=1pt \hhkern=1pt % h and v spaces between rules and content
\def\printatom#1{\frame{\ifmmode\rm#1\else$\rm#1$\fi}}
\chemfig{H_3C-C(=[:30]O)(-[:-30]OH)}/

Here is how to redefine it to use the bold sans serif font of math mode:
\exemple{Atoms displayed in bold sans serif}/\def\printatom#1{\ifmmode\bf#1\else$\bf#1$\fi}
\chemfig{H_3C-C(=[:30]O)(-[:-30]OH)}/

\sec[parametres.tikz] Parameters passed to \TIKZ
The key \CFkey{chemfig style} contains \TIKZ\ instructions that are passed to the \texttt{tikzpicture} environment in which the molecule is drawn. Furthermore, the key \CFkey{atom style} contains \TIKZ\ instructions that are executed when drawing each node; these instructions are added at the end of |every node/.style{<argument>}|, that is, after the following instructions: “|anchor=base,inner sep=0pt,outer sep=0pt,minimum size=0pt|”.

Through \label[chemfig.style]\wlabel{\CFkey{chemfig style}}\CFkey{chemfig style}, one can choose, for example, the general color or the line width:
\exemple{Choosing the style}/\chemfig{A-B-[2]C}\par\medskip
\chemfig[chemfig style={line width=1.5pt}]{A-B-[2]C}\par\medskip
\chemfig[chemfig style=red]{A-B-[2]C}/

With the key \CFkey{node style}, one can choose the color of the nodes drawn by \TIKZ, change the slant of the drawing or change the scale:
\exemple{Choosing styles}/\chemfig{A-B-[2]C}\par\medskip
\setchemfig{atom style=red}\chemfig{A-B-[2]C}\par\medskip
\setchemfig{atom style={rotate=20}}\chemfig{A-B-[2]C}\par\medskip
\setchemfig{atom style={scale=0.5}}\chemfig{A-B-[2]C}/

\sec Vertical alignment
\secc[baseline] The key \CFkey{baseline}
The key \CFkey{baseline} gives fine control of the vertical placement of the molecule with respect to the baseline of the current paragraph.

Its default value is \CFval{0pt}, and in this case the first atom encountered (whether empty or not) is the one placed on the baseline of the current paragraph, shown in gray in the examples of this manual. The choice of this first atom therefore determines the placement of all the others relative to it, and often affects the placement of the whole molecule.

\exemple{First atom}/\chemfig{H-[7]C(-[5]H)=C(-[1]H)-[7]H}\qquad
\chemfig{C(-[3]H)(-[5]H)=C(-[1]H)-[7]H}/

An arbitrary dimension can be specified to shift the molecule vertically by this value, with the syntax \CFkv{baseline}{dimension}:

\exemple{Vertical shift}/\chemfig{A(-[:-60]-[:30]C)-[:45]B}\qquad
\chemfig[baseline=5pt]{A(-[:-60]-[:30]C)-[:45]B}\qquad
\chemfig[baseline=-5pt]{A(-[:-60]-[:30]C)-[:45]B}/

With the syntax \CFkv{baseline}{(<name>)} (the name must be between parentheses), one specifies that the baseline of the molecule is on the node named |c<name>|. The name of the atom can be the one automatically assigned by \CF\ (of the form |n<a>-<b>|) or a name given by the user with the syntax |@{<name>}| (see page~\pgref[mecanismes-reactionnels]).

\exemple*{Alignment on atoms}/Default alignment:         \chemfig{A(-[:-60]-[:30]C)-[:45]B}\qquad
Alignment on B:            \chemfig[baseline=(b.base)]{A(-[:-60]-[:30]C)-[:45]@{b}B}\medbreak
Alignment on empty atom:   \chemfig[baseline=(empty)]{A(-[:-60]@{empty}-[:30]C)-[:45]B}\qquad
Alignment on C:            \chemfig[baseline=(c.base)]{A(-[:-60]-[:30]@{c}C)-[:45]B}/

\TIKZ\ node names can also be used. Thus, to center several molecules vertically on the current baseline, put the value \CFval{(current bounding box.center)} in the key \CFkey{baseline}.

\exemple*{Centered alignment}/1) \chemfig{A-[:-45]B} and 2) \chemfig{B-[:45]C}\bigbreak

\setchemfig{baseline=(current bounding box.center)}% vertical centering of all molecules
1) \chemfig{A-[:-45]B} and 2) \chemfig{B-[:45]C}
\setchemfig{baseline=0pt}% back to the default value/

\secc Importance of the height or depth of an atom
A bond leaving an atom would, if extended, pass through the center of its bounding box. The arrival atom is placed at the end of the bond so that the center of its bounding box is in the continuation of the bond. Consequently, a bond between two atoms passes, when extended, through the centers of their bounding boxes, as illustrated by this example:
\centerstuff{%
	\vvkern=1pt \hhkern=1pt % h and v spaces between rules and content
	\def\printatom#1{\frame{\ifmmode\rm#1\else$\rm#1$\fi}}
	\setchemfig{chemfig style={line width=1pt}}
	\typosize[16/]
	\chemfig{A@ABC-[:65,,2,3]DE@BFG}
	\chemmove{%
		\draw[red,fill=red]  (A.center)circle(.2ex);
		\draw[blue,fill=blue](B.center)circle(.2ex);
		\draw[gray,-,dashed,shorten <=-1.5em, shorten >=-1.5em](A.center)--(B.center);
	}
}%

This mechanism can create a height shift, particularly visible when bonds are horizontal. Everything goes well when atoms have the same vertical dimensions; on the other hand, it is enough that a departure atom be tall (with a superscript) or deep (with a subscript) and that the arrival atom have a different vertical dimension for a height shift to occur. In this example one can see that the bonds and atoms following |A^1| are slightly shifted upward and those following |E_1| downward.
\exemple[55]{Horizontal placement}!\typosize[13/]
\setchemfig{atom sep=2em}
\chemfig{A^1-B-C-D}\qquad \chemfig{E_1-F-G-H}!

This phenomenon can be highlighted by making the bounding boxes of the atoms visible:
\exemple[55]{Horizontal placement and bounding boxes}!\typosize[13/]
\setchemfig{atom sep=2em}
\vvkern=0pt \hhkern=0pt \rulewidth=0.1pt
\def\printatom#1{\frame{\ifmmode\rm#1\else$\rm#1$\fi}}
\chemfig{A^1-B-C-D}\qquad
\chemfig{E_1-F-G-H}!

The behavior prior to version 1.7 of \CF\ masked this effect on the first atom following the problematic bounding box by adding to the argument of each |\printatom| the |\vphantom| of the previous atom (without taking the added strut into account). This behavior can be restored by setting the key \CFkey{use atom strut} to \CFval{true}, but this correction is only effective on a single atom.

\exemple[55]{Horizontal placement and bounding boxes}!\typosize[13/]
\setchemfig{atom sep=2em}
\vvkern=0pt \hhkern=0pt \rulewidth=0.1pt
\def\printatom#1{\frame{\ifmmode\rm#1\else$\rm#1$\fi}}
\chemfig{A^1-B-C-D}\quad
\chemfig[use atom strut=true]{A^1-B-C-D}
\medbreak
\chemfig{E_1-F-G-H}\quad
\chemfig[use atom strut=true]{E_1-F-G-H}!

Since no automatic solution is satisfactory, this problem can be worked around “with an axe” by redefining |\printatom| to add to each typeset atom the strut defined by |\strut|:
\exemple[55]{Working around vertical placement}!\typosize[13/]
\setchemfig{atom sep=2em}
\vvkern=0pt \hhkern=0pt \rulewidth=0.1pt
\def\printatom#1{\frame{\strut\ifmmode\rm#1\else$\rm#1$\fi}}
\chemfig{A^1|\vphantom{X}-B-C-D}\par
\chemfig{E_1|\vphantom{X}-F-G-H}!

\secc[chemskipalign] The macro \code{\\chemskipalign}
For any group of atoms, the alignment adjustment mechanism can be temporarily disabled and the |\vphantom| neutralized. To do this, simply place the command |\chemskipalign| in the group of atoms: alignment resumes at the next group of atoms as if the group of atoms containing |\chemskipalign| had not existed. The following example shows the effect of this instruction, which places the reference point of the box containing the first atom at the level of the bond arriving from the left. The boxes enclosing the atoms have been drawn on the second line:

\exemple[60]{Disabling the alignment mechanism}*\typosize[13/]
\chemfig{A-.-B}\quad
\chemfig{A-\chemskipalign.-B}\par\bigbreak
\vvkern=0pt \hhkern=0pt \rulewidth=0.1pt
\def\printatom#1{\frame{\ifmmode\rm#1\else$\rm#1$\fi}}
\chemfig{A-.-B}\quad
\chemfig{A-\chemskipalign.-B}*

This command should be used with care because the alignment of the atoms in the following group of atoms may be disturbed. As a general rule, everything will go well if the group of atoms in which |\chemskipalign| appears contains \emph{a single atom} whose height and depth are \emph{smaller} than those of the preceding and following atoms, and if the preceding and following atoms have equal depth and height. Here, for example, is the mishap that occurs when the group of atoms contains 2 atoms, here “|\chemskipalign.|” and “|B|”:
\exemple{Consequence of the command \string\chemskipalign}*\typosize[13/]
\vvkern=0pt \hhkern=0pt \rulewidth=0.1pt
\def\printatom#1{\frame{\ifmmode\rm#1\else$\rm#1$\fi}}
\chemfig{A-\chemskipalign.B-C}*

This feature can sometimes prove useful. Suppose we want to draw the molecule
\centerstuff{%
	\def\emptydisk{\chemskipalign\tikz\draw(0,0)circle(2pt);}%
	\def\fulldisk{\chemskipalign\tikz\fill(0,0)circle(2pt);}%
	\chemfig{A-\CFhash(,0pt)\emptydisk-\CFhash(0pt,0pt)\fulldisk-\CFhash(0pt)B}%
}

The commands drawing the empty and filled disks can be defined with \TIKZ. So that these disks are at the right height, that is, at the height of the bond arriving at them, we use the command |\chemskipalign|. So that, on the second line of the example below, the bonds “stick” to the disks, we use the possibility of changing the offset of a bond with the character “|#|”:
\exemple{Using \code{\\chemskipalign} and \char`\#}/\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}/

\sec Shifted double bonds
All double bonds are made of 2 lines drawn on either side of the theoretical line that the single bond would follow. This double bond can be shifted so that one of the two lines is on this theoretical line, the other line then being above or below the bond. In fact, it is more rigorous to say “to the left” or “to the right” of the theoretical line when traveling along the bond in the drawing direction.

To shift the bond to the left, simply write “|=^|”, and to shift it to the right “|=_|”:
\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. They can however be shifted to the right by specifying it with “|=_|”:
\exemple{Shifted double bonds and rings}/\chemfig{*6(-=-=-=)}\qquad
\chemfig{*6(-=_-=_-=_)}/

Shifted bonds are particularly useful for drawing skeletal formulas of molecules containing carbon chains with double bonds. They give a continuous broken line, whereas this broken line would be discontinuous with normal double bonds:
\exemple{Shifted bonds and skeletal formulas}/\chemfig{-[:30]=[:-30]-[:30]=[:-30]-[:30]}\par
\chemfig{-[:30]=^[:-30]-[:30]=^[:-30]-[:30]}\par
\chemfig{-[:30]=_[:-30]-[:30]=_[:-30]-[:30]}/

\sec Delocalized double bonds
It is sometimes necessary to draw a double bond with one line solid and the other dashed. This feature is not hard-coded in \CF\ since \TIKZ, with its library “|decorations.markings|”, makes it possible.

\exemple*{Delocalized bonds}Z\catcode`\_=11
\tikzset{
	ddbond/.style args={#1}{
		draw=none,
		decoration={%
			markings,
			mark=at position 0 with {
				\coordinate (CF_startdeloc) at (0,\dimexpr#1\CF_doublesep/2)
				 coordinate (CF_startaxis)  at (0,\dimexpr-#1\CF_doublesep/2);
				},
			mark=at position 1 with {
				\coordinate (CF_enddeloc) at (0,\dimexpr#1\CF_doublesep/2)
				 coordinate (CF_endaxis)  at (0,\dimexpr-#1\CF_doublesep/2);
				\draw[dash pattern=on 2pt off 1.5pt] (CF_startdeloc)--(CF_enddeloc);
				\draw (CF_startaxis)--(CF_endaxis);
				}
			},
		postaction={decorate}
	}
}
\catcode`\_8
\chemfig{A-[,,,,ddbond={+}]B-[,,,,ddbond={-}]C}Z

\sec[definesubmol] Saving part of a molecule with \code{\\definesubmol}
\CF\ can save a |<code>| as an alias to reuse it in compact form in the code of a molecule. This is particularly useful when the |<code>| appears several times.

For this, the following command is available:
\CFcode|\definesubmol{<name>}{<code>}|

which saves the |<code>| so that it can be called in the code of the molecule with the shortcut “|!{<name>}|”. This |<name>| can be:
\begitems
	* a sequence of characters: all alphanumeric characters that can be between |\csname| and |\endcsname| are accepted;
	* a control sequence.
\enditems

In all cases, if the alias is already defined, overwriting it with a new definition made with |\definesubmol| is not recommended. A warning is issued, telling the user that this alias will be overwritten by the new one. To overwrite the definition of a previously defined alias, \label[redefinesubmol]\wlabel{use}use:
\CFcode|\redefinesubmol{<name>}{<code>}|

Here is a code that draws the pentane molecule. An alias “|xy|” has been defined beforehand for the code |CH_2|:
\exemple{Pentane}*\def\printatom#1{\strut\ifmmode\rm#1\else$\rm#1$\fi}
\definesubmol{xy}{CH_2}
\chemfig{H_3|C-!{xy}-!{xy}-!{xy}-CH_3}*

Here, the maneuver is not very interesting since “|!{xy}|” is as long to type as the code it replaces.

But in some cases, this feature saves a lot of space in the molecule code and improves its readability. In the following example, the expanded formula of butane is drawn. For this, an alias with the control sequence “|xx|” is defined for |CH_2|. Since only relative angles are used, the whole molecule can be rotated by any angle through the angle of the global optional parameter, which specifies the default bond angle of the main molecule. Here we use 15°:
\exemple{Butane}|\definesubmol\xx{C(-[::+90]H)(-[::-90]H)}
\chemfig{[:15]H-!\xx-!\xx-!\xx-!\xx-H}|

The command |\definesubmol| accepts an optional argument and its syntax is as follows:
\CFcode/\definesubmol{<name>}[<code1>]{<code2>}/

When the optional argument is present, the alias “|!<name>|” is replaced by |<code1>| if the bond arriving at the alias comes from the right, that is, if the angle of the incoming bond is between $-90°$ and 90°, these values being excluded. In all other cases, where the bond arrives from the left or vertically, the alias is replaced by |<code2>|.

We will define a control sequence |\Me| for “methyl” so that the alias “|!\Me|” is replaced by “|H_3C|” when the bond arrives from the right and by “|CH_3|” when it arrives from the left. With this alias, the example shows that we no longer need to worry about the angle (which in some more complex molecules is not even known):
\exemple{Dual alias}/\definesubmol\Me[H_3C]{CH_3}
\chemfig{*6((-!\Me)=(-!\Me)-(-!\Me)=(-!\Me)-(-!\Me)=(-!\Me)-)}/

The submolecule saved under a |<name>| takes no argument when called with “|!|”. To define a submolecule taking one or more arguments, write this |<number>| of arguments just after the |<name>|. The complete syntax of |\definesubmol| is therefore:
\CFcode/\definesubmol{<name>}<number>[<code1>]{<code2>}/

In the |<codes>|, the arguments must appear in their usual form “|#<n>|” where |<n>| is the number of the argument.
\exemple{\code{\\definesubmol} with arguments}/\definesubmol\X1{-[,-0.2,,,draw=none]{\scriptstyle#1}}
\chemfig{*6((!\X A)-(!\X B)-(!\X C)-(!\X D)-(!\X E)-(!\X F)-)}

\definesubmol{foo}3[#3|{#1#2}]{{#1#2}|#3}
\chemfig{A(-[:135]!{foo}{\bf}XY)-B(-[:45]!{foo}{\it}{W}{zoo})}/

Note that if the |<number>| of arguments is incorrect (negative or greater than 9), an error message is issued and \CF\ considers that the submolecule takes no argument.

Except when the character “|#|” is followed by a digit between 1 and |<number>|, in which case it represents an argument, “|#|” characters are allowed in the codes of submolecules.

\exemple{Using \#}/\definesubmol\X2{#1-#2-#3-#(3pt,3pt)#4}
\chemfig{A-!\X{M}{N}-B}/

In this example, only |#1| and |#2| are understood as the arguments of the submolecule |\X|. The other “|#|” are displayed as is in the molecule (case of |#3| and |#4|) or understood as the character specifying the fine tuning of bond offsets.

\sec[charge] The macro \code{\\charge}
\secc Presentation
The macro |\charge|, which requires two mandatory arguments, allows elements ---~which we will call charges~--- to be placed around an atom; its syntax is as follows
\CFcode|\charge{[<general parameters>]<position>[<tikz code>]=<charge>}{<atom>}|

where:
\begitems
	* the |<atom>| a priori consists of one or two letters, but may also be empty;
	* the |<charge>| is {\em arbitrary} content that will be placed around the |<atom>|. There are few constraints on this |<charge>|: it can be text (in math mode if needed), or even \TIKZ\ code or a molecule drawn with |\chemfig|;
	* the (optional) |<general parameters>| are a list of |<keys>|${}={}$|<values>| specifying the options this execution of the macro |\charge| must satisfy. These |<keys>| and |<values>| are described below;
	* the |<position>| has the form |<angle>:<shift>|, but it is possible to specify only the |<angle>|, in which case the |<shift>| is taken equal to |0pt|;
	* the optional |<tikz code>| contains the options passed to the \TIKZ\ macro |\node|, which places the |<charge>|.
\enditems

\secc Parameters
The |<keys>|${}={}$|<values>| available in the |<general parameters>| are:

\longtable{rcp{7.5cm\fL}}{%
	keys & default values & Description\cr\tskip2.5pt
	\Chargeparam{debug}& Boolean which, when equal to \CFval{true}, draws the outlines of the node receiving the |<atom>| (in green), of the one on which the |<charges>| are placed (in blue) and of those receiving the |<charges>| (in red).\cr
	\Chargeparam{macro atom}&Macro taking the |<atom>| as argument.\cr
	\Chargeparam{circle}&Boolean which, when equal to \CFval{true}, puts the |<atom>| in a circular node; otherwise, the node is rectangular.\cr
	\Chargeparam{macro charge}&Macro (|\printatom| or |\ensuremath| for example) taking each charge as argument.\cr
	\Chargeparam{extra sep}&Increase in the size of the node (circle or rectangle) for the position of the charges: this is the value passed to the \TIKZ\ key \CFkey{inner sep}.\cr
	\Chargeparam{overlay}&Boolean which, when \CFval{true}, draws the charges “overprinted”, that is, outside the final bounding box.\cr
	\Chargeparam{shortcuts}&Boolean which, when \CFval{true}, enables the shortcuts “|\.|”, “|\:|”, “\texttt{\string\|}” and “|\"|” to draw Lewis formulas.\cr
	\Chargeparam{lewisautorot}&Boolean which, when \CFval{true}, automatically rotates “|\:|” and “|\"|”.\cr
	\Chargeparam{.radius}&Radius of the dot used to draw “|\.|” and “|\:|”\cr
	\Chargeparam{:sep}&Separation between the two dots of “|\:|”\cr
	\Chargeparam{.style}&\TIKZ\ style used to draw the dots “|\.|” and “|\:|”\cr
	\Chargeparam{"length}&Length of the rectangle |\"| and of the line \code{\|}\cr
	\Chargeparam{"width}&Width of the rectangle |\"|\cr
	\Chargeparam{"style}&\TIKZ\ style used to draw the rectangle |\"|\cr
	\Chargeparam{|style}&\TIKZ\ style used to draw the line \code{\|}\cr
}%

Some (or all) of these parameters can be changed by executing the macro
\CFcode|\setcharge{<keys>=<values>}|

and all parameters can be reset to their default values with
\CFcode|\resetcharge|

The macro |\charge| places the |<charges>| outside the bounding box (unless otherwise specified in the |<parameters>|), whereas |\Charge| places them {\em inside} the bounding box.
\medbreak

The |<angle>| is the place on the boundary of the node where the |<charge>| is placed. This |<angle>| can be expressed in degrees or be a boundary anchor in the \TIKZ\ sense, such as “|south east|”. The |<shift>| is a \TeX{} dimension and represents an additional length between the boundary of the node containing the |<atom>| and the place where the |<charge>| is placed. Unless otherwise indicated in the |<tikz code>|, the placement concerns the {\em center} of the node containing the charge.
\medbreak

In the following two examples, \CFkey{debug} is set to \CFval{true} to better perceive the changes induced by modifying the parameters. Moreover, the macro |\Charge| is used so that the bounding boxes take the charges into account. Here one can see the influence of the shape of the node on the placement of the charges:
\exemple{Generic example}/Default node:
	\Charge{30=\:,120=$\ominus$,210=$\delta^+$}{Fe}\qquad
	\setcharge{debug=true}
	\Charge{30=\:,120=$\ominus$,210=$\delta^+$}{Fe}
	\setcharge{debug=false}
\medbreak
Circular node:
	\Charge{[circle]30=\:,120=$\ominus$,210=$\delta^+$}{Fe}\qquad
	\setcharge{debug=true}
	\Charge{[circle]30=\:,120=$\ominus$,210=$\delta^+$}{Fe}/

To move the charges $\ominus$ and $\delta^+$ further away, the |<shift>| can be used
\exemple{Shifting charges}/Without shift:
  \Charge{30=\:,120=$\ominus$,210=$\delta^+$}{Fe}
\medbreak
With shift:
  \Charge{[circle]30:3pt=\:,120:5pt=$\ominus$,210:5pt=$\delta^+$}{Fe}/

The anchor can also be adjusted: the |<angle>| where the |<charge>| is placed is stored in the macro |\chargeangle|; it is therefore wise to choose the anchor equal to |180+\chargeangle|. It is also possible to specify a circular node in which to place the |<charge>|.
\exemple{Fine positioning}|\Charge{30=\:,120:3pt=$\ominus$,210:5pt=$\delta^+$}{Fe}\qquad
\setcharge{debug}
\Charge{30=\:,120:3pt=$\ominus$,210:5pt=$\delta^+$}{Fe}
\setcharge{debug=false}
\medbreak
\Charge{[circle]30=\:,
        120[circle,anchor=180+\chargeangle]=$\ominus$,
        210[anchor=180+\chargeangle]=$\delta^+$}{Fe}%
\setcharge{debug}\qquad
\Charge{[circle]30=\:,
        120[circle,anchor=180+\chargeangle]=$\ominus$,
        210[anchor=180+\chargeangle]=$\delta^+$}{Fe}|

It is important to note that circular nodes have sizes that are {\em sometimes very different} from “classic” rectangular nodes, especially regarding horizontal and vertical extent. The boolean key \CFkey{circle} should therefore be set to \CFval{true} knowingly.

\exemple{Circular nodes}/\chemfig{\charge{90=\.}{N}H_3}: rectangular node\smallbreak
\chemfig{\charge{[circle]90=\.}{N}H_3}: circular node/

\sec[chemabove.chembelow] Stacking characters
The macros
\CFcode|\chemabove[<dim>]{<code>}{<material>}|

and
\CFcode|\chembelow[<dim>]{<code>}{<material>}|

place the |<material>| respectively above and below the |<code>| at a vertical distance |<dim>|, without changing the bounding box of the |<code>|. The optional argument allows specifying this dimension at each call if desired. If the optional argument is not used, a default dimension is taken: it is \CFval{1.5pt} but can be changed with the key \CFkv{stack sep}{dim}.

These commands are independent of the macro |\chemfig| and can be called inside or outside its argument.

They can be used in particular in rings, taking care to put braces around the letters A, B, C and D to prevent \CF\ from stopping the reading of the atom at these letters:
\exemple{Stacking in rings}|\chemfig{*5(-\chembelow{A}{B}--\chemabove{C}{D}--)}|

The commands |\Chemabove| and |\Chembelow| work the same way except that the bounding box {\em takes into account} the |<material>| placed above or below.

What is the difference between |\chemabove| and |\charge| when it comes to placing content above or below another?
\exemple{\string\chemabove\space or \string\charge}/\chemfig{*5(----\chemabove{A}{\oplus}-)}
\chemfig{*5(----\charge{90[anchor=-90]=$\oplus$}{A}-)}/

By default, both macros give very similar results. There are however differences in their use: the macro |\charge| requires the \TIKZ\ package, whereas |\chemabove| and |\chembelow| are coded with low-level \TeX{} primitives and are therefore {\em fast} and independent of any package.

\sec[save] Saving to a file
The boolean key \CFkey{save}, which is \CFval{false} by default, allows, when it is \CFval{true}, saving to a file the \TIKZ\ instructions\fnote{The macros \code{\\chemabove}, \code{\\chembelow} and \code{\\charge} are not translated into \TIKZ\ instructions and are left as they are.} generated by |\chemfig{<code>}|.

The key \CFkey{save name} specifies the name of the file (the extension will always be |tex|). Its default value is
\CFcode|\jobname-fig*|

where the character “|*|”, if used, is replaced by a number that starts at 1 and is incremented each time the macro |\chemfig| is called with \CFkv{save}{true}.

\sec How to\dots?
\secc Write a colored atom
Since the package |xcolor| is loaded by \TIKZ, itself loaded by \CF, color instructions such as |\Red|, |\Blue|, etc.\ can be put in the code of a molecule\fnote{For those using \LaTeX, these will be the macros \code{\\color} and \code{\\textcolor}.}. Since atoms are displayed in \TIKZ\ nodes, which behave like \TeX{} boxes, everything happens as if these atoms were confined in a group, so the color change remains local to the atom.

\exemple{Colors}/\chemfig{C\Blue H_3-C(=[1]O)-[7]O\Red H}/

One can see that this code does not work, again because of the rule used by \CF: here, the first atom of the molecule starts at “|C|” and extends to the next uppercase letter. This atom is therefore “|C\Blue|” and so the color change happens at the end of the atom and has no effect. One must force \CF\ to cut the first atom just after “|C|” with the character “\texttt{\string|}” and then enclose |\Blue H_3| between braces so that \CF\ does not stop the second atom before the “|H|”:
\exemple{Colors}/\chemfig{C|{\Blue H_3}-C(=[1]O)-[7]O|{\Red H}}/

The main drawback is that the operation must be repeated for each atom to be colored, even if they are contiguous.

\secc Add a superscript without affecting a bond
Adding a |<charge>| as a mathematical superscript to an atom means that the box (and therefore the \TIKZ\ node) containing it will have its dimensions changed. This hardly matters if the atom is at the end of a chain, but the aesthetics can be compromised if a bond must leave from it. The first reflex is to put the superscript in a zero-size \TeX{} box and thus to use the macro |\rlap|\fnote{If the charge must be put to the left of the atom, use the command \code{\\llap}.}, which often gives satisfactory results. Here one can see that thanks to |\rlap|, the horizontal alignment of the atoms is preserved:
\exemple{Charge and bond}/\chemfig{A^+-[2]B}
\qquad
\chemfig{A\rlap{${}^+$}-[2]B}/

The macro |\charge| performs this task simply and precisely.
\exemple{Placing charges}/\chemfig{\charge{[extra sep=0pt]45[anchor=180+\chargeangle]=%
$\scriptstyle\oplus$}{A}-[2]B}
\qquad
\chemfig{*5(---\charge{90:2pt=$\scriptstyle\oplus$}{}-%
\charge{135:2pt=$\scriptstyle-$}{}-)}/

\secc Draw a curved bond
We have already seen that with the \TIKZ\ library “|decorations.pathmorphing|”, a wavy bond can be drawn:

\exemple{Wavy bond}|\chemfig{A-[,3,,,decorate,decoration=snake]B}

\chemfig{A-[,3,,,decorate,decoration={snake,amplitude=1.5mm,
    segment length=2.5mm}]B}|

It is also possible to define a submolecule “wb” to draw a wavy line perpendicular to the previous bond:

\exemple{Wavy bond}|\definesubmol{wb}{%
	(-[::90,.5,,,draw=none]%
	-[::180,,,,blue,decorate,decoration={%
		snake,amplitude=0.2mm,segment length=0.75mm
		}%
	])}
\chemfig{!{wb}-O-[:60]}
\qquad
\chemfig{([:150]-!{wb})([:-90]-!{wb})=_[:30]-[:-30]!{wb}}|

For more flexibility, one can also place nodes with the marker “|@|” and reuse these nodes after the molecule has been drawn to connect them with a curved line using |\chemmove|:

\exemple[70]{Curved bonds}/\chemfig{@{a}A-[,,,,draw=none]@{b}B}
\chemmove{\draw[-](a)..controls +(45:7mm) and +(225:7mm)..(b);}
\bigskip

\chemfig{*6(@{a}---@{b}---)}
\chemmove{\draw[-](a)..controls +(60:3em) and +(240:3em)..(b);}/

\secc[polymerdelim] Draw a polymer element
The macro |\polymerdelim| has the following syntax:
\CFcode|\polymerdelim[<keys>=<values>]{<node1>}{<node2>}|

The effect, possibly after {\em two} compilations, is to place vertical delimiters at the specified nodes: by default, the first delimiter is placed on the first node and the second on the same horizontal line as the first, but at the abscissa of the second. The parameters are specified via keys and values, whose list, default values and actions are given here.

\longtable{rcp{7.5cm}}{
	keys & default values & Description \cr\tskip2.5pt
	\CFdelimparam{delimiters} & Defines the delimiters. If these delimiters are square brackets, one must write |delimiters={[]}|.\cr
	\CFdelimparam{height} & Defines the height (above the node) of the delimiters.\cr
	\CFdelimparam{depth}  & Defines the depth (below the node) of the delimiters. If the value is empty, the depth is equal to the height.\cr
	\CFdelimparam{h align}&Boolean which, when |false|, places the \eme2 delimiter on the \eme2 node, at the risk that the delimiters are not on the same horizontal line.\cr
	\CFdelimparam{auto rotate}&Boolean which, when equal to \CFval{true} and when \CFkv{h align}{false}, automatically rotates the delimiters so that they are perpendicular to the line connecting the two nodes.\cr
	\CFdelimparam{rotate}&When \CFkv{h align}{false} and \CFkv{auto rotate}{false}, specifies the rotation angle of both delimiters.\cr
	\CFdelimparam{open xshift}& Defines the horizontal shift of the opening delimiter.\cr
	\CFdelimparam{close xshift}& Defines the horizontal shift of the closing delimiter. If the value is empty, this shift is the opposite of the shift of the opening delimiter.\cr
	\CFdelimparam{indice} & Defines the subscript placed at the bottom right of the closing delimiter.
}%

\exemple*{Polyethylene}|\chemfig{\vphantom{CH_2}-[@{op,.75}]CH_2-CH_2-[@{cl,0.25}]}
\polymerdelim[height = 5pt, indice = \!\!n]{op}{cl}|

\exemple*{Polyvinyl chloride}|\chemfig{\vphantom{CH_2}-[@{op,1}]CH_2-CH(-[6]Cl)-[@{cl,0}]}
\polymerdelim[height = 5pt, depth = 25pt, open xshift = -10pt, indice = \!\!n]{op}{cl}|

\exemple*{Nylon 6}|\chemfig{\phantom{N}-[@{op,.75}]{N}(-[2]H)-C(=[2]O)-{(}CH_2{)_5}-[@{cl,0.25}]}
\polymerdelim[height = 30pt, depth = 5pt, indice = {}]{op}{cl}|

\exemple*{Polycaprolactam}|\chemfig[atom sep = 2em]{[:-30]-[@{left,.75}]N(-[6]H)-[:30](=[2]O)--[:30]--[:30]--[@{right,0.25}:30]}
\polymerdelim[height = 5pt, indice = \!\!n]{left}{right}|

\exemple*{Polyphenylene sulfide}|\chemfig{\vphantom{S}-[@{op,.75}]S-(**6(---(-[@{cl,0.25}])---))}
\polymerdelim[delimiters = (), height = 15pt, indice = {}]{op}{cl}|

\exemple*{Polymer}|\def\printatom#1{\strut\ifmmode\rm#1\else$\rm#1$\fi}
\chemfig{
	-CH_2-CH
		([6]-CO-NH-CH_2-NH-CO-CH
			([4]-CH_2-)
			([0]-[@{downleft,0.8},2]CH_2-CH([2]-CO-NH_2)-[@{downright,0.3},2]CH_2-[,1.5]C?H-)
		)
	-[@{upleft,0.8},2]CH_2-CH
		([6]-CO-NH_2)
	-[@{upright,0.3},2]CH_2-[,1.5]CH
		([6]-CO-NH-CH_2-NH-C?O)
	-}
\polymerdelim[delimiters ={[]}, height = 5pt,  depth = 55pt, indice = n]{upleft}  {upright}
\polymerdelim[delimiters ={[]}, height = 50pt, depth = 10pt, indice = n]{downleft}{downright}|


\exemple*{Polymer}|\chemfig{-[@{op,.5}:-30]O-[::60](=[::60]O)-[::-60]*6(-=-(-(=[::-60]O)-[::60]O-[::-60]-[::60]-[@{cl,.5}::-60])=-=)}
\polymerdelim[height=6ex, indice=n, h align=false]{op}{cl}|

\secc[hflipnext] Draw the mirror image of a molecule
The two commands |\hflipnext| and |\vflipnext| draw the mirror image of the next molecule with respect to a horizontal or vertical axis. To build the mirror image of several molecules, the commands must be written before each molecule concerned.

\exemple{Mirror images}/\chemfig{H_3C-C(=[:30]O)-[:-30]OH}\par% original
\vflipnext% draws the vertical mirror image of:
\chemfig{H_3C-C(=[:30]O)-[:-30]OH}
\bigbreak
\chemfig{H_3C-C(=[:30]O)-[:-30]OH}% original
\hflipnext% draws the horizontal mirror image of:
\chemfig{H_3C-C(=[:30]O)-[:-30]OH}/

\secc Add text above bonds and mark angles
Once one has understood that the character “|@|” places a “global” \TIKZ\ node, that is, accessible after the molecule has been drawn, everything that is possible with \TIKZ\ and nodes (that is, many things) becomes conceivable.

To write something above or below a bond, one can therefore place “global” nodes on the atoms at the ends of this bond and write, halfway between these two nodes, a text that is raised or lowered so that it is just above or below the bond. This is what the command |\namebond| does in the code below.

For angles between two bonds leaving an atom, 3 atoms are involved and a global node must be placed on each of them. The angle between two lines leaving the same node can easily be computed; this is what the command |\arcbetweennodes| does. Then the macro |\arclabel| draws an arc between two bonds and writes a text next to this arc: the optional argument of this macro is the code passed to \TIKZ. Argument 2 is the radius of the arc, while the next three arguments are the names of the global nodes between which the arc must be drawn, the middle name being that of the vertex of the angle. Finally, the last argument is the text to write.

\exemple*{Angles and text on bonds}|\def\angstrom{\charge{90:-1pt=°}{A}}
\def\namebond#1#2#3#4{\chemmove{\path(#2)--(#3)node[midway,sloped,yshift=#1]{#4};}}

\def\arcbetweennodes#1#2#3{%
  \pgfmathanglebetweenpoints{\pgfpointanchor{#1}{center}}{\pgfpointanchor{#2}{center}}%
  \let#3\pgfmathresult}

\def\arclabel#1#2#3#4#5{%
  \chemmove{%
    \arcbetweennodes{#3}{#2}\anglestart
    \arcbetweennodes{#3}{#4}\angleend
    \draw[stealth-stealth,shorten <=1pt,shorten >=1pt]([shift=(\anglestart:#1)]#3)arc(\anglestart:\angleend:#1);
    \pgfmathsetmacro\anglestart{(\anglestart+\angleend)/2}%
    \node[shift=(\anglestart:#1+1pt),anchor=\anglestart+180,rotate=\anglestart+90,inner sep=0pt,
          outer sep=0pt]at(#3){#5};}}

\chemfig{@{a}A=[:30,1.5]@{b}B-[7,2]@{c}C-@{d}D}
\namebond{5pt}{a}{b}{ Text}
\namebond{-3.5pt}{b}{c}{$\pi$}
\namebond{5pt}{c}{d}{1 \angstrom}
\medbreak
Horizontal water molecule: \chemfig{@{1}H-[::37.775,2]@{2}O-[::-75.55,2]@{3}H}.
\namebond{5pt}{1}{2}{0.9584 \angstrom}
\namebond{5pt}{2}{3}{0.9584 \angstrom}
\arclabel{0.5cm}{1}{2}{3}{104.45°}
\medbreak
Water molecule rotated by -30°: \chemfig{[:-30]@1H-[::37.775,2]@2O-[::-75.55,2]@3H}
\namebond{5pt}12{0.9584 \angstrom}
\namebond{5pt}23{0.9584 \angstrom}
\arclabel{0.5cm}{1}{2}{3}{104.45°}|

\secc Draw multiple bonds
Here again, the library “|decorations.markings|” makes it possible to draw multiple bonds:

\exemple*{Multiple bonds}|\catcode`\_=11
\tikzset{nbond/.style args={#1}{%
	draw=none,%
	decoration={%
		markings,%
		mark=at position 0 with {\coordinate (CFstart@) at (0,0);},
		mark=at position 1 with {%
		\foreach\ii in{0,1,...,\number\numexpr#1-1}{%
			\pgfmathsetmacro\CF_nbondcoeff{\ii-0.5*(#1-1)}%
			\draw ([yshift=\CF_nbondcoeff\CF_doublesep]CFstart@)--(0,\CF_nbondcoeff\CF_doublesep);
			}%
		}
		},
	postaction={decorate}
	}
}
\catcode`\_=8
\chemfig{A-[1,,,,nbond=4]B-[:-30,,,,nbond=5]C-[:15,,,,nbond=6]D}|

\sec Annotated examples
In this chapter, several molecules will be drawn using the methods previously presented. The aim here is to show in what logical order a molecule can be built, so that the user unfamiliar with \CF\ acquires a method for building complex molecules. To help, the construction steps will be shown.

Moreover, it will be shown that several possibilities are available to the user for the same graphic result, some intuitive and others much less so, the point being to show that \CF\ allows a certain flexibility in coding molecules. It is then up to each user to build and adopt the methods they are most comfortable with.

\secc Ethanal
Here we will draw the ethanal molecule: \chemfig{H-C(-[2]H)(-[6]H)-C(-[7]H)=[1]O}

The best method for non-cyclic molecules is to choose the longest chain. Here one can take “|H-C-C=O|”, for example. The bond |C=O| must be tilted by 45° using the predefined angle “|[1]|”. This gives the “structure” of the molecule, to which it will suffice to add the branches:
\exemple{Structure of ethanal}|\chemfig{H-C-C=[1]O}|

It remains to place 3 hydrogen atoms with the right tilts using predefined angles. The first at 90° with the branch “|(-[2]H)|”, the second at 270° with “|(-[6]H)|” and the one on the right at 315° with “|(-[7]H)|”:
\exemple{Ethanal}|\chemfig{H-C(-[2]H)(-[6]H)-C(-[7]H)=[1]O}|

\secc 2-amino-4-oxohexanoic acid
Here is the molecule to draw: \chemfig{-[::+30]-[::-60](=[:-90]O)-[::+60]-[::-60](-[:-90]NH_2)-[::+60](=[:90]O)-[::-60]OH}

There are ---~as is often the case for most molecules~--- several methods, and for each, several different ways of reaching the result. Here, we will examine 4 different methods.

{\bf Method with absolute angles}\par
We first draw the middle chain with absolute angles. The default angle is set to $+30°$ with the optional argument, so only the “descending” bonds need their absolute angle of $-30°$ to be specified:
\exemple{Structure (absolute angles)}|\chemfig{[:30]--[:-30]--[:-30]--[:-30]OH}|

It remains to add the branches “|(=[6]O)|”, “|(-[6]NH_2)|” and “|(=[2]O)|” on the right vertices:
\exemple{Molecule (absolute angles)}|\chemfig{[:30]--[:-30](=[6]O)--[:-30](-[6]NH_2)-(=[2]O)-[:-30]OH}|

{\bf Method with relative angles}\par
A more general approach would have been to use only relative angles. One would have proceeded 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}|

{\bf Method with a ring}\par
Since the angles between the bonds are 120°, one may think of using a 6-ring, although this method is less natural. Here one must take advantage of the fact that a ring can be incomplete. It is also necessary to rotate the ring by 120° so that the first vertex is at the south-east of the ring:
\exemple{Structure}|\chemfig{[:120]NH_2*6(---=O)}|

The branches must now start from the appropriate vertices:
\exemple{Molecule (ring)}|\chemfig{[:120]NH_2*6(-(-(=[::60]O)-[::-60]OH)--(--[::60])=O)}|

{\bf Method with fused rings}\par
Going further with the ring method, one can also think of nesting incomplete 6-rings. One could start from this structure:
\exemple{Structure}|\chemfig{*6(--*6(--=O))}|

And then add the bonds leaving the vertices of these rings. There is no need to worry about angles since the bonds leaving rings are the bisectors of the sides of the ring, which is precisely what we want here:
\exemple{Molecule (nested rings)}|\chemfig{*6((-)-(=O)-*6(-(-NH_2)-(-OH)=O))}|

A careful examination reveals, however, that the second double bond to the oxygen atom is {\em inside} the incomplete 6-ring\fnote{This was also the case for the previous method with a single ring.}. Despite its conciseness, this code therefore does not lead to a perfect drawing. This defect can of course be corrected by lengthening the code a little:
\exemple{Molecule (corrected nested rings)}|\chemfig{*6((-)-(=O)-*6(-(-NH_2)-(-OH)(=[::60]O)))}|

\secc Glucose
The aim here is to represent the glucose molecule according to different conventions.

{\bf Skeletal formula}\par
The code here resembles that of 2-amino-4-oxohexanoic acid. Almost the same structure is obtained with absolute angles, except that here the default angle is $-30°$:
\exemple[60]{Structure}|\chemfig{[:-30]HO--[:30]--[:30]--[:30]-H}|

And adding the branches poses no particular problem. Absolute angles are used:
\exemple[60]{Fructose, skeletal formula}|\chemfig{[:-30]HO--[:30](<[2]OH)-(<:[6]OH)
-[:30](<:[2]OH)-(<:[6]OH)-[:30](=[2]O)-H}|

{\bf Fischer projection}\par
The aim is to obtain the molecule below:
\centerstuff{
	\definesubmol{x}{(-[4]H)(-[0]OH)}
	\definesubmol{y}{(-[0]H)(-[4]OH)}
	\chemfig{[2]OH-[3]-!x-!x-!y-!x-=[1]O}
}
The idea is to start by drawing the longest vertical chain, specifying a default angle “|[2]|”. Here is the structure, where lowercase letters are deliberately put at the end of each vertical bond:
\exemple{Structure}|\chemfig{[2]OH-[3]-a-b-c-d-=[1]O}|

Then two aliases are defined for the horizontal bonds and the atoms that will end them. Let us take “|x|”, which we will put in place of the lowercase letters a, b and d, and “|y|”, which will take the place of the letter c. Since the aliases consist of a single character, braces can be omitted and one can write “|!x|” instead of “|!{x}|”:
\exemple{Glucose (Fischer projection)}|\definesubmol{x}{(-[4]H)(-[0]OH)}
\definesubmol{y}{(-[0]H)(-[4]OH)}
\chemfig{[2]OH-[3]-!x-!x-!y-!x-=[1]O}|

{\bf “Chair” representation}\par
We will represent this molecule of $\alpha$-D-glucose:
\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)}

For this, we first draw 5 sides of the chair and connect the first vertex to the last with a hook “|?|”. The following absolute angles are adopted, given in counterclockwise order: $-50°$, $10°$, $-10°$, $130°$, $190°$.
\exemple{Structure}|
\chemfig{?-[:-50]-[:10]-[:-10]-[:130]O-[:190]?}|

Now it suffices to add the branches between parentheses. The angles are chosen as well as possible to give an impression of perspective, and some bonds are shortened by a coefficient 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)}|

{\bf Haworth projection}\par
The aim is to represent this molecule of D-glucopyranose:
\chemfig[cram width=2pt]{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, we choose the longest chain, which starts from the “HO” group on the left and continues over 5 sides of the ring. The ring will be closed with a hook. For the vertical bond leaving the first “HO” group, it must be specified with the optional argument that it starts from the second atom. Moreover, it will be shortened by a coefficient of 0.5. Its optional argument will therefore be “|[2,0.5,2]|”.

Then, to give an impression of perspective to the ring, the tilted bonds are reduced by a coefficient of 0.7. For the tilted bold lines, Cram bonds are used, with the width of the base of the triangles redefined to 2pt. The horizontal bold bond must be drawn with a width of 2pt and its optional argument will therefore be “|[0,,,,line width=2pt]|”. Here is the structure of the molecule:
\exemple{Structure}|\chemfig[cram width=2pt]{HO-[2,0.5,2]?<[7,0.7]-[,,,,
line width=2pt]>[1,0.7]-[3,0.7]O-[4]?}|

All that remains is to add the branches, in the right places, specifying well-chosen absolute angles and sometimes reduced lengths to better give the illusion of perspective:
\exemple{Haworth projection}|\chemfig[cram width=2pt]{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)}|

\secc Adrenaline
We want to draw the adrenaline molecule:
\chemfig{*6((-HO)-=-(-(<[::60]OH)-[::-60]-[::-60,,,2]HN-[::+60]CH_3)=-(-HO)=)}

We will use two different methods.

{\bf Using one ring}\par
First, we start from the 6-ring and draw the beginning of the branches leaving it:
\exemple[60]{Structure of adrenaline}|\chemfig{*6((-HO)-=-(-)=-(-HO)=)}|

The branch on the right must now be completed, using, for example, relative angles:
\exemple[60]{Adrenaline, step 2}|\chemfig{*6((-HO)-=-(--[::-60]-[::-60]
HN-[::+60]CH_3)=-(-HO)=)}|

Then the Cram bond to |OH| must be added, and it must be specified that the bond arriving at “|HN|” does so on the second atom “N”. We use the \eme4 optional argument of the bond:
\exemple[60]{Adrenaline}|\chemfig{*6((-HO)-=-(-(<[::60]OH)-[::-60]-[::-60,,,2]
HN-[::+60]CH_3)=-(-HO)=)}|

{\bf Using 2 rings}\par
This method is less natural, but the aim here is to explain how to make a bond invisible.

This code could be improved by considering that the drawing of the adrenaline molecule consists of two 6-rings fused together:
\exemple[60]{Adrenaline, 2-ring structure}|\chemfig{*6((-HO)-=*6(--HN---)-=-(-HO)=)}|

The first two bonds of the right ring must therefore be made invisible. For this, we use the argument passed to \TIKZ, specifying “|draw=none|”. These bonds therefore have this code: “|-[,,,,draw=none]|”. To keep the code readable, an alias named “|&|” is defined for these bonds:
\exemple[60]{Adrenaline, step 2}|\definesubmol{&}{-[,,,,draw=none]}
\chemfig{*6((-HO)-=*6(!&!&HN---)-=-(-HO)=)}|

The rest becomes easy: it suffices to add the branches at the right vertices:
\exemple[60]{Adrenaline, step 3}|\definesubmol{&}{-[,,,,draw=none]}
\chemfig{*6((-HO)-=*6(!&!&HN(-CH_3)--(<OH)-)-=-(-HO)=)}|

Finally, we specify that the bonds {\em arriving at and leaving} “|HN|” must do so at the second atom. We therefore define another alias for the invisible bond arriving at “|HN|”:
\exemple[60]{Adrenaline}|\definesubmol{&}{-[,,,,draw=none]}
\definesubmol{&&}{-[,,,2,draw=none]}
\chemfig{*6((-HO)-=*6(!&!{&&}HN(-CH_3)-[,,2]-(<OH)-)-=-(-HO)=)}|

\secc Guanine
We will draw the guanine molecule:
\chemfig{*6((-H_2N)=N-*6(-\chembelow{N}{H}-=N?)=?-(=O)-HN-[,,2])}\medskip

First, let us draw the nested rings, putting only the nitrogen atoms at the vertices:
\exemple{Guanine, structure}|\chemfig{*6(=N-*6(-N-=N)=--N-)}|

Then we draw the horizontal bond in the right ring with a hook. We also place a hydrogen atom under the nitrogen atom of the 5-ring with the command |\chembelow{N}{H}|. We must also write “|HN|” instead of “|N|” at the top left vertex of the molecule:
\exemple{Guanine, step 2}|\chemfig{*6(=N-*6(-\chembelow{N}{H}-=N?)=?--HN-)}|

One can see that a bond leaves from the wrong atom\fnote{This seems illogical since the angle of the bond from the group |HN| to the first vertex of the 6-ring is between $-90°$ and $90°$; \CF\ should therefore start from the \eme2 atom. To explain this contradiction, one must know that in rings, the last bond always connects the last vertex to the first vertex, ignoring the {\em computed theoretical} angle of this bond (which is $-90°$ here). \CF\ uses this theoretical angle to determine the departure and arrival atoms, but does not use it to draw the bond since both ends are already defined. The departure atom of the last bond is therefore the first one.}! The automatic computation mechanism must be corrected so that the bond starts from the \eme2 atom “|N|” instead of the first. For this, an optional argument “|[,,2]|” is specified for the last bond of the first 6-ring:
\exemple{Guanine, step 3}|\chemfig{*6(=N-*6(-\chembelow{N}{H}-=N?)=?--HN-[,,2])}|

It suffices to add the branches at the right vertices. Note in particular the branch leaving the first vertex of the first 6-ring, “|(-H_2N)|”:
\exemple{Guanine}|\chemfig{*6((-H_2N)=N-*6(-\chembelow{N}{H}-=N?)=?-(=O)-HN-[,,2])}|

This same molecule could also have been drawn with a {\em regular} 5-ring, as is sometimes done:
\exemple{Guanine with 5-ring}|\chemfig{*6((-H_2N)=N-*5(-\chembelow{N}{H}-=N-)=-(=O)-HN-[,,2])}|

\chap Reaction schemes
I thank Clemens~{\caps\rm Niederberger} for the help he gave me and the tests he carried out on the new features presented in this part.

\sec[schemestart] Overview
A reaction scheme is placed in the environment delimited by the macros |\schemestart| and |\schemestop|. The syntax of the macro |\schemestart| is
\CFcode|\schemestart[<keys>=<values>] <reaction> \schemestop|

As can be seen in this example, debugging information has been hidden and then made visible to help understanding, with the key \CFkey{scheme debug} and the value \CFval{true} or \CFval{false}:
\exemple[50]{Example 1}/\setchemfig{scheme debug=false}
\schemestart
  \chemfig{*6(-=-=-=)}\arrow
  \chemfig{X=[1]Y}\arrow
  \chemfig{S>T}
\schemestop
\bigbreak
\setchemfig{scheme debug=true}
\schemestart
  \chemfig{*6(-=-=-=)}\arrow
  \chemfig{X=[1]Y}\arrow
  \chemfig{S>T}
\schemestop/

Some remarks:
\begitems
	* the |\arrow| commands draw the arrows;
	* everything between two |\arrow| commands is considered a compound. The choice was made that all possible settings, whether they concern arrows or compounds, are made through the arguments of the |\arrow| command, whose syntax becomes rather complex as a result;
	* arrows are drawn horizontally, which can of course be changed;
	* arrows lie on the imaginary line connecting the centers of the bounding boxes of the compounds (the red and blue dots are the attachment points of the arrows). This behavior can also be changed;
	* the debugging information, made visible or not with the key \CFkey{scheme debug}, is:
	\begitems \style x
		* what appears in green above the bounding boxes is the name assigned by default by \CF\ to the compounds, following the progression |c1|, |c2|, etc. Numbering restarts at 1 for a new reaction scheme;
		* the bounding boxes of the compounds;
		* the ends of the arrows are shown by red dots and the anchors by blue dots;
	\enditems
	* the edge-to-edge distance between two compounds is defined with the key \CFkv{compound sep}{dim}. The default value of \CFval{dim} is 5em;
	* finally, the distance between the edges of the compounds and the start and end of the arrows is defined with the key \CFkv{arrow offset}{dim}. By default, this \CFval{dim} is 4pt.
\enditems

Here is the exhaustive list of parameters concerning the macro |\schemestart|, their default values and a brief description. These parameters must be set with the macro |\setchemfig{<keys>=<values>}|.

\longtable{rcp{7.5cm}}{
	keys & default values & Description\cr\tskip2.5pt
	\CFparam{schemestart code}{arbitrary code executed at the very beginning of the non-nested environment \code{\\schemestart} (just after the \code{\\begingroup})}
	\CFparam{schemestop code}{arbitrary code executed at the very end of the non-nested environment \code{\\schemestart} (just before the \code{\\endgroup})}
	\CFparam{init anchor}{anchor of the first compound}
	\CFparam{scheme debug}{if \CFval{true}, displays the boundaries of the compounds, their names and the anchors}
	\CFparam{compound style}{style of the compounds}
	\CFparam{compound sep}{spacing between 2 compounds}
	\CFparam{name sep}{minimum vertical distance between the boxes of the compound and of its name}
	\CFparam{arrow offset}{spacing between a compound and the arrow}
	\CFparam{arrow angle}{default angle of reaction arrows}
	\CFparam{arrow coeff}{length coefficient of the arrows}
	\CFparam{arrow style}{style of the arrows}
	\CFparam{arrow double sep}{spacing between double arrows}
	\CFparam{arrow double coeff}{reduction coefficient of the small arrow for double arrows}
	\CFparam{arrow double harpoon}{boolean for drawing double arrows as “harpoons”}
	\CFparam{arrow label sep}{spacing between the arrow and its text}
	\CFparam{arrow head}{style of the arrow tips}
	\CFparam{+ sep left}{spacing before the $+$ sign}
	\CFparam{+ sep right}{spacing after the $+$ sign}
	\CFparam{+ vshift}{vertical shift of the $+$ sign}\
}

\sec[arrow] Arrow types
When the command |\arrow| is followed by an optional argument between braces (which is therefore not mandatory), this argument contains the arrow type:
\exemple[50]{Arrow types}|\schemestart A\arrow{->}B\schemestop\par % default
\schemestart A\arrow{-/>}B \schemestop\par
\schemestart A\arrow{<-}B \schemestop\par
\schemestart A\arrow{<->}B \schemestop\par
\schemestart A\arrow{<=>}B \schemestop\par
\schemestart A\arrow{<->>}B \schemestop\par
\schemestart A\arrow{<<->}B \schemestop\par
\schemestart A\arrow{0}B \schemestop\par
\schemestart A\arrow{-U>}B \schemestop|
The arrow “|-UZ|” is not drawn completely; an arc tangent to it at its middle can be added with the optional arguments passed to this arrow, see page~\pgref[fleche.arg.optionnel]. Here is a “|-UZ|” arrow with its arc: \schemestart A\arrow{-U>[$\scriptstyle x$][$\scriptstyle y$]}B\schemestop

For the sake of brevity, from now on, except for special examples, uppercase letters will be used instead of chemical formulas created with the |\chemfig| command. Obviously, reaction schemes work identically with letters or molecule drawings. Several examples involving reaction schemes can be seen in the gallery.

\sec Arrow features
Each arrow is characterized by:
\begitems
	* an angle in degrees, set with \CFkv{arrow angle}{angle}, which is 0 by default;
	* a coefficient specified by \CFkv{arrow coeff}{decimal}, which is 1 by default and gives the length of the arrow by multiplying the value of the spacing between compounds defined by \CFkey{compound sep};
	* a style, defined by \CFkv{arrow style}{tikz code}, empty by default, which contains \TIKZ\ instructions allowing the color, the thickness of the arrow or another graphic attribute to be customized.
\enditems

\exemple[50]{Setting default values}/\schemestart A\arrow B\arrow C\schemestop

\setchemfig{arrow angle=15,arrow coeff=1.5,
arrow style={red, thick}}
\schemestart A\arrow B\arrow C\schemestop

\setchemfig{arrow coeff=2.5,arrow style=dashed}
\schemestart A\arrow B\arrow C\schemestop

\setchemfig{arrow angle={},arrow coeff={},arrow style={}}
\schemestart A\arrow B\arrow C\schemestop/

To change one or all of these default values, one can use |\setchemfig| or the optional argument of |\schemestart|, so that the changes are limited to the current scheme.
\exemple*{Optional argument}/\setchemfig{arrow angle=5,arrow coeff=2.5,arrow style=blue}
\schemestart A\arrow B\arrow C\schemestop

\schemestart[arrow angle=0] A\arrow B\arrow C\schemestop

\schemestart[arrow angle=0,arrow coeff=1] A\arrow B\arrow C\schemestop

\schemestart[arrow angle=0,arrow coeff=1,arrow style=thick] A\arrow B\arrow C\schemestop

\schemestart[arrow angle=0,arrow coeff=1,arrow style=black] A\arrow B\arrow C\schemestop/

For the style, the rule is as follows: the style specified in the argument between square brackets is applied {\em after} the default style, without overwriting it! This is why only the color attribute “black” manages to override the default one, which is “blue”.

Finally, the command |\arrow| accepts an optional argument between square brackets of the form |[<angle>,<coeff>,<style>]| to change the features of the arrow concerned. For the style, as before, it is applied {\em after} the default style and any style specified in the optional argument of the command |\schemestart|, all without overwriting.
\exemple[50]{Arrow features}/\schemestart
  A\arrow[45]B\arrow[-20,2]C
\schemestop
\bigskip

\schemestart
  A\arrow[90,,thick]B\arrow[,2]C
  \arrow[-45,,dashed,red]D
\schemestop/

\sec Compound names
The automatic mechanism that names the compounds “c1”, “c2”, etc.\ can be overridden. For this, the command |\arrow| accepts an argument between parentheses which must immediately follow the command. This argument has the form |(n1--n2)|. It names “|n1|” the compound at the origin of the arrow and “|n2|” the one at its end. Any string of alphanumeric characters can be used. The numbering of the names “|c<n>|” continues internally, which means that if a compound has a name other than the default one, this does not change the default name of the following compounds.

The names are optional and the argument can just as well be |(n1--)| or |(--n2)|.

\exemple[50]{Compound names}/\setchemfig{scheme debug=true}
\schemestart
  A\arrow(aa--bb)B\arrow(--cc)C\arrow(--dd)D\arrow E
\schemestop
\bigskip

\schemestart
  A\arrow(aa--)B\arrow(bb--)C\arrow(cc--dd)D\arrow E
\schemestop/
As can be seen, both methods are equivalent, and a compound can therefore be named with the arrow preceding it or with the arrow following it. On the other hand, when a compound is surrounded by two arrows specifying its name, the first name is ignored and a warning is issued:
\exemple[50]{Redundant names}/\setchemfig{scheme debug=true}
\schemestart
  A\arrow(--foo)B\arrow(bar--)C
\schemestop/
Here, the compound “B” is named “foo” by the arrow arriving at it and “bar” by the one leaving it. \CF\ therefore issues the following warning, announcing that the name “foo” will be ignored:
\CFcode/Package chemfig Warning: two names for the same node, first name "foo" ignored/

\sec Anchors
As we have seen, arrows lie on the line connecting the centers of the bounding boxes of the compounds. An anchor other than the default one (which, in the \TIKZ\ sense, is called “|center|”) can be specified. For this, the argument between parentheses is used:
\CFcode/(n1.a1--n2.a2)/

where the anchor “|a1|” or “|a2|” can be: |north west|, |north|, |north east|, |west|, |center|, |east|, |mid west|, |mid|, |mid east|, |base west|, |base|, |base east|, |south west|, |south|, |south east|, |text|, or any angle.

Here is an example where the default alignment is not good because the two “A” are not vertically aligned. The debugging information has been made visible to show that the default “|center|” anchors are not suitable:
\exemple[50]{Alignment problems}/\setchemfig{scheme debug=true}
\schemestart
  \chemfig{A*5(-----)}
  \arrow
  \chemfig{A*5(---(-)--)}
\schemestop/
To obtain a correct alignment, the arrow will start/end either at the anchors “|base east|”/“|base west|”, or at the anchors “|mid east|”/“|mid west|”:
\exemple[50]{Alignment problems}/\setchemfig{scheme debug=true}
\schemestart
  \chemfig{A*5(-----)}
  \arrow(.base east--.base west)
  \chemfig{A*5(---(-)--)}
\schemestop
\bigskip

\schemestart
  \chemfig{A*5(-----)}
  \arrow(foo.mid east--bar.mid west)
  \chemfig{A*5(---(-)--)}
\schemestop/

One last anchor remains to be specified: that of the first compound with respect to the baseline of the text preceding it. It is the green dot on the left in the following scheme:
\exemple[50]{Initial anchor}/\setchemfig{scheme debug=true}
Preceding text:
\schemestart
  \chemfig{A*5(-----)}\arrow A
\schemestop/

The location of this anchor on the box containing the first compound is “|text|” by default. It can be set with the key \CFkey{init anchor}:
\exemple[50]{Setting the initial anchor}/\setchemfig{scheme debug=true}
Preceding text:
\schemestart[init anchor=south]
  \chemfig{A*5(-----)}\arrow A
\schemestop
\bigskip

Preceding text:
\schemestart[init anchor=north west]
  \chemfig{A*5(-----)}\arrow A
\schemestop
\bigskip

Preceding text:
\schemestart[init anchor=west]
  \chemfig{A*5(-----)}\arrow A
\schemestop/

\sec Compound style
Again through the argument between parentheses of the |\arrow| command, the style “|<s1>|” or “|<s2>|” of the bounding box of the departure or arrival compound can be specified with \TIKZ\ instructions. The complete syntax of the |\arrow| command is therefore as follows, where each specification is optional and can be omitted:
\CFcode/\arrow(n1.a1[<s1>]--n2.a2[<s2>]){<arrow type>}[<angle>,<coeff>,<arrow style>]/

Just as for names, if a style is specified for a compound by the arrow arriving at it and by the one leaving it, the first style is ignored with a warning.
\exemple[60]{Compound style}/\schemestart
  A
  \arrow([red]--[fill=blue,semitransparent,text opacity=1,
  inner sep=10pt,rounded corners=2mm])
  B
\schemestop
\bigskip

\schemestart
  A\arrow(--foo[yshift=5mm])B
\schemestop/

The key \CFkv{compound style}{tikz code} defines in general the style of the compounds displayed afterwards. Obviously an empty argument must be given for no style to be applied, which is the default.

Here, we will define a style in the form of boxes with rounded corners, whose background is semi-transparent:
\exemple[50]{Global styles}/\setchemfig{compound style={draw,line width=0.8pt,
semitransparent,text opacity=1,inner sep=8pt,
rounded corners=1mm}}
\schemestart
  A\arrow([fill=red]--[fill=blue])[90]
  B\arrow(--[fill=gray])
  C\arrow(--[fill=green])[-90]
  D\arrow(--[draw=none])[-180]
\schemestop/

\sec Branches
So far, only linear reaction schemes could be drawn. Branches can also be made, and this is where compound names become really important. In the argument between parentheses of the |\arrow| command, if a name is preceded by “|@|”, this means that the compound already exists. Several cases can arise:
\begitems
	* |(@n1--n2)|: the arrow is drawn from the existing compound “|n1|” and the scheme continues after this arrow, thus creating a branch;
	* |(@n1--@n2)|: the arrow is drawn between two existing compounds, whether they are already defined or defined later in the reaction scheme: this syntax can therefore be placed {\em anywhere} in the code of the reaction scheme;
	* |(n1--@n2)|: this syntax is not allowed.
\enditems

Here is an example where 3 branches are created, one starting from “B”, another from “D” and the last from “X”. At the end, an arrow is drawn between 2 existing compounds, “XX” and “D”:
\exemple[50]{Branches}/\schemestart
  A\arrow(aa--bb)B\arrow(--cc)C\arrow D
  \arrow(@bb--xx1)[-90]X\arrow[-90]Y% 1st branch
  \arrow(@c4--)[-90]Z\arrow W% 2nd branch
  \arrow(@xx1--xx2)[-45]XX% 3rd branch
  \arrow(@xx2--@c4)% arrow from XX to D
\schemestop/

One might want “Y” and “XX” to be on the same horizontal line. For this, we draw an invisible horizontal arrow from “Y” to “XX” and end the scheme with an arrow between the two existing compounds “XX” and “D”:
\exemple[50]{Branches}/\schemestart
  A\arrow(aa--bb)B\arrow(--cc)C\arrow D
  \arrow(@bb--xx1)[-90]X\arrow[-90]Y\arrow(--xx2){0}XX
  \arrow(@c4--)[-90]Z\arrow W
  \arrow(@xx1--@xx2)% arrow from X to XX
  \arrow(@xx2--@c4)% arrow from XX to D
\schemestop/

\sec[subscheme] Subscheme
Part of a reaction scheme can be placed in a single bounding box, considered by \CF\ as a compound. The command |\subscheme|, whose mandatory argument contains the subscheme between braces, groups a subscheme as a whole, and when |\subscheme| comes after an arrow, the command wraps this subscheme in a compound named “|c<n+1>|”:
\exemple[50]{Subscheme}/\setchemfig{scheme debug=true}
\schemestart
  A\arrow
  \subscheme{B\arrow[-90,2]C}
  \arrow
  D
\schemestop/

Although it is not clear because the names overlap, the box containing the subscheme is named “|c2|” and numbering continues inside the subscheme: “|c3|” for B, “|c4|” for C. Since the first compound of the subscheme is “B”, the baseline of the subscheme is that of “B”. This can be highlighted by specifying the anchors:
\exemple[50]{Subscheme}/\setchemfig{scheme debug=true}
\schemestart
  A\arrow(--.mid west)
  \subscheme{B\arrow[-90,2]C}
  \arrow
  D
\schemestop/

Note that the command |\subscheme{<scheme>}| is nothing but a convenient shortcut for
\CFcode-\schemestart<scheme>\schemestop-

Consequently, |\subscheme| accepts the same optional arguments as |\schemestart|.

\CF\ provides the pair of \label[chemleft]\wlabel{commands}commands |\chemleft| and |\chemright|, which place extensible delimiters on either side of some material. These commands must be followed by delimiters, just as one would put after the \TeX{} primitives |\left| and |\right|:
\CFcode/\chemleft<char1><material>\chemright<char2>/

where |<char1>| and |<char2>| are “|(|” and “|)|” or “|[|” and “|]|” or any other extensible delimiter accepted by the commands |\left| and |\right|.
\exemple{The macros \string\chemleft\ and \string\chemright}/\chemleft(\chemfig{A-[1]B}\chemright)

\chemleft\{\chemfig{A-[1,1.25]B-[6,1.25]C}\chemright\}

\chemleft[\chemfig{H-[1]O-[7]H}\chemright]/
Here is the code of the reaction scheme seen previously, using |\chemleft| and |\chemright|:
\exemple{Reaction scheme with \code{\\chemleft} and \code{\\chemright}}/\schemestart
  A\arrow
  \chemleft[\subscheme{B\arrow[-90,2]C}\chemright]
  \arrow
  D
\schemestop/
In the same vein, the \label[chemup]\wlabel{macros}macros |\chemup| and |\chemdown| work the same way except that the extensible delimiters are positioned above and below the material:
\CFcode/\chemup<char1><material>\chemdown<char2>/

Here is an example:
\exemple{The macros \code{\\chemup} and \code{\\chemdown}}/\schemestart[arrow angle=-90]
X\arrow
\chemup\{\chemfig{A-[1]B-[7]C}\chemdown\}
\arrow Y
\schemestop
\qquad
\schemestart[arrow angle=-90]
X\arrow
\chemup[\chemfig{A-[1]B-[7]C}\chemdown]
\arrow Y
\schemestop/

With compound styles, it is also possible to delimit any compound (and therefore a subscheme) with extensible delimiters (parentheses, square brackets, braces), after loading the \TIKZ\ library “|matrix|” by putting in the preamble of the document:
\CFcode-\usetikzlibrary{matrix}-

Since the commands |\chemleft|, |\chemright|, |\chemup| and |\chemdown| are available, the \CF\ package does {\em not} perform this loading; it is up to the user to do so if they want access to these delimiters.

Here is the previous subscheme delimited by square brackets:
\exemple[50]{The delimiters of the “matrix” library}/%\usetikzlibrary{matrix}
\schemestart
  A\arrow(--[left delimiter={[}, right delimiter={]}])
  \subscheme{B\arrow[-90,2]C}
  \arrow
  D
\schemestop/

Since the delimiters are drawn outside the bounding box, it is advisable here to shorten the arrows arriving at and leaving these delimiters a little:
\exemple[50]{Subscheme}/%\usetikzlibrary{matrix}
\schemestart
  A\arrow(--[left delimiter={[},
  right delimiter={]}])[,,shorten >=6pt]
  \subscheme{B\arrow[-90,2]C}
  \arrow[,,shorten <=6pt]
  D
\schemestop/

Subschemes must be used wisely and can sometimes give undesired results. Here is an example where a subscheme is used to align 3 compounds horizontally:
\exemple[50]{Subscheme}/\setchemfig{scheme debug=true}
\schemestart
  A
  \arrow{0}[-90]
  \subscheme{%
    longword\arrow{}
    mid\arrow{}
    end}
  \arrow(xx--yy){}E
  \arrow(@c1--@c3){}
  \arrow(@c1--@c5){}
  \arrow(@c1--@c4){}
\schemestop/
One can see that the center of the subscheme is on the same vertical line as the center of the compound “A”, since an invisible arrow with an angle of $-90°$ was drawn. On the other hand, the arrow between the two existing compounds “A” and “mid” is {\em not} vertical, because “mid” is not under the center of the subscheme, since “longword” is wider than “end”. To make this arrow vertical, a subscheme cannot help, except by specifying an angle found by trial and error for the arrival anchor of the invisible arrow.

It is much simpler to proceed without a subscheme and to use a branch: draw a {\em visible} arrow between “A” and “mid”, then start from “mid” to draw horizontal arrows on either side, creating a branch for the arrows to the right.
\exemple[50]{Subscheme}/\setchemfig{scheme debug=true}
\schemestart
  A
  \arrow(--mid){->}[-90]
  mid
  \arrow{<-}[180]
  longword
  \arrow(@mid--end){}
  end
  \arrow{}
  E
  \arrow(@c1--@c3){}
  \arrow(@c1--@end){}
\schemestop/

\sec[fleche.arg.optionnel] Optional arguments of arrows
Inside the argument between braces of the |\arrow| command, the name of the arrow can be followed by optional arguments placed between square brackets. Here are these optional arguments and their meaning for the arrows defined by \CF:\ttanglefalse
\begitems
	* the arrows “|->|”, “|<-|”, “|<->|”, “|<=>|”, “|<<->|”, “|<->>|”, “|-/>|” have three optional arguments:
	\begitems\style x
		* the first contains the “label” placed above the arrow;
		* the second contains the “label” placed below the arrow. These two labels are oriented at the same angle as the arrow. The perpendicular shift between the arrow and the anchor of the labels can be set with the key \CFkv{arrow label sep}{dim}, which is 3pt by default. The labels contained in the two optional arguments {\em are not} typeset in math mode;
		* the third is a dimension corresponding to the shift to be applied to the arrow in the direction perpendicular to it: this dimension is positive to shift the arrow (and its labels, if any) upward and negative to shift it downward.
	\enditems
	* the arrow “|-U>|” has 5 optional arguments:
	\begitems\style x
		* the first three are identical to those of the other arrow types;
		* the fourth is the coefficient (0.333 by default) multiplying the length of the arrow to obtain the radius of the arc;
		* the fifth is the half-angle from the center of the drawn arc; it is 60 degrees by default.
	\enditems
	* the invisible arrow “|0|” accepts 2 optional arguments, of the same type as the first two seen above.
\enditems\ttangletrue

\exemple[50]{Optional arguments of arrows}/\setchemfig{scheme debug=false}
\schemestart A\arrow{->[above][below]}B \schemestop
\qquad
\schemestart A\arrow{->[above][below][4pt]}B \schemestop
\qquad
\schemestart A\arrow{->[above][below][-4pt]}B \schemestop
\medskip

\schemestart A\arrow{<=>[above][below]}[30,1.5]B \schemestop
\medskip

\schemestart[arrow angle=-20]
  A\arrow{->}B\arrow{->[][][3pt]}C\arrow{->[][][-3pt]}D
\schemestop/

A problem arises when arrows are vertical:
\exemple[50]{Vertical arrows}/\schemestart
  A\arrow{->[above][below]}[-90]B
\schemestop/

For readability, it would be preferable for the labels placed above and below to be horizontal. The angle at which the labels are displayed can be chosen, the default value being the angle of the arrow. To specify another angle, simply put |*{<angle>}| at the beginning of the optional arguments:
\exemple[55]{Choosing angles}/\setchemfig{scheme debug=true}
\schemestart A\arrow{->[*{0}above][*{0}below]}[90]B\schemestop
\qquad
\schemestart A\arrow{->[*{0}above][*{0}below]}[45]B\schemestop
\qquad
\schemestart A\arrow{->[*{0}above][*{0}below]}[-45]B\schemestop
\qquad
\schemestart A\arrow{->[*{0}above][*{0}below]}[-90]B\schemestop/

The default anchor to which each label is attached sometimes produces undesirable displays:
\exemple[50]{Anchors}/\setchemfig{scheme debug=true}
\schemestart
  A\arrow{->[*{0}text above][*{0}text below]}[45,2]B
\schemestop/

The attachment anchor can also be specified to override the one chosen by default by \CF. Simply use the following syntax: |*{<angle>.<anchor>}|.
\exemple[50]{Anchors}/\setchemfig{scheme debug=true}
\schemestart
  A\arrow{->[*{0.0}text above][*{0.180}text below]}[45,2]B
\schemestop
\qquad
\schemestart
  A\arrow{->[*{0.south east}text above]%
    [*{0.north west}text below]}[45,2]B
\schemestop/

The special case to consider is the arrow “|-UZ|”. If either of the two labels contained in the first two optional arguments is present, the corresponding arc is drawn:
\exemple[50]{The arrow \texttt{-U>}}/\schemestart A\arrow{-U>[123][456]}B\schemestop
\qquad
\schemestart A\arrow{-U>[123]}[30]B\schemestop
\qquad
\schemestart A\arrow{-U>[][456]}[-30]B\schemestop/

The fourth and fifth optional arguments change the dimensions of the arc. They represent respectively the coefficient multiplying the length of the arrow to obtain the radius, and the angle corresponding to the half arc (only the absolute value of the angle is taken into account):
\exemple[50]{The arrow \texttt{-U>}}/\schemestart A\arrow{-U>[123][456][][0.25]}B\schemestop
\qquad
\schemestart A\arrow{-U>[123][456][][][90]}B\schemestop
\qquad
\schemestart A\arrow{-U>[123][456][][1][45]}B\schemestop/
With a negative radius and angle, the arc is located below the arrow:
\exemple[50]{The arrow \texttt{-U>}}/\schemestart
  A\arrow{-U>[123][456][][-0.333][-60]}B
\schemestop/

The first two arguments have the same features regarding display angles and configurable anchors as those of the other arrows:
\exemple[50]{The arrow \code{-U>}}/\schemestart
  A\arrow{-U>[123][456]}[-90]B
\schemestop
\qquad
\schemestart
  A\arrow{-U>[*{0.180}123][*{0.180}456]}[-90]B
\schemestop/

\sec[definearrow] Creating your own arrows
This section, rather technical and requiring some knowledge of \TIKZ, will only interest advanced users who need to define their own arrows.

The command |\definearrow| allows custom arrows to be built. The syntax of this command is as follows:
\CFcode-\definearrow{<number>}{<arrow name>}{<code>}-

where |<number>| is the number of optional arguments, referred to in the |<code>| with the usual syntax |#1|, |#2|, etc. Default values cannot be defined for these optional arguments, and if they are absent when the user uses the macro |\arrow|, they will be empty.

Before going further, let us examine the macros available internally when arrows are drawn. Since these macros have the character “\code{_}” in their name, they can only be accessed between the commands |\catcode`\_=11| and |\catcode`\_=8|.
\begitems
	* |\CF_arrowstartname| and |\CF_arrowendname| contain the names of the compounds (which are nodes for \TIKZ) between which the arrow must be drawn;
	* |\CF_arrowstartnode| and |\CF_arrowendnode| contain the names of the nodes where the ends of the arrows will be placed. These names are followed, if not empty, by the anchors specified by the user in the argument between parentheses of the |\arrow| command;
	* |\CF_arrowcurrentstyle| and |\CF_arrowcurrentangle| contain the style and the angle of the arrow to be drawn;
	* |\CF_arrowshiftnodes<dim>| shifts the nodes “|\CF_arrowstartnode|” and “|\CF_arrowendnode|” by the dimension contained in its argument, in the direction perpendicular to the arrow;
	* |\CF_arrowdisplaylabel{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}| is the most complex and places the labels with the following arguments:
	\begitems\style x
		* |#1| and |#5| are the labels to write;
		* |#2| and |#6| are real numbers between 0 and 1 specifying where on the arrow these labels must be written, 0 being the beginning and 1 the end, all this assuming that the arrow is {\em straight};
		* |#3| and |#7| are the characters “+” or “-”, “+” displaying the label above and “-” displaying it below;
		* |#4| and |#8| are the names of the nodes corresponding to the beginning and the end of the arrow.
	\enditems
	* the arrow tips used are based on the model “|CF|” for a full arrow, and with the option “harpoon” for the upper half arrow.
\enditems

\secc A first arrow
As an example, let us build an arrow with a disk in its middle, which we will call “|-.Z|”. Let us decide that it will accept 4 optional arguments. As for the arrows already defined, the \eme1 and \eme2 will be the labels to put above and below; the \eme3 will be the shift of the arrow perpendicular to its direction. Finally, the \eme4 argument will be the size of the dot, which will be 2pt if the \eme4 argument is absent.

We will first write |\definearrow{4}{-.Z}| to declare that the arrow will have 4 optional arguments and will be called “|-.Z|”. First of all, the positions of the nodes between which the arrow must be drawn must be modified to take into account the shift contained in the \eme3 argument. This is done by the macro |\CF_arrowshiftnodes|, so it suffices to start the code of the arrow with: |\CF_arrowshiftnodes{#3}|. Then the arrow itself must be drawn, placing a node named “|mid@point|” in the middle of the segment along the way, and then a circle centered on this last node is drawn. All this is done by the following \TIKZ\ code:
\CFcode/\edef\pt_radius{\ifx\empty#4\empty 2pt\else #4\fi}% radius of the dot
\expandafter\draw\expandafter[\CF_arrowcurrentstyle,-CF]
    (\CF_arrowstartnode)--(\CF_arrowendnode)coordinate[midway](mid@point);
\filldraw(mid@point)circle(\pt_radius);%/

All that remains is to place the labels, if they exist, with the following line:
\CFcode/\CF_arrowdisplaylabel{#1}{0.5}{+}{\CF_arrowstartnode}{#2}{0.5}{-}{\CF_arrowendnode}/

Here is our finished arrow:
\exemple*{Arrow “\code{-.>}”}/\catcode`\_11
\definearrow4{-.>}{%
  \edef\pt_radius{\ifx\empty#4\empty 2pt\else #4\fi}% radius of the dot
  \CF_arrowshiftnodes{#3}%
  \expandafter\draw\expandafter[\CF_arrowcurrentstyle,-CF](\CF_arrowstartnode)--(\CF_arrowendnode)
    coordinate[midway](mid@point);
  \filldraw(mid@point)circle(\pt_radius);%
  \CF_arrowdisplaylabel{#1}{0.5}{+}{\CF_arrowstartnode}{#2}{0.5}{-}{\CF_arrowendnode}
  }
\catcode`\_8
\schemestart
A \arrow{-.>} B \arrow{-.>[above][below][][1pt]} C \arrow{-.>[][below]}[30] D \arrow{-.>[above][][5pt][1.5pt]} E
\schemestop/

\secc A curved arrow
Why not now create a curved arrow? To keep things simple, let us say that it will have only one optional argument containing the \TIKZ\ code defining the control point(s), and if this argument is empty, an arrow of type “|-CF|” will be drawn.

If the argument |#1| is not empty, what interests us is not |\CF_arrowstartnode| and |\CF_arrowendnode|, which contain the names of the nodes where the ends of the arrows will be placed, because the location of these nodes is already determined by anchors computed for {\em straight} arrows! Instead we will take |\CF_arrowstartname| and |\CF_arrowendname|, which contain the names of the compounds (which are nodes for \TIKZ) between which the arrow must be drawn. Here is the \TIKZ\ code that will draw the curved line between these two compounds:
\CFcode/\draw[shorten <=\CF_arrowoffset,shorten >=\CF_arrowoffset,\CF_arrowcurrentstyle,-CF,
    (\CF_arrowstartname).. controls #1 ..(\CF_arrowendname);/

\TIKZ\ code must be added to shorten the arrow by the value |\CF_arrowoffset| defined by the key \CFkey{arrow offset}, since we do not start from the nodes corresponding to straight arrows |\CF_arrowstartnode| and |\CF_arrowendnode|. The following code must therefore be added at the beginning of |\CF_arrowcurrentstyle|:
\CFcode/shorten <=\CF_arrowoffset, shorten >=\CF_arrowoffset/

this is what the two lines following the |\else| do.

Here is our arrow:
\exemple*{Curved arrow}/\catcode`\_11
\definearrow1{s>}{%
\ifx\empty#1\empty
  \expandafter\draw\expandafter[\CF_arrowcurrentstyle,-CF](\CF_arrowstartnode)--(\CF_arrowendnode);%
\else
  \def\curvedarrow_style{shorten <=\CF_arrowoffset,shorten >=\CF_arrowoffset,}%
  \CF_eaddtomacro\curvedarrow_style\CF_arrowcurrentstyle
  \expandafter\draw\expandafter[\curvedarrow_style,-CF](\CF_arrowstartname)..controls#1..(\CF_arrowendname);
\fi
}
\catcode`\_8
\schemestart
A\arrow{s>}
B\arrow{s>[+(0.5cm,0.5cm)]}
C\arrow{s>[+(45:1cm)]}
D\arrow(.60--.120){s>[+(60:1cm) and +(-120:1cm)]}
E\arrow{s>[+(45:1) and +(-135:1)]}
F\arrow{s>[+(-30:1) and +(150:1)]}[,1.5]
G\arrow(.90--.90){s>[+(60:1)and+(120:1)]}[,2]
H
\schemestop

\schemestart
A\arrow(.90--.180){s>[+(90:0.8) and +(180:0.8)]}[45]B
\arrow(.0--.90){s>[+(0:0.8) and +(90:0.8)]}[-45]C
\arrow(.-90--.0){s>[+(-90:0.8) and +(0:0.8)]}[-135]D
\arrow(.180--.-90){s>[+(180:0.8) and +(-90:0.8)]}[135]
\schemestop/

\sec The \code{\\merge} command
The command |\merge| draws arrows that start from several existing compounds and then join to continue the reaction scheme.

Immediately after the command |\merge|, the direction of progression must be specified. For this, one of the 4 direction characters is used: “|Z|” (the default if the character is absent), “|Y|”, “|^|” and “|v|”.

The syntax then becomes:
\CFcode/\merge{dir}(n1.a1)(n2.a2)(...)(ni.ai)--(n.a[s])/

where the names “|ni|” before the double dash are those of already existing compounds to be joined. The anchor “|ai|” from which the arrow must start can also be specified if the default anchor is not suitable. As for the |\arrow| command, “|n.a[s]|” contains the name, the anchor and the style of the next compound.

\exemple[50]{The \string\merge\ command}/\schemestart
ABC\arrow[30]EFGHIJ\arrow[45]KLM\arrow[30]NO
\merge>(c1)(c2)(c3)--()next 1
\arrow next 2
\schemestop
\bigskip

\schemestart
Foooo\arrow(foo--bar){<=>}Bar\arrow(--baz){<=>}Bz
\merge^(foo)(bar)(baz)--()next
\schemestop
\qquad
\setchemfig{scheme debug=true}
\schemestart
A\arrow{<->}[90]B
\merge<(c1.120)(c2)--(foobar.45[circle,blue])CCC
\schemestop/

As for the geometry of the |\merge| arrow, it consists of $n$ lines leaving each compound and going up to the junction line perpendicular to them: the default length of the shortest of these lines is half the spacing between compounds defined with |\setcompoundsep|. The arrow drawn from the junction line to the next compound also has this default length, and it starts from the middle of the junction line. These 3 geometric features can be changed with the optional argument that comes after the name of the next compound:
\CFcode/\merge{dir}(n1.a1)(n2.a2)(...)(ni.ai)--(n.a[s])[c1,c2,c,<style>]/

where:
\begitems
	* the length of the shortest line between the compounds to be joined and the junction line is obtained by multiplying the spacing between compounds defined with |\setcompoundsep| by the coefficient |c1|, which is 0.5 by default;
	* the length of the arrow between the junction line and the next compound is obtained by multiplying the spacing between compounds by the coefficient |c2|, which is 0.5 by default;
	* the place where the arrow leaves the junction line is determined by the coefficient |c|, knowing that if it is 0, the arrow starts from the left of the junction line (or from the top if the direction is |v| or |^|);
	* the style of the arrow drawn with |\merge| is defined by the last argument |<style>|.
\enditems

\exemple*{Geometric parameters of \string\merge}/\schemestart A\arrow{<=>}[90]B\merge(c1)(c2)--()C\schemestop\qquad
\schemestart A\arrow{<=>}[90]B\merge(c1)(c2)--()[1]C\schemestop\qquad
\schemestart A\arrow{<=>}[90]B\merge(c1)(c2)--()[,1]C\schemestop\qquad
\schemestart A\arrow{<=>}[90]B\merge(c1)(c2)--()[,,0.2]C\schemestop\qquad
\schemestart A\arrow{<=>}[90]B\merge(c1)(c2)--()[,,0.9,red,thick]C\schemestop/

\exemple*{Geometric parameters of \string\merge}/\schemestart A\arrow{<=>}B\merge^(c1)(c2)--()C\schemestop\qquad
\schemestart A\arrow{<=>}B\merge^(c1)(c2)--()[1]C\schemestop\qquad
\schemestart A\arrow{<=>}B\merge^(c1)(c2)--()[,1]C\schemestop\qquad
\schemestart A\arrow{<=>}B\merge^(c1)(c2)--()[,,0.2]C\schemestop\qquad
\schemestart A\arrow{<=>}B\merge^(c1)(c2)--()[,,0.9,red,thick]C\schemestop/

Finally, labels can be written above or below the arrow created by the |\merge| command. For this, the character defining the direction accepts two optional arguments between square brackets, the first containing the label put above and the second the one put below the arrow. The complete syntax of the |\merge| command is therefore:
\CFcode/\merge{dir}[labelup][labeldown](n1.a1)(n2.a2)(...)(ni.ai)--(n.a[s])[c1,c2,c,style]/

All the features already presented for arrow labels are possible here, namely choosing the rotation angle and the anchor with the syntax |*{angle.anchor}| placed just before the content of the label.

\exemple*{Labels of the \string\merge\ command}/\schemestart
ABC\arrow{<=>}[90]DEF\merge>[above][below](c1)(c2)--()[0.25,1,0.75]GHIJ
\schemestop\qquad
\schemestart
ABC\arrow{<=>}[90]DEF\merge>[*{45.south west}above][*{45.north east}below](c1)(c2)--()[0.25,1,0.75]GHIJ
\schemestop\qquad
\schemestart
ABC\arrow{<=>}[90]DEF\merge>[*{90}above][*{90}below](c1)(c2)--()[0.25,1,0.75]GHIJ
\schemestop
\bigskip

\schemestart
ABC\arrow{<=>}DEF\merge v[above][below](c1)(c2)--()[0.25,1,0.75]GHIJ
\schemestop\qquad
\schemestart
ABC\arrow{<=>}DEF\merge v[*{45.north west}above][*{45.south east}below](c1)(c2)--()[0.25,1,0.75]GHIJ
\schemestop\qquad
\schemestart
ABC\arrow{<=>}DEF\merge v[*{0}above][*{0}below](c1)(c2)--()[0.25,1,0.75]GHIJ
\schemestop/

\sec The + sign
Between the commands |\schemestart| and |\schemestop|, the macro “|\+|” is available, which displays a ${}+{}$ sign. It accepts an optional argument {\em between braces} containing 3 dimensions in this form |{<dim1>,<dim2>,<dim3>}| where:
\begitems
	* |<dim1>| and |<dim2>| are the dimensions inserted before and after the ${}+{}$ sign;
	* |<dim3>| is the vertical shift to be applied to the sign.
\enditems

These dimensions can also be specified for all ${}+{}$ signs with the keys \CFkv{+ sep left}{dim}, \CFkv{+ sep right}{dim} and \CFkv{+ vshift}{dim}. The default values of these dimensions are 0.5em for the first two and 0pt for the third.

\exemple[50]{The \string\+\ command}/\schemestart
A\+B\+{2em,,5pt}C\+{0pt,0pt,-5pt}D\arrow E\+F
\schemestop

\setchemfig{+ sep left=1em,+ sep right=1em,+ vshift=0pt}
\schemestart
A\+B\+{2em,,5pt}C\+{0pt,0pt,-5pt}D\arrow E\+F
\schemestop/

As can be seen in the example below, it must be understood that the ${}+{}$ sign inserted by the |\+| command is part of the compound:
\exemple[50]{Compounds and \string\+}/\setchemfig{scheme debug=true}
\schemestart A\+ B\+{,,5pt}C\arrow D\+ E\schemestop/

It therefore becomes difficult to start an arrow exactly under the letter “A”, since this letter is not a single compound in the eyes of \CF. In this case, the |\subscheme| command can be used to wrap the letter “A” in a single compound, or even the sign itself, so that it can be referred to later with the name assigned to it:
\exemple[50]{Subcompound and \string\+}/\setchemfig{scheme debug=true}
\schemestart
\subscheme{A}\+ B\arrow C
\arrow(@c2--)[-90]E
\schemestop
\medskip

\schemestart
A\subscheme{\+}BCDEF \arrow G
\arrow(@c2--)[-90]H
\schemestop/%

The alignment of the “+” sign with the preceding or following molecules may sometimes be a problem. Here is an example:
\exemple[70]{Alignment of the + sign}/\setchemfig{scheme debug=true}
\schemestart
  \chemfig{C(<[:40])(<[:160])=[6]C(<[:-130])<[:-20]}
  \+
  \chemfig{\charge{90=\|,180=\|,270=\|}{Br}-\charge{0=\|,90=\|,-90=\|}{Br}}
\schemestop/
What happens is that the “+” sign is on the same baseline as the preceding compound, and this baseline is that of the upper atom “C”. One could of course shift the “+” sign, but this would not change the vertical position of “\kern0.3333em\chemfig{\charge{90=\|,180=\|,270=\|}{Br}-\charge{0=\|,90=\|,-90=\|}{Br}}\kern0.3333em”. In fact, the “+” sign does not stop the reading of a compound for \CF, as can be seen in the example above where everything is included in the compound “c1”. We will therefore have to stop the compound after the first molecule with an |\arrow{0}[,0]|, which produces an invisible arrow of zero length. To center everything vertically, we will also specify that the anchor of the first compound must be “|west|” (or “|180|”, which is a synonym) with the optional argument of the |\schemestart| command:
\exemple[70]{Alignment of the + sign}/\setchemfig{scheme debug=true}
\schemestart[init anchor=west]
  \chemfig{C(<[:40])(<[:160])=[6]C(<[:-130])<[:-20]}
  \arrow{0}[,0]\+
  \chemfig{\charge{90=\|,180=\|,270=\|}{Br}-\charge{0=\|,90=\|,-90=\|}{Br}}
\schemestop/

In this way, the first compound “c1” is the first molecule and the second compound is the rest, that is, the “+” sign and the second molecule. One could have used the anchors or styles via the |\arrow| command to place the second compound elsewhere. Here, for example, the second compound is shifted 10pt downward in the first case, and in the second case the anchor “south east” of the first compound is made to coincide with the anchor “south west” of the second:
\exemple[70]{Alignment of the + sign}/\setchemfig{scheme debug=true}
\schemestart[init anchor=west]
  \chemfig{C(<[:40])(<[:160])=[6]C(<[:-130])<[:-20]}
  \arrow(--[yshift=-10pt]){0}[,0]\+
  \chemfig{\charge{90=\|,180=\|,270=\|}{Br}-\charge{0=\|,90=\|,-90=\|}{Br}}
\schemestop
\medskip

\schemestart[init anchor=west]
  \chemfig{C(<[:40])(<[:160])=[6]C(<[:-130])<[:-20]}
  \arrow(.south east--.south west){0}[,0]\+
  \chemfig{\charge{90=\|,180=\|,270=\|}{Br}-\charge{0=\|,90=\|,-90=\|}{Br}}
\schemestop/

\chap[hreac] Horizontal reactions
\sec Syntax
A horizontal reaction is placed in an environment with the syntax:
\CFcode/\hreac <reaction>\endhreac/

The tokens \framett+ \framett> \framett\> \framett\^ are reserved and have a meaning in the |<reaction>|:
\begitems
	* a |<compound>| extends up to the next occurrence of “|+|”, “|Z|” or the end of the environment;
	* in the |<reaction>|, any code belonging to a |<compound>| that is between braces is not examined and is left as is between braces;
	* spaces are ignored except when they are between braces (see previous point) and in the optional or mandatory arguments of the macros |\chemfig| and |\polymerdelim|;
	* a |<compound>| consists of any code except the reserved tokens seen above, unless they are between braces;
	* the sign “|+|” displays the sign $+$ and constitutes a |<compound>| on its own;
	* the sign “|Z|” displays an arrow and constitutes a |<compound>| on its own.
\enditems

\exemple[60]{Example 1}/
\hreac
	\chemfig{*6(-=-=-=)}
	+
	\chemfig{X=[1]Y}
	+
	Z > X + Y
\endhreac/

\sec Placement of compounds
All compounds are numbered |c<n>| (where |<n>| is an integer) and are placed in boxes. The centers of all boxes are placed on the same horizontal line, which is drawn as red dots when the option |hreac debug| is enabled:
\exemple[60]{Vertical alignment of compounds}/
\hreac[hreac debug]
	\chemfig{*6(-=-=-=)}
	+
	\chemfig{X=[1]Y}
	+
	Z > X + Y
\endhreac/

When |\Z{<dimension>}| is encountered within a |<compound>| (but preferably at its beginning), the compound is shifted \label[hshift]\wlabel{horizontally}horizontally by |<dimension>|.
\exemple[60]{Horizontal adjustment of compounds}/
\hreac[hreac debug]
	\chemfig{*6(-=-=-=)}
	+
	\>{-5pt}\chemfig{X=[1]Y}
	+
	\>{5pt}Z > X + Y
\endhreac/

When |\^{<dimension>}| is encountered at the beginning of a |<compound>|, this compound (and only this one) is shifted \label[vshift]\wlabel{vertically}vertically by |{<dimension>}|. In the starred version |\^*{<dimension>}|, the compound and all following ones are affected.
\exemple[60]{Vertical adjustment of compounds}/
\hreac[hreac debug]
	\chemfig{*6(-=-=-=)}
	+
	\^{10pt}\chemfig{X=[1]Y}
	+
	Z > X + Y
\endhreac\medbreak
\hreac[hreac debug]
	\chemfig{*6(-=-=-=)}
	+
	\^*{10pt}\chemfig{X=[1]Y}
	+
	Z > X + Y
\endhreac/

\sec[name] Compound names
To display the |<name>| of a |<compound>| below it, either of these syntaxes can be used:
\begitems
	* |\chemname[<dimension>]{<compound>}{<name>}|;
	* |<compound>\name[<dimension>]{<name>}| or |\name[<dimension>]{<name>}<compound>|, the order of appearance being irrelevant.
\enditems

The optional |<dimension>| is the minimum distance between the box of the |<compound>| and that of the |<name>|. When it is omitted, its default value is the value of the key \CFkey{name sep}.

All names are numbered |name<n>| where |<n>| is the integer corresponding to the |<compound>|. They are placed in boxes whose width is that of the |<compound>|. The upper boundaries of these boxes are on the same horizontal line, whose vertical position is computed to be below the compound with the greatest depth.
\exemple[60]{Compound names}/
\hreac[hreac debug]
	\chemfig{*6(-=-=-=)}\name{ring}
	+
	\chemfig{X=[1]Y}\name{name}
	+
	Z > X + Y
\endhreac/

If the width of a |<name>| exceeds that of its |<compound>|, no adjustment of the width of the |<compound>| is made and the |<name>| will overflow the boundaries of the box containing it. It is up to the user to use the macro |\\| to display the |<name>| on several lines.
\exemple[60]{Compound names}/
\hreac[hreac debug]
	\chemfig{*6(-=-=-=)}\name{ring}
	+
	\chemfig{X=[1]Y}\name{name much too long}
	+
	Z > X + Y
\endhreac\medbreak
\hreac[hreac debug]
	\chemfig{*6(-=-=-=)}\name{ring} +
	\chemfig{X=[1]Y}\name{name\\too\\long} +
	Z > X + Y
\endhreac/

\sec[harrow] Arrow types
If the token “|Z|” is immediately followed by a text between braces, this optional text specifies the arrow type. Its default value is the value of the key \CFkey{arrow head}, which contains \CFval{-CF} by default.

The complete syntax of the token |Z| is therefore:\par
\CFcode|Z{<arrow type>}[<upper label>][<lower label>]|

Using this optional parameter between braces gives access to these other arrow types, already described in the part “Reaction schemes”: \ttanglefalse“|->|”, “|<-|”, “|<->|”, “|<=>|”, “|<<->|” and “|<->>|”\ttangletrue.
\exemple[60]{The 6 arrow types}/
\hreac A > B \endhreac\par% same as >{->}
\hreac A >{<-} B \endhreac\par
\hreac A >{<->} B \endhreac\par
\hreac A >{<=>} B \endhreac\par
\hreac A >{<<->} B \endhreac\par
\hreac A >{<->>} B \endhreac/

\sec Arrow labels
If the token “|Z|” is immediately followed by an optional argument |[<label>]|, this |<label>| is placed above the arrow. If another optional argument |[<label>]| is present, the other |<label>| is placed below the arrow.
\exemple[60]{Arrow labels}/
\hreac[hreac debug]
	A >[up] B >[][down] C >[up][down] D
\endhreac/

The default width of an arrow is |3em|, but if a label exceeds this dimension, the arrow is lengthened.
\exemple[60]{Arrow extension}/
\hreac[hreac debug]
	A >[up][down] B
\endhreac
\qquad
\hreac[hreac debug]
	A >[very long label][down] B
\endhreac/

As for compound names, |\\| can be used to typeset a |<label>| on several lines.
\exemple[60]{Label on several lines}/
\hreac[hreac debug]
	A >[very\\long\\label][down] B
\endhreac/

The box containing the lower label has no influence on the vertical position of the compound names.
\exemple[60]{Independence of labels and names}/
\hreac[hreac debug]
	\chemfig{*6(-=-=-=)}\name{ring}
	+
	\chemfig{X=[1]Y}\name{name}
	+
	Z >[][label\\under\\the arrow\\very\\deep] X
\endhreac/

\chap List of commands
The macros created by \CF\ are:

\begingroup
	\parskip0pt
	\def\wcolA{6.5cm}
	\def\wcolB{9.5cm}
	\def\colsep{0.5cm}
	\def\vsep{7.5pt}
	\def\_{\par\hfill\hbox to\dimexpr\wcolA+\colsep+\wcolB{\hrulefill}\hfill\null\par\nointerlineskip\kern\vsep}
	\def\1{\quitvmode\hfill\hbox\bgroup\vtop\bgroup\hsize\wcolA \parindent1cm\noindent\ignorespaces}
	\def\2{\unskip\par\egroup\egroup\kern\colsep \hbox\bgroup\vtop\bgroup\hsize\wcolB \ignorespaces}
	\def\3{\unskip\par\egroup\egroup\hfill\null\par\nointerlineskip\kern\vsep}
	\_
	\1Macros\2Description\3
	\_
	\1|\chemfig[<parameters>]{<code>}| \2 draws the molecule whose drawing is described by the |<code>|\3
	\1|\setchemfig{<parameters>}| \2 sets the parameters with the syntax \CFkv{key}{value}, \cfpage{setchemfig}\3
	\1|\resetchemfig| \2 Restores the parameters to their default values\3
	\1|\printatom| \2 this macro displays the atoms in molecules, \cfpage{printatom}\3
	\1|\hflipnext| \2 the next molecule will be flipped horizontally, \cfpage{hflipnext}\3
	\1|\vflipnext| \2 the next molecule will be flipped vertically, \cfpage{hflipnext}\3
	\1|\definesubmol|\par
		|{<name>}<n>[<code1>]{<code2>}| \2 creates an alias |<name>| that can be placed in the code of molecules to be drawn and is replaced by |<code1>| or |<code2>| depending on the slope of the last bond, \cfpage{definesubmol}\3
	\1|\chemskipalign| \2 Ignores the current group of atoms for the vertical alignment mechanism, \cfpage{chemskipalign}\3
	\1|\redefinesubmol|\par
		|{<name>}<n>[<code1>]{<code2>}| \2 replaces the already existing alias |<name>| with the new |<code>|, \cfpage{redefinesubmol}\3
	\1|\charge|\par
		|[<parameters>]<pos>|\par
		|[<tikz>]{<atom>}| \2 displays the |<atom>| and places the charges at their |<positions>| without taking them into account in the bounding box, \cfpage{charge}\3
	\1|\Charge|\par
		|[<parameters>]<pos>|\par
		|[<tikz>]{<atom>}| \2 same as |\charge|, but the charges are taken into account in the bounding box.\3
	\1|\chemmove[<tikz options>]<tikz code>| \2 opens a |\tikzpicture| environment, adding the |<tikz options>| to those already existing, and connects with the |<tikz code>| the nodes placed in the molecules with the character “|@|”, \cfpage{chemmove}\3
	\1|\chemabove[<dim>]{<txt1>}{<txt2>}| \2 writes |<txt1>| and places |<txt2>| above it, leaving |<dim>| of vertical space. This command does not change the bounding box of |<txt1>|, \cfpage{chemabove.chembelow}\3
	\1|\chembelow[<dim>]{<txt1>}{<txt2>}| \2 writes |<txt1>| and places |<txt2>| below it, leaving |<dim>| of vertical space. This command does not change the bounding box of |<txt1>|, \cfpage{chemabove.chembelow}\3
	\1|\Chemabove[<dim>]{<txt1>}{<txt2>}| \2 writes |<txt1>| and places |<txt2>| above it, leaving |<dim>| of vertical space, \cfpage{chemabove.chembelow}\3
	\1|\Chembelow[<dim>]{<txt1>}{<txt2>}| \2 writes |<txt1>| and places |<txt2>| below it, leaving |<dim>| of vertical space, \cfpage{chemabove.chembelow}\3
	\1|\chemname[<dim>]{<molecule>}{<name>}| \2 displays the |<name>| under the |<molecule>|, \cfpage{chemname}\3
	\1|\chemnameinit| \2 initializes the greatest depth of the molecules encountered, to obtain a correct alignment of their names\3
	\1|\schemestart...\schemestop|\2 markers between which a reaction scheme is drawn, \cfpage{schemestart}\3
	\1|\arrow|\2 draws an arrow in a reaction scheme (the command is only defined inside a reaction scheme)\3
	\1|\+| \2 displays a $+$ sign in a reaction scheme (the command is only defined inside a reaction scheme), \cfpage{arrow}\3
	\1|\subscheme{<code>}| \2 draws a reaction subscheme (the command is only defined inside a reaction scheme), \cfpage{subscheme}\3
	\1|\definearrow| \2 defines an arrow for a reaction scheme, \cfpage {definearrow}\3
	\1|\chemleft<char1><material>|\par
		|...\chemright<char2>| \2 draws extensible delimiters defined by |<char1>| and |<char2>| to the left and right of the |<material>|, \cfpage{chemleft}\3
	\1|\chemup<char1><material>|\par
		|...\chemdown<char2>| \2 draws extensible delimiters defined by |<char1>| and |<char2>| above and below the |<material>|, \cfpage{chemup}\3
	\1|\polymerdelim|\par|[<parameters>]{<node1>}{<node2>}| \2 draws delimiters at the specified nodes, \cfpage{polymerdelim}\3
	\1|\hreac...\endhreac| \2 markers between which a horizontal reaction is drawn, \cfpage{hreac}\3
	\1|Z{<type>}[<upper label>][<lower label>]| \2 draws a horizontal arrow, \cfpage{harrow}\3
	\1|+| \2 displays the $+$ sign in the horizontal reaction\3
	\1|\Z{<dimension>}| \2 shifts the current compound horizontally, \cfpage{hshift}\3
	\1|\^{<dimension>}| or |\^*{<dimension>}| \2 shifts the current compound vertically, \cfpage{vshift}\3
	\1|\name{<name>}| \2 puts the |<name>| under the current compound, \cfpage{name}\3
	\_
\endgroup

\chap Gallery
\raggedbottom
This manual ends with drawings of molecules of varying complexity.

The curious user may take an interest in the |<code>| of each molecule, although it sometimes becomes off-putting when the molecules become complex. Indeed, beyond a certain level of complexity, although it is fairly easy to write a |<code>| to draw a molecule, it is rather hard to reread it in order to analyze it afterwards. The limits of the immediate readability of the code of a complex drawing are quickly reached.

In any case, I hope this package will help all users of \TeX{}, and even those of \LaTeX{}, who wish to draw chemical molecules. Although \CF\ has been thoroughly tested, I hope you will be lenient regarding any bugs you encounter. An {\Sourcepro\typoscale[800/800]\mono\bolder\rm\ulink[mailto:unbonpetit@netc.fr]{email}} to report a malfunction or to suggest any improvement will be welcome.

\exemple*{2-methylpentane}/\chemfig{[7]H_3C-CH(-[6]CH_3)-[1]CH_2-CH_2-[1]CH_3}/

\exemple*{3-ethyl-2-methylhexane}/\chemfig{H_3C-[7]CH(-[6]CH_3)-[1]CH(-[7]C_3H_7)-[2]CH_2-[3]H_3C}/

\exemple*{Stearin, condensed structural formula}/\definesubmol{@}{([0,2]-O-[0,1]C(=[2,1]O)-C_{17}H_{33})}
\chemfig{[2,2]CH_2!@-CH_{\phantom 2}!@-CH_2!@}/

\exemple*{Stearin, skeletal formula}/\definesubmol{x}{-[:+30,.6]-[:-30,.6]}
\definesubmol{y}{-O-(=[2,.6]O)-!x!x!x!x!x!x!x!x}
\chemfig{[2]([0]!y)-[,1.5]([0]!y)-[,1.5]([0]!y)}/

\exemple*{Methyl 2-methylpropanoate}/\chemfig{H_3C-CH_2(-[2]CH_3)-C(=[1]O)-[7]O-CH_3}/

\exemple*{Vanillin}/\chemfig{HC*6(-C(-OH)=C(-O-[::-60]CH_3)-CH=C(-[,,,2]HC=[::-60]O)-HC=[,,2])} \quad or \quad
\chemfig{*6(-(-OH)=(-OCH_3)-=(-=[::-60]O)-=)}/

\exemple*{Caffeine}/\chemfig{*6((=O)-N(-CH_3)-*5(-N=-N(-CH_3)-=)--(=O)-N(-H_3C)-)}/

\exemple*{Aspirin}/\chemfig{*6(-=-(-O-[::-60](=[::-60]O)-[::+60])=(-(=[::+60])-[::-60]OH)-=)}/

\exemple*{Phthalic anhydride}/\chemfig{*6(=*5(-(=O)-O-(=O)-)-=-=-)}/

\exemple*{Camphor}/\chemfig{*6(-(<:[::120](-[::-100,0.7])(-[::100,0.7]))--(=O)-(-)(<:[::120])--)}
\quad or \quad
\setchemfig{cram width=3pt}
\chemfig{<[:10](>[:85,1.8]?(-[:160,0.6])-[:20,0.6])
>[:-10]-[:60](=[:30,0.6]O)-[:170]?(-[:30,0.6])-[:190]-[:240]}/

\exemple*{Triphenylmethane}/\chemfig{*6(-=-*6(-(-*6(=-=-=-))-*6(=-=-=-))=-=)}
\quad or \quad
\definesubmol{@}{*6(=-=-=-)}
\chemfig{(-[:-30]!@)(-[:90]!@)(-[:210]!@)}/

\exemple*{Amygdalin}/\setchemfig{cram width=2pt}
\definesubmol{c1}{-[:200]-[:120]O-[:190]}
\definesubmol{c2}{-[:170](-[:200,0.7]HO)<[:300](-[:170,0.6]HO)
-[:10,,,,line width=2pt](-[:-40,0.6]OH)>[:-10]}
\definesubmol{csub}{-[:155,0.65]-[:90,0.65]}
\chemfig{O(!{c1}(!{csub}O(!{c1}(!{csub}OH)!{c2}))!{c2})-[:-30](-[:-90]CN)-[:30]*6(=-=-=-)}/

\exemple*{Adenosine triphosphate}/\setchemfig{cram width=3pt}
\definesubmol{a}{-P(=[::-90,0.75]O)(-[::90,0.75]HO)-}
\chemfig{[:-54]*5((--[::60]O([::-60]!aO([::-60]!aO([::60]!aHO))))<(-OH)
-[,,,,line width=2pt](-OH)>(-N*5(-=N-*6(-(-NH_2)=N-=N-)=_-))-O-)}/

\exemple*{Viagra}/\chemfig{N*6((-H_3C)---N(-S(=[::+120]O)(=[::+0]O)-[::-60]*6(-=-(-O-[::-60]-[::+60]CH_3)
=(-*6(=N-*5(-(--[::-60]-[::+60]CH_3)=N-N(-CH_3)-=)--(=O)-N(-H)-))-=))---)}/

\exemple*{Cholesterol ester}/\chemfig{[:30]R-(=[::+60]O)-[::-60]O-*6(--*6(=--*6(-*5(---(-(-[::+60]Me)
-[::-60]-[::-60]-[::+60]-[::-60](-[::-60]Me)-[::+60]Me)-)-(-[::+0]Me)---)--)-(-[::+0]Me)---)}/

\exemple*{Porphyrin}/\chemfig{?=[::+72]*5(-N=(-=[::-72]*5(-[,,,2]HN-[,,2](=-[::-36]*5(=N-(=-[::-72]*5(-NH-[,,1]?=-=))
-=-))-=-))-=-)}/

\exemple*{Manganese 5,10,15,20-tetra(N-ethyl-3-carbazolyl) porphyrin}/\definesubmol{A}{*6(=-*5(-*6(-=-=-)--N(--[::-60])-)=-=-)}
\chemfig{([::+180]-!A)=[::+72]*5(-N=(-(-[::+54]!A)=[::-72]*5(-N(-[::-33,1.5,,,draw=none]Mn)
-(=(-[::+72]!A)-[::-36]*5(=N-(=(-[::+54]!A)-[::-72]*5(-N-(-)=-=))-=-))-=-))-=-)}/

\exemple*{Penicillin}/\chemfig{[:-90]HN(-[::-45](-[::-45]R)=[::+45]O)>[::+45]*4(-(=O)-N*5(-(<:(=[::-60]O)
-[::+60]OH)-(<[::+0])(<:[::-108])-S>)--)}/

\exemple*{LSD}/\chemfig{[:150]?*6(=*6(--*6(-N(-CH_3)--(<(=[::+60]O)-[::-60]N(-[::+60]-[::-60])
-[::-60]-[::+60])-=)([::-120]<H)---)-*6(-=-=-(-[::-30,1.155]\chembelow{N}{H}?)=))}/

\exemple*{Strychnine}/\chemfig{*6(=-*6(-N*6(-(=O)--([::-120]<:H)*7(-O--=?[0]([::-25.714]-[,2]?[1]))
-*6(-?[0,{>}]--(<N?[1]?[2])-(<[::-90]-[::-60]?[2]))(<:[::+0]H)-([::+120]<H))--?)=?-=-)}/

\exemple*{Codeine}/\chemfig{[:-30]**6(-(-OH)-?-*6(-(-[3]-[2,2]-[0,.5])*6(-(<:[:-150,1.155]O?)
-(<:OH)-=-)-(<:[1]H)-(-[2]NCH_3)--)---)}/

\exemple*{Dye (red)}/\chemfig{**6(--*6(-(-NO_2)=-(-\charge{90=\|,-90=\|}{O}-[0]H)=(-\charge{180=\|}{N}=[0]\charge{90=\|}{N}-[0]Ar)-)----)}/

\exemple*{Menthone}/\chemfig{CH_3-?(-[2]H)(-[::-30,2]-[::+60](=[1]\charge{0=\|,90=\|}{O})
-[::-150,1.5](-[:20]CH(-[1]CH_3)(-[7]CH_3))(-[6]H)-[::-90,2]-[::+60]?)}/

\exemple*{Fullerene}/\definesubmol\fragment1{
	(-[:#1,0.85,,,draw=none]
	-[::126]-[::-54](=_#(2pt,2pt)[::180])
	-[::-70](-[::-56.2,1.07]=^#(2pt,2pt)[::180,1.07])
	-[::110,0.6](-[::-148,0.60](=^[::180,0.35])-[::-18,1.1])
	-[::50,1.1](-[::18,0.60]=_[::180,0.35])
	-[::50,0.6]
	-[::110])
}
\chemfig{
	!\fragment{18}
	!\fragment{90}
	!\fragment{162}
	!\fragment{234}
	!\fragment{306}
}/% https://tex.stackexchange.com/questions/506293/how-to-draw-a-fullerene

\exemple*{Fischer indole synthesis}/\schemestart
	\chemfig{*6(=-*6(-\chembelow{N}{H}-NH_2)=-=-)}
	\+
	\chemfig{(=[:-150]O)(-[:-30]R_2)-[2]-[:150]R_1}
	\arrow(.mid east--.mid west){->[\chemfig{H^+}]}
	\chemfig{*6(-=*5(-\chembelow{N}{H}-(-R_2)=(-R_1)-)-=-=)}
\schemestop/

\exemple*{Reaction mechanism: carbonyl group}/\schemestart
	\chemfig{C([3]-)([5]-)=[@{db,.5}]@{atoo}\charge{0=\|,-90=\|}{O}}
	\arrow(.mid east--.mid west){<->}
	\chemfig{\charge{90:3pt=$\scriptstyle\oplus$}{C}([3]-)([5]-)-%
		\charge{0=\|,90=\|,-90=\|,45:3pt=$\scriptstyle\ominus$}{O}}
\schemestop
\chemmove{\draw[shorten <=2pt, shorten >=2pt](db) ..controls +(up:5mm) and +(up:5mm)..(atoo);}/

\exemple*{Reaction mechanisms: nitro compounds}/\schemestart
	\chemfig{R-\charge{225:3pt=$\scriptstyle\oplus$}{N}([1]=[@{db}]@{atoo1}O)([7]-[@{sb}]@{atoo2}
	\charge{45=\|,-45=\|,-135=\|,45:5pt=$\scriptstyle\ominus$}{O})}
	\arrow(.mid east--.mid west){<->}
	\chemfig{R-\charge{135:3pt=$\scriptstyle\oplus$}{N}([1]-\charge{90:3pt=$\scriptstyle\ominus$}{O})([7]=O)}
\schemestop
\chemmove{
	\draw[shorten <=2pt, shorten >=2pt](db) ..controls +(120:5mm) and +(120:7mm)..(atoo1);
	\draw[shorten <=3pt, shorten >=2pt](atoo2) ..controls +(225:10mm) and +(225:10mm)..(sb);
}/

\exemple*{Calcium alginate gel}?\definesubmol{0}{-[-3,.15,,,draw=none]}% invisible bond to stack
\definesubmol{COO/Na+}1{-[7]((-[-3,.66]COO^{-}!0N|a^+#1))}
\definesubmol{chain}{-[5]!{COO/Na+}{}-[5]!{COO/Na+}{}-[5]-[7]}
\definesubmol{COO/Ca2+}1{-[7]((-[-3,.66]COO^{-}!0C|a^{2+}!0COO^{-}-[-3,.66](-[7]-[5])#1))}
\hreac[fixed length,atom sep=2.5em,angle increment=30]
	\chemfig{-[5]!{COO/Na+}{!0\phantom{C}!0(!{COO/Na+}{}!{chain})(-[-1])}!{chain}}
	>[\printatom{Ca^{2+}}]
	\chemfig{-[5]!{COO/Ca2+}{(-[-1]-[1])}-[5]!{COO/Ca2+}{}-[5]!{COO/Ca2+}{}-[5]-[7]}
\endhreac?

\exemple*{Nucleophilic addition. Primary amines}/\setchemfig{atom sep=2.5em,compound sep=5em}
\schemestart
	\chemfig{R-@{aton}\charge{90=\|}{N}H_2}
	\+
	\chemfig{@{atoc}C([3]-CH_3)([5]-CH_3)=[@{atoo1}]O}
	\chemfig{@{atoo2}\chemabove{H}{\scriptstyle\oplus}}
	\chemmove[-stealth,shorten <=3pt,dash pattern= on 1pt off 1pt,thin]{
		\draw[shorten >=2pt](aton) ..controls +(up:10mm) and +(left:5mm)..(atoc);
		\draw[shorten >=8pt](atoo1) ..controls +(up:10mm) and +(north west:10mm)..(atoo2);}
	\arrow{<=>[\tiny addition]}
	\chemfig{R-@{aton}\chembelow{N}{\scriptstyle\oplus}H([2]-[@{sb}]H)-C(-[2]CH_3)(-[6]CH_3)-OH}
\schemestop
\chemmove{
    \draw[-stealth,dash pattern= on 1pt off 1pt,shorten <=3pt, shorten >=2pt]
    (sb)..controls +(left:5mm) and +(135:2mm)..(aton);}
\par
\schemestart
	\arrow{<=>}
	\chemfig{R-@{aton}\charge{90=\|}{N}([6]-[@{sbh}]H)-[@{sb}]C(-[2]CH_3)(-[6]CH_3)-[@{sbo}]@{atoo}
	\chemabove{O}{\scriptstyle\oplus}(-[1]H)(-[7]H)}
	\chemmove[-stealth,shorten <=3pt,shorten >=2pt,dash pattern= on 1pt off 1pt,thin]{
		\draw(aton) ..controls +(up:5mm) and +(up:5mm)..(sb);
		\draw(sbh) ..controls +(left:5mm) and +(south west:5mm)..(aton);
		\draw(sbo) ..controls +(up:5mm) and +(north west:5mm)..(atoo);}
	\arrow{<=>[\tiny elimination]}\chemfig{R-N=C(-[1]CH_3)(-[7]CH_3)}
	\+
	\chemfig{H_3\chemabove{O}{\scriptstyle\oplus}}
\schemestop/

\exemple*{Reaction scheme}/\setchemfig{atom sep=2em}
\schemestart[arrow angle=-90]
	\chemfig{**6(---(-NH _2)---)}\arrow{0}\chemfig{HNO_2}
	\merge(c1)(c2)--()
	\chemfig{**6(---(-N_2|{}^\oplus)---)}\arrow{0}\chemfig{**6(---(-NH _2)---)}
	\merge(c3)(c4)--()
	\chemfig{**6(---(-N=[::-30]N-[::-30]**6(---(-NH_2)---))---)}
\schemestop/

\exemple*{Addition reaction}/\setchemfig{atom sep=2.5em}
\schemestart
	\chemfig{*6(=-(-)(=[2]O))}
	\arrow{->[\+\chemfig{H^\oplus}]}
	\chemleft[%
	\subscheme[90]{%
		\chemfig{*6((-[2,0.33,,,draw=none]\scriptstyle\oplus)-=(-)-OH)}
		\arrow{<->}
		\chemfig{*6(=-(-)(-[6,0.33,,,draw=none]\scriptstyle\oplus)-OH)}}%
	\chemright]
	\arrow(@c4--)\chemfig{*6(=-(-)(-[6]R)-OH)}
\schemestop/

\exemple*{Electrophilic aromatic substitution}Z\setchemfig{atom sep=1.5em}%
\definesubmol{+}{-[,-0.4,,,draw=none]\oplus}%
\schemestart
	\arrow{0}[,0]
	\chemleft[\subscheme{\chemfig{*6(=-=-(-[:120]Br)(-[:60]H)-(!+)-)}
		\arrow{<->}
		\chemfig{*6(-(!+)-=-(-[:120]Br)(-[:60]H)-=)}
		\arrow{<->}
		\chemfig{*6(-=-(!+)-(-[:120]Br)(-[:60]H)-=)}}\chemright]
	\arrow(@c2--){<-[*0\chemfig{{-}AlBr_4|^\ominus}][*0\chemfig{Br_2/Al_2Br_3}]}[90,1.5]
	\chemname{\chemfig{*6(-=-=-=-)}}{Benzene 1}
	\arrow(@c4--){->[*0\chemfig{{-}H^\oplus}]}[90,1.5]
	\chemname{\chemfig{*6(-=-=(-Br)-=-)}}{Bromobenzene 2}
	\arrow(@c5.mid east--@c6.mid west)
\schemestop
\chemnameinit{}Z

\exemple*{Reaction mechanisms of chlorination}/\scriptsize\setchemfig{bond offset=1pt,atom sep=2em,compound sep=4em}
\schemestart
	\chemfig{Cl-[4]@{a0}(=[@{a1}:120]@{a2}O)-[:-120](=[:-60]O)-[4]Cl}\+\chemfig{*6(-=-=(-@{oh1}OH)-=)}\arrow
	\chemfig{*6((-O-[:150](-[@{o0}:150]@{o1}\charge{-90=\.}{O})(-[@{cl0}:60]@{cl1}Cl)-[:240](-[4]Cl)=[6]O)=-=-=-)}
	\arrow\chemfig{*6((-O-[:150](=[2]O)-[:-150](=[6]O)-[:150]Cl)=-=-=-)}\+\chemfig{HCl}
	\arrow(@c1--){0}[-90,0.5]
	\chemfig{*6(-=*6(-O-*6(-@{o2}(=[@{o3}]@{o4}O)-Cl)=)-=-=)}\+\chemfig{*6(-=-=(-@{oh2}OH)-=)}\arrow
	\chemfig{*6(-=*6(-O-(-(-[@{cl2}:60]@{cl3}Cl)(-[@{o5}:-120]@{o6}\charge{-90=\.}{O})-O-[::-40]*6(=-=-=-))=)-=-=)}
	\kern-3em \arrow\chemfig{[:30]*6(=-(-O-[:-60](=O)-[:-120](=[4]O)-[:-60]O-*6(=-=-=-))=-=-)}
	\kern-3em \+\chemfig{HCl}
\schemestop
\chemmove[line width=0.2pt,-stealth,dash pattern = on 2pt off 1pt]{
	\draw[shorten <=2pt](a1)..controls+(200:5mm)and+(200:5mm)..(a2);
	\draw[shorten >=2pt](oh1.west)..controls+(180:15mm)and+(60:5mm)..(a0);
	\draw[shorten <=6pt,shorten >=2pt](o1)..controls+(270:5mm)and+(270:5mm)..(o0);
	\draw[shorten <=2pt](cl0)..controls+(150:5mm)and+(150:5mm)..(cl1.150);
	\draw[shorten <=2pt](o3)..controls +(30:3mm) and +(30:5mm)..(o4.east);
	\draw[shorten >=2pt](oh2.135).. controls +(150:10mm) and +(90:10mm).. (o2);
	\draw[shorten >=2pt,shorten <=5pt]([xshift=-1.5mm]o6.315)..controls +(315:5mm) and +(315:5mm)..(o5);
	\draw[shorten <=2pt](cl2)..controls +(135:5mm) and +(135:5mm)..(cl3.north west);}/

\exemple*{Cannizzaro}/\schemestart
	\chemfig{[:-30]*6(=-=(-@{atoc}C([6]=[@{db}]@{atoo1}O)-H)-=-)}
	\arrow(start.mid east--.mid west){->[\chemfig{@{atoo2}\chemabove{O}{\scriptstyle\ominus}}H]}
	\chemmove[-stealth,shorten >=2pt,dash pattern=on 1pt off 1pt,thin]{
			\draw[shorten <=8pt](atoo2) ..controls +(up:10mm) and +(up:10mm)..(atoc);
			\draw[shorten <=2pt](db) ..controls +(left:5mm) and +(west:5mm)..(atoo1);}
	\chemfig{[:-30]*6(=-=(-C([6]-[@{sb1}]@{atoo1}\chembelow{O}{\scriptstyle\ominus})([2]-OH)-[@{sb2}]H)-=-)}
	\hskip1cm \relax
	\chemfig{[:-30]*6((-@{atoc}C([6]=[@{db}]@{atoo2}O)-[2]H)-=-=-=)}
	\chemmove[-stealth,shorten <=2pt,shorten >=2pt,dash pattern=on 1pt off 1pt,thin]{
			\draw([yshift=-4pt]atoo1.270) ..controls +(0:5mm) and +(right:10mm)..(sb1);
			\draw(sb2) ..controls +(up:10mm) and +(north west:10mm)..(atoc);
			\draw(db) ..controls +(right:5mm) and +(east:5mm)..(atoo2);}
	\arrow(@start.base west--){0}[-75,2]
	{}
	\arrow
	\chemfig{[:-30]*6(=-=(-C([1]-@{atoo2}O-[@{sb}0]@{atoh}H)([6]=O))-=-)}
	\arrow{0}
	\chemfig{[:-30]*6((-C(-[5]H)(-[7]H)-[2]@{atoo1}\chemabove{O}{\scriptstyle\ominus})-=-=-=)}
	\chemmove[-stealth,shorten >=2pt,dash pattern=on 1pt off 1pt,thin]{
			\draw[shorten <=7pt](atoo1.90) ..controls +(+90:8mm) and +(up:10mm)..(atoh);
			\draw[shorten <=2pt](sb) ..controls +(up:5mm) and +(up:5mm)..(atoo2);}
\schemestop/

\begingroup
\catcode`;=12
\exemple*{Beckmann rearrangement}/\setchemfig{bond offset=1pt,atom sep=2.5em,compound sep=5em,arrow offset=6pt}
\schemestart
	\chemfig{(-[:-150]R')(-[:-30]R)=[2]N-[:30]OH}
	\arrow{<=>[\chemfig{H^\oplus}]}
	\chemfig{(-[@{a0}:-150]R')(-[:-30]R)=[2]@{a1}N-[@{b0}:30]@{b1}\chemabove{O}{\scriptstyle\oplus}H_2}
	\chemmove[red,-stealth,red,shorten <=2pt]{
		\draw(a0)..controls +(135:2mm) and +(215:4mm).. (a1);
		\draw(b0)..controls +(120:2mm) and +(180:3mm).. ([yshift=7pt]b1.180);}
	\arrow{<=>[\chemfig{{-}H_2O}]}[,1.1]
	\chemleft[\subscheme[90]{%
		\chemfig{R'-\chemabove{N}{\scriptstyle\oplus}~C-R}
		\arrow{<->}[,0.75]
		\chemfig{R'-\charge{90=\:}{N}=@{a1}\chemabove{C}{\scriptstyle\oplus}-R}}\chemright]
	\arrow{<=>[\chemfig{H_2@{a0}\charge{0=\:,90=\:}{O}}]}[,1.1]
	\chemmove[red,-stealth,red,shorten <=3pt]{
		\draw(a0)..controls+(90:10mm)and+(45:10mm)..([yshift=6pt]a1.45);}
	\arrow(@c1--){0}[-90,0.333]
	\chemfig{*6(R\rlap{$'$}-N=(-R)-\chemabove{O}{\scriptstyle\oplus} H_2)}
	\arrow{<=>[\chemfig{{-}H^\oplus}]}
	\chemfig{*6(R\rlap{$'$}-N=(-R)-OH)}
	\arrow
	\chemfig{*6(R\rlap{$'$}-\chembelow{N}{H}-(-R)(=[2]O))}
\schemestop/
\endgroup

\exemple*{Reaction scheme}/\setchemfig{atom sep=1.5em,compound sep=4em}
\schemestart
	\chemfig{-[::30]=_[::-60](-[:: -60])-[::60]}
	\arrow{->[\chemfig{HCl}]}
	\chemfig{-[::30]-[::-60](-[::120]Cl)(-[::-60])-[::60]}\+\chemfig{-[::30](-[::60]Cl)-[::-60](-[::-60])-[::60]}
	\arrow(@c1--.north west){->[\chemfig{H_2O}]}[-45,1.7]
	\chemfig{-[::30]-[::-60](-[::120]OH)(-[::-60])-[::60]}\+\chemfig{-[::30](-[::60]OH)-[::-60](-[::-60])-[::60]}
\schemestop/

\exemple*{Esterification of formic acid}Z\tikzset{obrace/.style={left delimiter={[},inner sep=3pt},
	cbrace/.style={right delimiter={]},inner sep=3pt},
	braces/.style={left delimiter={[},right delimiter={]},inner sep=3pt}}
\setchemfig{atom sep=2em}
\schemestart
	\chemfig{H-C(=[:60]O)-[:-60]O-H}
	\arrow(--M1[obrace]){-U>[\scriptsize\chemfig{H_2SO_4^{}}][\scriptsize\chemfig{HSO_4^\ominus}][][.25]}%
		[,1.5,shorten >=6pt]
	\chemfig{H-@{a2}C(-[:60]O-H)(-[:30,.5,,,draw=none]{\scriptstyle\oplus})-[:-60]O-H}
	\arrow(--[cbrace]){<->}
	\chemfig{H-C(=[:60]\chemabove{O}{\scriptstyle\oplus}-H)-[:-60]O-H}
	\arrow(@M1--){<=>[*{0}\scriptsize\chemfig{H-[:120]@{a1}O-[:60]CH_3}][*{0}\tiny addition]}[-90,1.33]
	\chemfig{H-C(-[2]O-[:30]H)(-\chemabove{O}{\scriptstyle\oplus}(-[:60]CH_3)-[:-60]H)-[6]O-[:-30]H}
	\arrow{<=>[\tiny protolysis]}[180]
	\chemfig{H-C(-[2]O-[:30]H)(-O-CH_3)-[@{b1}6]@{a3}\chemabove{O}{\kern-4mm\scriptstyle\oplus}(-[:-150]H)-[:-30]H}
	\arrow(--[obrace]){<=>[*{0}\scriptsize\chemfig{{-}H_2O}][*{0}\tiny elimination]}[-90,,shorten >=6pt]
	\chemfig{H-C(-[:60]O-H)(-[,.5,,,draw=none]{\scriptstyle\oplus})-[:-60]O-CH_3}
	\arrow(--[cbrace]){<->}
	\chemfig{H-C(=[:60]\chemabove{O}{\scriptstyle\oplus}-H)-[:-60]O-CH_3}
	\arrow{-U>[\scriptsize\chemfig{HSO_4^\ominus}][\scriptsize\chemfig{H_2SO_4^{}}][][.25]}[,1.5]
	\chemfig{H-C(=[:60]O)-[:-60]O-CH_3}
	\arrow(@M1--[yshift=-5pt]){0}[180,.5]{\tiny protolysis}
	\chemmove[red,shorten <=3pt,shorten >=1pt]{
		\draw(a1)..controls +(0:1.5cm)and+(0:3cm).. (a2);
		\draw(b1)..controls +(0:5mm)and+(20:5mm)..(a3);}
\schemestop Z

\exemple*{Electrophilic addition of a halogen to an olefin}/\schemestart
	\subscheme{%
		\chemfig{C(<[:40])(<[:160])=[6]C(<[:-130])<[:-20]}
		\arrow{0}[,0]\+\chemfig{\charge{90=\|,180=\|,270=\|}{Br}-\charge{90=\|,0=\|,270=\|}{Br}}}
	\arrow(@c1--olefin){<=>[*{0}rapide]}[-90]
	\chemfig{>[:-20]C(<[:40])=[@{db}6]C(<[:-130])<[:-20]}
	\arrow(--bromonium){0}[-90]
	\chemname{\chemfig{C*3((<)(<:[:-155])-\charge{45=\|,-45=\|,180:3pt=$\scriptstyle\oplus$}{Br}-C(<:)(<[:155])-)}}
		{bromonium ion}
	\arrow(--carbeniumA){<<->}[,1.5]
	\chemname{\chemfig{-[:-30]\chemabove{C}{\scriptstyle\oplus}(-[:30])-[6]C(<:[:-150])(<[:-100])-[:-30]
		\charge{45=\|,-45=\|,225=\|}{Br}}}{carbenium ion}
	\arrow(@bromonium--carbeniumB){<<->}[180,1.5]
	\chemname{\chemfig{-[:-30]\chemabove{C}{\scriptstyle\oplus}(-[:30])-[6]C(<[:-150])
		(<:[:-100])-[:-30]\charge{45=\|,-45=\|,135=\|}{Br}}}{carbenium ion}
	\arrow(@olefin--){0}[,.25]
	\chemfig{@{Br1}\charge{90=\|,180=\|,270=\|,90:5pt=$\scriptstyle\delta\oplus$}{Br}-[@{b2}]@{Br2}
		\charge{90=\|,0=\|,270=\|,90:5pt=$\scriptstyle\delta\ominus$}{Br}}
	\arrow(@olefin--[left]){0}[180,0]
	$\pi$ complexe
	\arrow(@carbeniumA--@olefin){<=>[slow, \chemfig{{-}Br^\ominus}]}
	\arrow(@carbeniumB--@olefin){<=>[slow, \chemfig{{-}Br^\ominus}]}
	\chemmove[-stealth,red,shorten <=3pt,shorten >=2pt]{
		\draw(db) .. controls +(20:5mm) and +(135:5mm) .. (Br1);
		\draw(b2) .. controls +(-90:5mm) and +(-120:5mm) .. (Br2);}
\schemestop
\chemnameinit{}/

\exemple*{Sulfonation of naphthalene}/\definesubmol\cycleoplus{-[,0.25,,,draw=none]\oplus}
\definesubmol{so2oh}{S(=[::90]O)(=[::-90]O)-OH}
\setchemfig{atom sep=2.5em}
\schemestart[arrow coeff=1.5]
	\chemname{\chemfig{*6(=-*6(-=-=-)=-=-)}}{Naphthalene}\+\chemfig{H_2SO_4}
	\arrow(nph.mid east--.south west){->[80° C]}[45]
	\chemname{\chemfig{*6(=-*6(-=-(!\cycleoplus)-(-SO_3H)-)=-=-)}}{1-arenium ion}
	\arrow(.mid east--.mid west)
	\chemname{\chemfig{*6(=-*6(-=-=(-!{so2oh})-)=-=-)}}{1-naphthalenesulfonic acid}
	\arrow(@nph.mid east--.north west){->[160° C]}[-45]
	\chemname{\chemfig{*6(=-*6(-=-(-SO_3H)-(!\cycleoplus)-)=-=-)}}{2-arenium ion}\kern-4em
	\arrow(.mid east--.mid west)
	\chemname{\chemfig{*6(=-*6(-=-(-!{so2oh})=-)=-=-)}}{2-naphthalenesulfonic acid}
\schemestop
\chemnameinit{}/

\exemple*{Taxotere}/\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)-)}/

% https://tex.stackexchange.com/questions/673490/diverging-arrow-in-chemfig/673572#673572
\exemple*{Diverging arrows}/\schemestart
	\chemfig{(-[:210]R_2)(-[:330]R_1)=[2]O}
	\arrow(a--)[,1.5,,,draw=none]
	\subscheme{
		\charge{30:4pt=$\rm S_1$}{\chemleft{[}\chemfig{(-[:210]R_2)(-[:330]R_1)=[2]O}\chemright{]}}
		\arrow(b--c){->[*{0}ISC]}[-90,1.5]
		\charge{30:4pt=$\rm T_1$}{\chemleft[\chemfig{(-[:210]R_2)(-[:330]R_1)=[2]O}\chemright{]}}
	}
	\arrow(--d)[,1.5,,,draw=none]
	\chemfig{(-[:210]R_2)(-[:330,0.1,,,draw=none]\charge{330:-1pt=\.\,}{})=[2]O}
	\+
	\chemfig{\charge{90:1pt=\.\,}{R}_1}
\schemestop
\chemmove{
	\draw[thick,shorten >=10pt] (a.east) -- ++(1,0) |- (b.west);
	\draw[thick,shorten >=10pt] (a.east) -- ++(1,0) |- (c.west);
	\draw[-,thick,shorten >=15pt,shorten <=8pt] (b.east) -- ++(1.3,0) |- (d.west);
	\draw[thick,shorten >=10pt,shorten <=8pt] (c.east) -- ++(1.3,0) |- (d.west);
}/

\chap[changelogs] Change history
\normalbottom
Changes (most recent first) made to \CF\ since the first version. {\it The change history below is reproduced from the French manual and has not been translated.}
\input{changelog.tex}
\bye