5. Chemistry chemfig LaTeX๏ƒ

See: https://www.overleaf.com/learn/latex/Chemistry_formulae See: https://mirror.aarnet.edu.au/pub/CTAN/macros/generic/chemfig/chemfig-en.pdf

BingAi can be used to quickly get structural diagrams of chemicals by inlcuding โ€œchemfig latexโ€ in the prompt.
Output latex can be copied and pasted into overleaf so that a pdf can be produced.
e.g prompt: write latex with chemfig for 20 organic compounds

5.1. chemfig๏ƒ

The chemfig package makes it easy to draw structural diagrams of chemicals.
methane

methane๏ƒ

1\documentclass[border = 5mm]{standalone}
2\usepackage{chemfig}
3\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}} % This line changes the font of the atoms to sans serif
4\begin{document}
5\chemfig{C(-[2]H)(-[4]H)(-[6]H)-H}
6\end{document}
ethanol

ethanol๏ƒ

1\documentclass[border = 5mm]{standalone}
2\usepackage{chemfig}
3\begin{document}
4\chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-O-H}
5\end{document}
acetaldehyde

acetaldehyde๏ƒ

1\documentclass[border = 5mm]{standalone}
2\usepackage{chemfig}
3\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}} % This line changes the font of the atoms to sans serif
4\begin{document}
5\chemfig{H-C(-[2]H)(-[6]H)-C(=[1]O)-[7]H}
6\end{document}
ethyne

ethyne๏ƒ

1\documentclass[border = 5mm]{standalone}
2\usepackage{chemfig}
3\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}} % This line changes the font of the atoms to sans serif
4\begin{document}
5% Ethylene
6\chemfig{C(-[4]H)~C(-[8]H)}
7\end{document}
benzene

benzene๏ƒ

1\documentclass[border = 5mm]{standalone}
2\usepackage{chemfig}
3\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}} % This line changes the font of the atoms to sans serif
4\begin{document}
5\chemfig{C*6((-H)-C(-H)=C(-H)-C(-H)=C(-H)-C(-H)=)}
6\end{document}

alanine

alanine๏ƒ

1\documentclass[border = 5mm]{standalone}
2\usepackage{chemfig}
3\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}} % This line changes the font of the atoms to sans serif
4\begin{document}
5\chemfig{H-C(-[2]NH_2)(-[6]CH_3)-C(=[1]O)-[7]OH}
6\end{document}
7
8

5.2. Pentane latex explained๏ƒ

pentane

pentane๏ƒ

1\documentclass[border = 5mm]{standalone}
2\usepackage{chemfig}
3\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}} % This line changes the font of the atoms to sans serif
4\begin{document}
5\definesubmol{C}{-C(-[2]H)(-[6]H)}
6\chemfig{H!C!C!C!C!C-H}
7\end{document}
Pentane LaTeX uses a submolecule macro.
The full LaTeX explanation is:
  • documentclass[border = 1mm]{standalone}: This sets the document class to standalone, which means that the output will be a single image file with a border of 1mm. This is useful for creating diagrams or figures that can be inserted into other documents.

  • usepackage{chemfig}: This loads the chemfig package, which provides commands and tools for drawing chemical structures and reactions.

  • renewcommand*printatom[1]{ensuremath{mathsf{#1}}}: This line changes the font of the atoms to sans serif

  • begin{document}: This marks the beginning of the document content.

  • definesubmol{C}{-C(-[2]H)(-[6]H)}: This defines a sub-molecule named C, which consists of a carbon atom with two hydrogen atoms attached at angles of 2 and 6 (relative to the horizontal axis). This sub-molecule can be reused later in the code to simplify the drawing of larger molecules.

  • chemfig{H!C!C!C!C!C-H}: This draws a chemical structure using the chemfig syntax. The ! symbol indicates that a sub-molecule is inserted at that position. So this code draws a hexane molecule, which is composed of six carbon atoms (using the sub-molecule C) and two hydrogen atoms at the ends.

  • end{document}: This marks the end of the document content.


5.3. Chemfig syntax๏ƒ

\chemfig{<atom>-[<angle>,<length>,<side>,<style>]<atom>}
The <atom> argument is the name of the atom to be drawn. It can be a single letter or a group of letters enclosed in braces. For example, H, C, O, N, {CH3}, {OH}, etc.
The - symbol is used to draw a single bond between two atoms. It can be replaced by other symbols to draw different types of bonds. For example, = for a double bond, ~ for a triple bond, etc.
The [<angle>,<length>,<side>,<style>] argument is optional and can be used to modify the appearance of the bond. It can have up to four parameters separated by commas:
  • The <angle> parameter is a number that specifies the angle of the bond relative to the horizontal axis. It can be a multiple of 45 degrees (such as 2, 4, 6, 8) or an exact angle in degrees (such as 30, 60, 90). It can also be preceded by a colon (:) to indicate an absolute angle or a double colon (::) to indicate a relative angle. Positive angles are masured clockwise; negative, anticlockwise.

  • The <length> parameter is a number that specifies the length of the bond as a factor of the default length. For example, 2 means twice as long as the default length, 0.5 means half as long as the default length, etc.

  • The <side> parameter is either 1 or -1 and specifies which side of the bond the next atom will be drawn. For example, 1 means above the bond and -1 means below the bond.

  • The <style> parameter is a TikZ code that specifies the style of the bond. For example, dashed, dotted, red, thick, etc.


5.4. Ethylene syntax explained๏ƒ

ethene

ethene๏ƒ

1\documentclass[border = 5mm]{standalone}
2\usepackage{chemfig}
3\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}} % This line changes the font of the atoms to sans serif
4\begin{document}
5% Ethylene with absolute angles
6\chemfig{C(-[:120]H)(-[:240]H)=C(-[:300]H)-[:60]H}
7\end{document}
chemfig{C(-[:120]H)(-[:240]H)=C(-[:300]H)-[:60]H} represents a molecule of ethene.
The syntax of the expression is as follows:
  • The chemfig command starts drawing a molecular structure.

  • The C symbols represent carbon atoms.

  • The H symbols represent hydrogen atoms.

  • The (-[:120]H) means that there is a single bond (-) between the carbon atom and the hydrogen atom at an angle of 120 degrees from the horizontal axis. The angle is measured counterclockwise in multiples of 45 degrees, so 120 degrees is equivalent to [2.67] in the optional argument of the bondยน.

  • Similarly, the (-[:240]H) means that there is a single bond (-) between the carbon atom and the hydrogen atom at an angle of 240 degrees from the horizontal axis, or [5.33] in the optional argument of the bondยน.

  • The = symbol represents a double bond between two carbon atoms.

  • The (-[:300]H) means that there is a single bond (-) between the carbon atom and the hydrogen atom at an angle of 300 degrees from the horizontal axis, or [6.67] in the optional argument of the bondยน.

  • The -[:60]H means that there is a single bond (-) between the carbon atom and the hydrogen atom at an angle of 60 degrees from the horizontal axis, or [1.33] in the optional argument of the bondยน.


5.5. Lewis dot diagram๏ƒ

water_lewis

water_lewis๏ƒ

1\documentclass[border = 5mm]{standalone}
2\usepackage{chemfig}
3\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}} % This line changes the font of the atoms to sans serif
4\begin{document}
5\chemfig{H-[:52.24]\charge{45=\:,135=\:}{O}-[::-104.48]H}
6\end{document}
hydronium_lewis

