chemfig
Operation of chemfig
15 Writing a name under a molecule¶
For convenience, chemfig can write the name of a molecule underneath it with the command
\chemname[⟨dim⟩]{\chemfig{⟨code of the molecule⟩}}{⟨name⟩}
The ⟨dim⟩, which is 1.5ex by default, will be inserted between the baseline of the molecule and the top of the letters of the ⟨name⟩. The ⟨name⟩ will be centered relative to the molecule, but the ⟨name⟩ may not contain multiple paragraphs. As we see in this example: , the ⟨name⟩ which is displayed under the molecule is taken into account only for the vertical size of the bounding box. The horizontal size of ⟨name⟩ is always zero.
Here is a reaction with the names under the molecules:
\schemestart
\chemname{\chemfig{R-C(-[:-30]OH)=[:30]O}}{Acide carboxylique}
\+
\chemname{\chemfig{R'OH}}{Alcool}
\arrow(.mid east--.mid west)
\chemname{\chemfig{R-C(-[:-30]OR')=[:30]O}}{Ester}
\+
\chemname{\chemfig{H_2O}}{Water}
\schemestop
\chemnameinit{}
There are some limitations to this command. Suppose we switch the acid and the alcohol on the left side:
\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, to draw the ⟨name⟩ the command \chemname inserts 1.5ex\({}+{}\)the largest of the depths1 of the molecules thus far below the baseline of each molecule (light gray for the examples in this manual). The command \chenameinit{⟨stuff⟩} initializes this largest depth with the ⟨stuff⟩. Therefore one should:
write \chemnameinit{⟨deepest molecule⟩} before using the \chemname command in a reaction, unless the reaction begins with the deepest molecule;
write \chemnameinit{} after having written all the names in a chemical reaction lest the greatest depth in this reaction interfere with a future reaction.
Note that the assignments for the largest depth are global if gchemname = ⟨true⟩, which is the default behavior. They are local otherwise.
Thus the correct code uses \chemnameinit before and after the reaction:
\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 multiple lines, the command \\ encountered in a ⟨name⟩ causes a line break2:
\schemestart
\chemname{\chemfig{R-C(-[:-30]OH)=[:30]O}}{Carboxilic\\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 \chemname*{⟨name⟩} is written, the macro does not take into account the previous names.