Draw Lewis structures like a book

Here are a different versions using different chemistry packages. Which one you want to use is up to you...

  • chemfig, provides \startscheme, \stopscheme, \chemfig, \lewis, \Lewis, \chemname ... ;
  • mhchem, provides \ce{};
  • chemformula, provides \ch{} with the !(<below>)(<formula>) syntax and \chlewis;
  • elements, provides \elconf and \writeelconf.
\documentclass{article}
\usepackage{chemfig}
\usepackage[version=4]{mhchem}
\usepackage{chemformula}
\usepackage{elements}

\newcommand*\pkg[1]{\texttt{#1}}

\begin{document}

\section*{Version 1 -- \pkg{chemfig} and \pkg{mhchem}}
\ce{
  \Lewis{4.,Li} + \Lewis{0.2:4:6:,F}
   ->
  Li+ + \Lewis{0:2:4:6:,F}-
}

\section*{Version 2 -- \pkg{chemfig} and \pkg{elements}}
\schemestart
  \chemname[1.5ex]{\lewis{4.,Li}}{\scriptsize\elconf{Li}}
  \+{1.5em,1.5em}
  \chemname[1.5ex]{\lewis{0.2:4:6:,F}}{\scriptsize\elconf{F}}
  \arrow(.mid east--.mid west)
  \chemname[1.5ex]{Li$^+$}{\scriptsize\writeelconf{2}}
  \+{1em,1em}
  \chemname[1.5ex]{\lewis{0:2:4:6:,F}$^-$}{\scriptsize\writeelconf{2,2+6}}
\schemestop

\section*{Version 3 -- \pkg{chemformula}}
\ch{
  "\chlewis{180.}{Li}" + "\chlewis{0.90:180:270:}{F}"
   ->
  Li+ + "\chlewis{0:90:180:270:}{F}" {}-
}

\section*{Version 4 -- \pkg{chemformula} and \pkg{elements}}
\ch{
  !(\elconf{Li})( "\chlewis{180.}{Li}" ) +
  !(\elconf{F})( "\chlewis{0.90:180:270:}{F}" )
   ->
  !(\writeelconf{2})( Li+ ) +
  !(\writeelconf{2,2+6})( "\chlewis{0:90:180:270:}{F}" {}- )
}

\end{document}

enter image description here


I introduce \lewis with 7 arguments, and I apologize that I don't know the precise naming conventions for chemistry. (EDITED to specify valence in only one place).

Arguments:

#1 Core atom

#2 Top electrons

#3 Right electrons

#4 bottom electrons

#5 left electrons

#6 valence

#7 inner electron shells

\documentclass{article}
\usepackage{stackengine}
\usepackage{graphicx,ifthen}
\begin{document}
\newcommand\lewis[7]{%
  \ifthenelse{\equal{#3}{}}%
    {\def\RHS{}\def\RRHS{\hspace{.5ex}}}%
    {\def\RHS{~\rotatebox{90}{\makebox[1.5ex]{#3}}\,}\def\RRHS{}}%
  \stackengine{5ex}{%
  \rotatebox{90}{\makebox[1.5ex]{#5}}~%
  \stackengine{1.1ex}{%
  \stackengine{2.4ex}{#1}{#2}{O}{c}{F}{F}{L}%
  }{#4}{U}{c}{F}{F}{L}%
  \RHS$^{#6}$\RRHS%
  }{$#7$}{U}{c}{F}{F}{L}%
}
\lewis{Li}{}{}{}{.}{}{1s^22s^1} +
\lewis{F}{..}{.}{..}{..}{}{1s^22s^22p^5}
$\longrightarrow$
\lewis{Li}{}{}{}{}{+}{1s^2}
\lewis{F}{..}{..}{..}{..}{-}{1s^22s^22p^6}
$\quad$(o LiF)
\end{document}

enter image description here