Amino Acids

This page shows the structure of an amino acid. R is a placeholder for a side chain. It could be non-trivial for the first time to draw this structure in LaTeX. Therefore, I decided to share the code below so that anyone who needs this example can easily see how to use it.

The first picture displays the non-charged state:

Amino acid molecule chemical formula
\documentclass[varwidth,border=2pt]{standalone}
\usepackage{chemfig}
\usepackage{amsmath}
\setchemfig{atom sep=2em}
\begin{document}

\chemfig{H_2N-C(-[:90]H)(-[:-90]R)-C(=[:45]O)(-[:-45]OH)}

\end{document}

The second one displays the charged state at physiological pH=7.4. As you can see, the amino group has a positive charge, while the carboxyl group has a negative charge. This state is called a zwitterion.

Amino acid general molecule chemical formula charged

The code for the charged molecule:

\documentclass[varwidth,border={2pt 2pt 4pt 2pt}]{standalone}
\usepackage{chemfig}
\usepackage{amsmath}
\setchemfig{atom sep=2em}
\newcommand{\minusch}{\textcolor{blue}{\charge{80:8pt=$\scriptstyle-$}{}}}
\newcommand{\plusch}{\textcolor{red}{\charge{80:8pt=$\scriptstyle+$}{}}}
\begin{document}

\chemfig{H_3N \plusch -C(-[:90]H)(-[:-90]R)-C(=[:45]O)(-[:-45]O \minusch )}

\end{document}

How to compile this code into SVG? Use this script below. It also deletes font definitions that are no longer used in modern software. You need TeX Live Full installed. Overleaf can also compile, but into PDF. Or you can compile this into PDF with pdflatex.

#!/usr/bin/bash
#This script produces an svg file from the provided tex file.

if [ -z "$1" ]; then
    echo "Usage: $0 filename.tex or filename"
    exit 1
fi

filename="${1%.tex}"

latex $filename.tex
dvisvgm --bbox=papersize $filename.dvi

sed -i '/<font id='"'"'cmr[0-9]\{1,2\}'"'"' horiz-adv-x='"'"'0'"'"'>/,/<\/font>/d' $filename.svg
sed -i '/<font id='"'"'cmsy[0-9]\{1,2\}'"'"' horiz-adv-x='"'"'0'"'"'>/,/<\/font>/d' $filename.svg
sed -i 's/font-family:cmr[0-9]\{1,2\};/font-family:serif;/g' $filename.svg
sed -i 's/font-family:cmsy[0-9]\{1,2\};/font-family:serif;/g' $filename.svg

rm *.aux *.dvi *.log

Page published: March 05, 2026

Tags: biochemistry aminoacids latex shell