hydronium_lewis๏ƒ

 1\documentclass[border = 5mm]{standalone}
 2\usepackage{chemfig}
 3\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}} % This line changes the font of the atoms to sans serif
 4\begin{document}
 5
 6\chemleft[\chemfig{
 7\charge{[overlay=true]35:3pt=\color{red}{$\scriptstyle\delta^+$}}{H}
 8-\charge{[overlay=true]35:3pt=\color{red}{$\scriptstyle\delta^-$},90=\:}{O}
 9(-[6]\charge{[overlay=true]35:3pt=\color{red}{$\scriptstyle\delta^+$}}{H})
10-\charge{[overlay=true]35:3pt=\color{red}{$\scriptstyle\delta^+$}}{H}}
11\quad\chemright]
12\chemmove{\node[] at (0pt,10pt) {\footnotesize $+$};}
13
14\end{document}

5.6. Lewis equation๏ƒ

lewis_equation

lewis_equation๏ƒ

 1\documentclass[border=5mm]{standalone} \usepackage{chemfig} 
 2\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}} 
 3\begin{document}
 4\setchemfig{atom sep=1.5em, fixed length=true}
 5\setcharge{extra sep=3pt}
 6\schemestart
 7\chemfig{-\charge{90=\:}{N}=C=\charge{90=\:,270=\:}{O}}
 8\arrow{<->}
 9\chemfig{-\charge{90=\:}{N}=\charge{90=$ ^+ $}{C}-\charge{0=\:,90=\:,270=\:,45=$ \;^- $}{O}}
10\arrow{<->}
11\chemfig{-\charge{90=\:,270=\:,135=$ ^-\; $}{N}-\charge{90=$ ^+ $}{C}=\charge{0=\:,90=\:}{O}}
12\schemestop
13\end{document}

5.7. Molecular equation๏ƒ

molecular_equation

molecular_equation๏ƒ

 1\documentclass[border=5mm]{standalone}
 2\usepackage{chemfig}
 3\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}}
 4\begin{document}
 5\chemnameinit{\chemfig{R-C(-[:-30]OH)=[:30]O}}
 6\schemestart
 7\chemname{\chemfig{Rโ€™OH}}{Alcohol}
 8\+
 9\chemname{\chemfig{R-C(-[:-30]OH)=[:30]O}}{Carboxylic acid}
10\arrow(.mid east--.mid west)
11\chemname{\chemfig{R-C(-[:-30]ORโ€™)=[:30]O}}{Ester}
12\+
13\chemname{\chemfig{H_2O}}{Water}
14\schemestop
15\chemnameinit{}
16\end{document}