%%
%% This is file `chemobabel-en.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% chemobabel.dtx  (with options: `en')
%% 
%% IMPORTANT NOTICE:
%% 
%% For the copyright see the source file.
%% 
%% Any modified versions of this file must be renamed
%% with new filenames distinct from chemobabel-en.tex.
%% 
%% For distribution of the original source see the terms
%% for copying and modification in the file chemobabel.dtx.
%% 
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
%%
%% This document describes the usage of `chemobabel.sty',
%% a LaTeX package for generating chemical structural formulas
%% using Open Babel and Inkscape.
%%
%% Copyright 2014-2022 Acetaminophen (Hironobu YAMASHITA)
%%   Email   :  h.y.acetaminophen[a t]gmail.com
%%   GitHub  :  https://github.com/aminophen
%%   Blog    :  http://acetaminophen.hatenablog.com/
%%   Twitter :  @aminophen
%%
\documentclass[12pt]{ltjsarticle}
\usepackage[margin=20mm]{geometry}
\usepackage[english]{babel}
\usepackage[nofontspec,defaultsups]{newpxtext}
\usepackage[zerostyle=c,straightquotes]{newtxtt}
\usepackage{newpxmath}
\usepackage{ascmac}
\usepackage[librsvg]{chemobabel}
\usepackage[bookmarksnumbered=true,hidelinks,%
 pdftitle={User Manual for chemobabel.sty},%
 pdfauthor={Hironobu Yamashita (Acetaminophen)},%
 pdfsubject={TeX \& LaTeX Advent Calendar 2014},%
 pdfkeywords={chemistry,open babel,chemdraw,smiles}]{hyperref}
\usepackage{footnotebackref}
\makeatletter
\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
  \sbox\@tempboxa{#1: #2}%
  \global\@minipagefalse
  \hbox to\hsize{\hfil\box\@tempboxa\hfil}%
  \vskip\belowcaptionskip}
\makeatother
\newcount\TestCount
\def\XyM{\ifnum\fam=-1\relax\fam=0\relax\fi\TestCount=\fam
  X\kern-.30em\smash{\raise.50ex\hbox{$\fam\TestCount\Upsilon$}}%
  \kern-.30em{M}}
\def\XyMTeX{\XyM\kern-.1em\TeX}
\def\Lpack#1{\textsf{#1}}
\def\Lcode#1{\texttt{#1}}
\def\Lmeta#1{\textit{#1}}
\def\Lver#1{\Lpack{chemobabel} #1}
\def\TikZ{Ti\textit{k}Z}
\title{\Lpack{chemobabel} \\[1ex]
  \normalsize --- Chemical Structures from MDL Molfiles,
  ChemDraw Files or SMILES Notations --- \\
  }
\author{Hironobu Yamashita (@aminophen)}
\begin{document}
\renewcommand{\figurename}{Fig.\,}
\pagenumbering{roman}
\maketitle

This document (\jobname.pdf) describes the usage of \Lpack{chemobabel.sty},
a \LaTeX\ package for \textbf{generating chemical structural formulas}
to be inserted in your documents.
The formulas can be generated \textbf{from many kinds of chemical data
formats}, including MDL Molfiles, ChemDraw files and even from
SMILES notations, with the help of Open Babel.
The formulas below are generated using this method.\footnote{Unless
otherwise noted, this documentation used \Lcode{\input{obversion.txt}}}

日本語版ドキュメントはchemobabel-ja.pdfを参照してください。

\begin{figure}[ht]
  \centering
  \chemobabel[width=65mm]{draw/Firefly luciferin.mol}{} \quad
  \chemobabel*[width=90mm]{draw/Brevetoxin A.mol}
  \caption{Firefly luciferin \& Brevetoxin A (from MDL Molfiles)}
\end{figure}

\begin{figure}[ht]
  \centering
  \chemobabel[width=80mm]{draw/ATP.cdx}{} \hspace{1cm}
  \chemobabel*[width=30mm]{draw/Glucose.cdx}
  \caption{ATP (Adenosine triphosphate) \& Glucose (from ChemDraw files)}
\end{figure}
\begin{center}\small
Note: with Open Babel 3.1.1 the chemical structure of ATP from the .cdx file
becomes wrong.\\ See \url{https://github.com/openbabel/openbabel/issues/338}
\end{center}

\begin{figure}[ht]
  \centering
  \smilesobabel[width=36mm]{CCO}{} \hspace{1cm}
  \smilesobabel*[width=40mm]{CC(C(=O)O)N} \hspace{1cm}
  \smilesobabel*[width=30mm]{C1[C@H](C)C[C@@H](O)C1}
  \caption{Ethanol, Alanine \& (1\textit{S},3\textit{S})-3-Methylcyclopentanol (from SMILES notations)}
\end{figure}

\begin{figure}[ht]
  \centering
  \smilesobabel*[width=30mm]{CC(=O)Nc1ccc(cc1)O} \hspace{1cm}
  \smilesobabel*[width=40mm]{C([C@@H]1[C@H]([C@@H]([C@H]([C@H](O1)O)O)O)O)O}
  \caption{Acetaminophen (Paracetamol) \& $\alpha$-\textsc{d}-Glucose (from SMILES notations)}
\end{figure}

\begin{figure}[ht]
\centering
This package is maintained on GitHub:\par
\url{https://github.com/aminophen/chemobabel}\par
If you have questions, please let me know.
\end{figure}

\begin{figure}[ht]
\centering
Also available on CTAN:
\url{https://www.ctan.org/pkg/chemobabel}\par
Distributed with \TeX\ Live and MiK\TeX.
Below is a short description for CTAN:\par
\begin{screen}
This package provides a way to convert and include
chemical structure graphics from various chemical formats,
such as ChemDraw files, MDL molfile or SMILES notations
using Open Babel.
To use this \LaTeX\ package, it is necessary to enable execution
of the following external commands via \Lcode{latex -shell-escape}.
\begin{itemize}
 \item \Lcode{obabel} (Open Babel)
 \item \Lcode{inkscape} or \Lcode{rsvg-convert}
   (for SVG -> PDF/EPS conversion)
 \item \Lcode{pdfcrop} or \Lcode{ps2eps}
   (optional; for cropping large margins of PDF/EPS)
\end{itemize}
\end{screen}
\end{figure}

\clearpage
\setcounter{tocdepth}{3}
\tableofcontents

\clearpage
\pagenumbering{arabic}

\section{Introduction}

\subsection{Motivation for Development}

As you already know, \LaTeX\ is being used all over the world.
However, when it comes to drawing chemical strucutral formulas,
ways of inserting formulas into \LaTeX\ documents are very limited.
I think it is mainly due to lack of both reliable and simple methods
of doing this that many of the researchers in chemistry are reluctant
to use \LaTeX\ system.

Some \TeX/\LaTeX\ macros and packages are already available from
\href{http://www.ctan.org/}{CTAN}:
\begin{itemize}
  \item \href{http://www.ctan.org/pkg/xymtex}{\XyMTeX}:
    a set of packages for drawing chemical structural formulas
\item \href{http://www.ctan.org/pkg/chemfig}{\Lpack{chemfig}}:
    a package which draws molecules using \TikZ
\end{itemize}
These packages are reliable and almost all kinds of structural formulas
can be drawn in a consistent way. However, a lot of practice will be
required before one can come to make full use of them.

You can also insert structural formulas with \verb|\includegraphics| of
PDF or EPS files exported from special softwares for chemists, such as
\href{http://www.cambridgesoft.com/Ensemble_for_Chemistry/ChemDraw/}{ChemDraw}
and other similar programs.
In this case, you have to save files in both chemical formats
(such as \verb|.cdx| or \verb|.mol|) and graphical formats
(\verb|.pdf| or \verb|.eps|) manually.

This new package, \Lpack{chemobabel.sty}, will offer a new choice for
chemists who need chemical structures inserted in their \LaTeX\ documents.
In this method, we use \href{http://openbabel.org/}{Open Babel} for
generating chemical structural formulas in SVG format,
and \href{https://inkscape.org/en/}{Inkscape} for converting SVG to PDF/EPS.
Both programs are open source and cross-platform, and being actively maintained.

\paragraph{About Open Babel}

Open Babel is a toolbox specially designed to handle many kinds of
chemical data. It is an open, collaborative project allowing anyone to search,
convert, analyze, or store data from molecular modeling, chemistry,
solid-state materials, biochemistry, or related areas.
See \href{http://openbabel.org/}{Official Website} for detail.

\clearpage

\subsection{Idea and Approach}

First I found a post on Noel O'Blog \cite{NOB1}, \cite{NOB2} and
the comment \cite{JLA} about generating chemical structural formulas
from SMILES notations using Open Babel.
I thought the method described in these posts were very interesting,
but I didn't like all the programs could be executed by
\verb|-shell-escape| option.
At the same time, I encountered a macro for copying all
\verb|\includegraphics| from one source file to another \cite{OKU},
which made me conceive of an idea of extracting minimal source code
which needs \verb|-shell-escape| option.

I thought this method would be applicable to converting ChemDraw files into
graphics, but I could not find any project attempting to realize this idea.
I found a project named
\href{http://chemdrawinlatex.sourceforge.net/}{Chemdraw in \LaTeX}
on Sourceforge, but now it was closed.
This drove me to develop a new package to simplify the process for
inserting chemical structural formulas into \LaTeX\ documents.


\clearpage

\section{Before you begin}

\subsection{Installing dependent softwares}

First, you have to install \href{http://openbabel.org/}{Open Babel} and
\href{https://inkscape.org/en/}{Inkscape}
(or \href{http://librsvg.sourceforge.net/download/}{librsvg}) on your
computer, and export PATH to the required command-line programs,
\Lcode{obabel} and \Lcode{inkscape} (or \Lcode{rsvg-convert}).
The package also uses \Lcode{pdfcrop} (or \Lcode{ps2eps}) to
crop large margins, but it is included in \TeX\ Live.
You can confirm by executing following commands:
In UNIX operating system:
\begin{verbatim}
$ which obabel
$ which inkscape        (if you choose inkscape)
$ which rsvg-convert    (if you choose librsvg)
\end{verbatim}

In Windows operating system:
\begin{verbatim}
> where obabel
> where inkscape        (if you choose inkscape)
> where rsvg-convert    (if you choose librsvg)
\end{verbatim}

And when you get some command echo, installation should be successful.

\subsection{Loading the package}

In the preamble of your document, declare
\begin{verbatim}
\usepackage{chemobabel}
\end{verbatim}
to load \Lpack{chemobabel} package.
The package depends on \Lpack{graphicx}.

\clearpage

\section{Basic Usage}
\label{basic}

\subsection{Conversion from Chemical Structure Data Files}

Suppose you have \verb|ATP.cdx|, a file with chemical structural formula
of ATP (Adenosine triphosphate) drawn in ChemDraw, and
\verb|Brevetoxin A.mol|, a MDL Molfile which can be obtained from
\href{http://www.chemspider.com/}{ChemSpider} (originally \verb|9041092.mol|).

Use \verb|\chemobabel| command as follows. I put original files in a
subdirectory \Lcode{draw}, so added \Lcode{draw/} before the actual filename.
Of course you can put in the same directory with your \LaTeX\ file.

\begin{verbatim}
\chemobabel[width=90mm]{draw/ATP.cdx}{}
\chemobabel*[width=120mm]{draw/Brevetoxin A.mol}
\end{verbatim}

Then, typeset with \verb|-shell-escape| option.
Remember to use this option, otherwise it won't allow \LaTeX\ to
call any external command-line programs, such as obabel and inkscape!
\begin{verbatim}
$ pdflatex -shell-escape test.tex
\end{verbatim}
You will see in \verb|chemobabelimgdir| subdirectory ``chemobabelimg[NUM].pdf'',
and output file test.pdf will be Figure~\ref{fig:chem1}:

\begin{figure}[h]
  \centering
  \chemobabel[width=90mm]{draw/ATP.cdx}{} \\ \vspace{1cm}
  \chemobabel*[width=120mm]{draw/Brevetoxin A.mol}
  \caption{Conversion from ATP.cdx and Brevetoxin A.mol}\label{fig:chem1}
\end{figure}

The syntax is:
\begin{center}
\verb|\chemobabel[|\Lmeta{options}\verb|]{|\Lmeta{filename}\verb|}{|\Lmeta{obabel options}\verb|}| \\
\verb|\chemobabel*[|\Lmeta{options}\verb|]{|\Lmeta{filename}\verb|}|
\end{center}
\verb|\chemobabel| takes one optional parameter and two mandatory parameters.
\begin{itemize}
 \item The optional parameter \Lmeta{options} in the box brackets
   is passed to \verb|\includegraphics|.
   If omitted, the default ``clip,scale=1' is assumed.
 \item The first mandatory parameter \Lmeta{filename} is the file name
   which contains chemical structural formula.
 \item The second mandatory parameter \Lmeta{obabel options}
   is passed to \verb|obabel| command
   (see Section \ref{depict} for some examples).
\end{itemize}
If you want to leave the second parameter empty,
a shorthand form \verb|\chemobabel*| is also available
(since \Lver{v0.9k [2022/10/09]}).

\subsection{Conversion from SMILES Notations}

You can also write SMILES notations directly in your \LaTeX\ file to be
converted into structural formulas.
For example, \verb|CCO| is the SMILES notation of ethanol, and
\verb|CC(=O)Nc1ccc(cc1)O| is that of acetaminophen (paracetamol).
Use \verb|\smilesobabel| command as follows:

\begin{verbatim}
\smilesobabel{CCO}{}
\smilesobabel*[width=25mm]{CC(=O)Nc1ccc(cc1)O}
\end{verbatim}

Again typeset with \verb|-shell-escape| option:
\begin{verbatim}
$ pdflatex -shell-escape test.tex
\end{verbatim}
This time you will get ``smilesobabelimg[NUM].pdf'' and ``test.pdf''
as Figure~\ref{fig:smi1}.
\begin{figure}[h]
  \centering
  \smilesobabel{CCO}{} \quad
  \smilesobabel*[width=25mm]{CC(=O)Nc1ccc(cc1)O}
  \caption{Conversion from SMILES notation}\label{fig:smi1}
\end{figure}

The syntax is:
\begin{center}
\verb|\smilesobabel[|\Lmeta{options}\verb|]{|\Lmeta{SMILES notation}\verb|}{|\Lmeta{obabel options}\verb|}| \\
\verb|\smilesobabel*[|\Lmeta{options}\verb|]{|\Lmeta{SMILES notation}\verb|}|
\end{center}
The only difference from \verb|\chemobabel| is that
\Lmeta{SMILES notation} should be placed in the first braces.
You can put any kinds of SMILES notations in parameters of
\verb|\smilesobabel|, even when they contain some special characters
such as a backslash (\verb|\|) and a percent symbol (\verb|%|).
Similarly, parameters of \verb|\chemobabel| can also contain
these special characters.
\begin{verbatim}
\smilesobabel*[width=28mm]{Cl/C=C/Br}
\smilesobabel*[width=28mm]{Cl/C=C\Br}
\end{verbatim}
\begin{figure}[h]
  \centering
  \smilesobabel*[width=28mm]{Cl/C=C/Br} \quad
  \smilesobabel*[width=28mm]{Cl/C=C\Br}
\end{figure}

\noindent \textbf{Notes for users of earlier versions \Lver{v0.6 [2015/06/29]} or older}

In earlier versions of \Lpack{chemobabel}, it was necessary for users
to pay another attention when using these \LaTeX\ special characters.
However, the workaround I had suggested before was far from desirable
because ``casual \LaTeX\ users'' were forced to change category codes
of these characters manually.

To solve this problem, I improved the internal macros since \Lver{v0.7 [2015/08/26]}.
Now you can put any kinds of SMILES notations directly without worrying
about special characters (\verb|\|, \verb|%|, etc).
Note that the undesirable workaround (like changing \verb|\catcode| inside
\verb|\begingroup| ... \verb|\endgroup|) has now become rather harmful.


\clearpage

\subsection{Package options}

By default, \Lpack{chemobabel} converts chemical structures into
PDF images using Inkscape. However, you can switch the image format
and the conversion program if you like.

When you are using drivers which do not support PDF figures (such as dvips),
it will be helpful if \Lpack{chemobabel} converts them into EPS images.
For this purpose, you can use:
\begin{verbatim}
\usepackage[eps]{chemobabel}
\end{verbatim}
The option \verb|eps| switches the image format
(that is, output format from Inkscape) into EPS (since
\Lver{v0.9d [2016/02/28]}).\footnote{Moreover, since
\Lver{v0.9l [2022/10/22]}, the package automatically switches to
EPS mode when using dvips.}

You can also change the image conversion program from ``Inkscape'' to
``rsvg-convert'' (since \Lver{v0.9e [2016/03/07]}).
The program rsvg-convert is faster than inkscape, so it will be useful.
For this purpose, use \verb|librsvg| option:
\begin{verbatim}
\usepackage[librsvg]{chemobabel}
\end{verbatim}
The default behavior is equivalent to the \verb|pdf| and \verb|inkscape| options:
\begin{verbatim}
\usepackage[pdf,inkscape]{chemobabel}
\end{verbatim}

Moreover, Open Babel v2.4.0 or later versions generate images with
a rather large margin. To avoid this, the images are cropped
using \verb|pdfcrop| for PDF or \verb|ps2eps| for EPS
(since \Lver{v0.9i [2022/09/12]}).
If you want to disable this cropping, please add \verb|nocrop| option:
\begin{verbatim}
\usepackage[nocrop]{chemobabel}
\end{verbatim}

\clearpage

\subsection{For Safer Typesetting...}
\label{extract}

With the basic method described in Section \ref{basic},
you will get desired output in almost any situation.
However, it is sometimes NOT desirable to use \verb|-shell-escape| option,
because with that option \LaTeX\ can call \emph{any} external command-line
programs whether you like it or not.
This means that there is a chance for unknown programs to be executed,
and this can be dangerous especially in case that you don't write your
own \LaTeX\ code. To avoid this problem, I provide a workaround for
extracting all \verb|\chemobabel| and \verb|\smilesobabel| commands
to another \LaTeX\ file (Reference: \TeX\ Forum \cite{OKU}).

All you have to do is to add \verb|extract| option when loading the package:
\begin{verbatim}
\usepackage[extract]{chemobabel}
\end{verbatim}
When typesetting, usual command
\begin{verbatim}
$ pdflatex test.tex
\end{verbatim}
can be used.
With \verb|extract| option, all \Lpack{chemobabel} does is extracting
all \verb|\chemobabel| and \verb|\smilesobabel| commands from the
original \LaTeX\ file.
You will get ``ChemFigFile.tex'' in the current directory, a minimal
\LaTeX\ source file which includes all \verb|\chemobabel| and
\verb|\smilesobabel| commands.
You can simply typeset it by
\begin{verbatim}
$ pdflatex -shell-escape ChemFigFile.tex
\end{verbatim}
and you will get PDF figures in the same way
as described in Section \ref{basic}.
After this, typeset your own document again
(this time you should remove \verb|extract| option):
\begin{verbatim}
$ pdflatex test.tex
\end{verbatim}
This time you will get desired output ``test.pdf''
which includes figures properly.
This method will also save you a lot of time for typesetting.

\paragraph{Note on the option \Lcode{-output-directory}}

When using the option \Lcode{-output-directory} of \TeX,
the extracted code ``ChemFigFile.tex'' goes there
but the subdirectory \verb|chemobabelimgdir| and
generated images stay in the current working directory.
To process the resulting files correctly, it would be
necessary to move files properly.

\clearpage

\section{Advanced Usage}

\subsection{Options for Depiction}
\label{depict}

As I have already mentioned, in both \verb|\chemobabel| and \verb|\smilesobabel|,
you can give some \Lmeta{obabel options} in the second braces.
Here I will introduce some examples.
\begin{itemize}
\item
\begin{verbatim}
\smilesobabel{CC(=O)Nc1ccc(cc1)O}{-xa}
\end{verbatim}
executes a command which gives a formula with all carbon atoms shown:
\begin{verbatim}
$ obabel -:"CC(=O)Nc1ccc(cc1)O" -O smilesobabelimg[NUM].svg -xa
\end{verbatim}
\item
\begin{verbatim}
\smilesobabel{CC(=O)Nc1ccc(cc1)O}{-xu -xC}
\end{verbatim}
gives one without element-specific atom coloring or terminal carbon atoms:
\begin{verbatim}
$ obabel -:"CC(=O)Nc1ccc(cc1)O" -O smilesobabelimg[NUM].svg -xu -xC
\end{verbatim}
\item
\begin{verbatim}
\chemobabel{ATP.cdx}{-xd}
\end{verbatim}
You can add \Lcode{-xd} option to remove filenames from ChemDraw figures with Open Babel 2.x.
\begin{verbatim}
$ obabel -:"ATP.cdx" -O chemobabelimg[NUM].svg -xd
\end{verbatim}
\end{itemize}

\begin{figure}[ht]
  \centering
  \smilesobabel[width=21mm]{CC(=O)Nc1ccc(cc1)O}{} \hspace{1cm}
  \smilesobabel[width=25mm]{CC(=O)Nc1ccc(cc1)O}{-xa} \hspace{1cm}
  \smilesobabel[width=21mm]{CC(=O)Nc1ccc(cc1)O}{-xu}
  \caption{Acetaminophen (Paracetamol): Nothing, \Lcode{-xa}, \Lcode{-xu}}
  SMILES: \verb|CC(=O)Nc1ccc(cc1)O|
\end{figure}

\begin{figure}[ht]
  \centering
  \smilesobabel[width=25mm]{C1[C@H](C)C[C@@H](O)C1}{} \hspace{1cm}
  \smilesobabel[width=25mm]{C1[C@H](C)C[C@@H](O)C1}{-xC} \hspace{1cm}
  \smilesobabel[width=25mm]{C1[C@H](C)C[C@@H](O)C1}{-xt}
  \caption{(1\textit{S},3\textit{S})-3-Methylcyclopentanol: Nothing, \Lcode{-xC}, \Lcode{-xt}}
  SMILES: \verb|C1[C@H](C)C[C@@H](O)C1|
\end{figure}

\begin{figure}[ht]
  \centering
  \smilesobabel[width=42mm]{CCc1cccc(c1)C(=O)Cl}{} \hspace{1cm}
  \smilesobabel[width=42mm]{CCc1cccc(c1)C(=O)Cl}{-xa -xu} \hspace{1cm}
  \smilesobabel[width=42mm]{CCc1cccc(c1)C(=O)Cl}{-xu -xC}
  \caption{3-Ethylbenzoyl chloride: Nothing, \Lcode{-xa -xu}, \Lcode{-xu -xC}}
  SMILES: \verb|CCc1cccc(c1)C(=O)Cl|
\end{figure}

\begin{figure}[ht]
  \centering
  \smilesobabel[width=42mm]{CCc1cccc(c1)C(=O)Cl}{--highlight "cC=O blue"} \hspace{1cm}
  \smilesobabel[width=42mm]{CCc1cccc(c1)C(=O)Cl}{-xA --genalias}
  \caption{3-Ethylbenzoyl chloride: \Lcode{--highlight "cC=O blue"}, \Lcode{-xA --genalias}}
  SMILES: \verb|CCc1cccc(c1)C(=O)Cl|
\end{figure}

\begin{figure}[ht]
  \centering
  \chemobabel[width=65mm]{draw/Firefly luciferin.mol}{} \hspace{1cm}
  \chemobabel[width=65mm]{draw/Firefly luciferin.mol}{-xa}
  \caption{Firefly luciferin (from MDL Molfiles): Nothing, \Lcode{-xa}}
\end{figure}

\begin{figure}[ht]
  \centering
  \chemobabel[width=70mm]{draw/ATP.cdx}{} \hspace{1cm}
  \chemobabel[width=70mm]{draw/ATP.cdx}{-xd}
  \caption{ATP (from ChemDraw files): Nothing, \Lcode{-xd}}
\end{figure}

\begin{figure}[ht]
For more details, see
\href{http://openbabel.org/docs/dev/Command-line_tools/babel.html}{obabel and babel}
and
\href{http://openbabel.org/docs/dev/FileFormats/SVG_2D_depiction.html}{SVG depiction (svg)}
in Open Babel documentation.
\end{figure}

\clearpage

\subsection{More complex structural formulas}

Open Babel can generate more complex structural formulas from SMILES notations.

\begin{figure}[ht]
  \centering
  \smilesobabel*[width=55mm]{CN1CC[C@]23c4c5ccc(c4O[C@H]2[C@H](C=C[C@H]3[C@H]1C5)O)O}
  \caption{($-$)-Morphine}
  SMILES: \verb|CN1CC[C@]23c4c5ccc(c4O[C@H]2[C@H](C=C[C@H]3[C@H]1C5)O)O|
\end{figure}

\begin{figure}[ht]
  \centering
  \smilesobabel*[width=150mm]{C[C@@H]1C[C@H]2[C@@H](CC(=O)O2)O[C@H]3C[C@@H]4[C@H](C[C@@H]([C@@H]5[C@@H](O4)C/C=C\C[C@@H]6[C@@H](O5)C/C=C\[C@@H]7[C@@H](O6)CCC[C@@H]8[C@@](O7)(C[C@@H]9[C@@H](O8)C[C@@H]2[C@@H](O9)[C@H](C[C@H](O2)CC(=C)C=O)O)C)C)O[C@@]3(C1)C}
  \caption{Brevetoxin A}
  SMILES (Sorry but too long): \verb|C[C@@H]1C[C@H]2[C@@H](CC(=O)O2)O[C@H]3C[C@@H]4[C@H](C[C@@H]([C@@H]5[C@@H](O4)C/C=C\C[C@@H]6[C@@H](O5)C/C=C\[C@@H]7[C@@H](O6)CCC[C@@H]8[C@@](O7)(C[C@@H]9[C@@H](O8)C[C@@H]2[C@@H](O9)[C@H](C[C@H](O2)CC(=C)C=O)O)C)C)O[C@@]3(C1)C|
\end{figure}

However, the results are sometimes undesirable and may also be
different depending on version numbers.
Here are some examples:

\clearpage

\begin{figure}[p]
Cephalostatin-1 (Example from \href{http://en.wikipedia.org/wiki/Simplified_molecular-input_line-entry_system}{Wikipedia}): \\
\verb|C[C@@](C)(O1)C[C@@H](O)[C@@]1(O2)[C@@H](C)[C@@H]3CC=C4[C@]3(C2)C(=O)C[C@H]5[C@H]4CC[C@@H](C6)[C@]5(C)Cc(n7)c6nc(C[C@@]89(C))c7C[C@@H]8CC[C@@H]%10[C@@H]9C[C@@H](O)[C@@]%11(C)C%10=C[C@H](O%12)[C@]%11(O)[C@H](C)[C@]%12(O%13)[C@H](O)C[C@@]%13(C)CO|
\begin{center}
  \includegraphics[scale=0.85]{figures/Mac231-Cephalostatin-1.pdf}
  \caption{Cephalostatin-1 (figure from Open Babel for Mac 2.3.1)}
  \includegraphics[scale=0.5]{figures/Win232-Cephalostatin-1.pdf}
  \caption{Cephalostatin-1 (figure from Open Babel for Win 2.3.2)}
\end{center}
\end{figure}

\begin{figure}[p]
Sesamin: \verb|c1cc2c(cc1C3C4COC(C4CO3)c5ccc6c(c5)OCO6)OCO2|
\begin{center}
  \centering
  \includegraphics[scale=0.5]{figures/Mac231-sesamin-normal.pdf}
  \includegraphics[scale=0.5]{figures/Mac231-sesamin-gen2d.pdf}
  \caption{Sesamin (figures from Open Babel for Mac 2.3.1; Normal and \Lcode{--gen2d})}
  \includegraphics[scale=0.5]{figures/Win232-sesamin-normal.pdf}
  \includegraphics[scale=0.5]{figures/Win232-sesamin-gen2d.pdf}
  \caption{Sesamin (figures from Open Babel for Win 2.3.2; Normal and \Lcode{--gen2d})}
\end{center}
\end{figure}

\clearpage

Also, Open Babel may generate wrong structures from SMILES notations.
Here we can see the formula generated from a SMILES notation lacks one double bond.
\begin{figure}[ht]
  \centering
  \includegraphics[scale=0.6]{figures/Exact-FireflyLuciferin.pdf}
  \caption{Firefly luciferin: exact structure from ChemSpider ID 4588411}
  \includegraphics[scale=0.6]{figures/Win232-FireflyLuciferin.pdf}
  \caption{Firefly luciferin?: output from Open Babel for Win 2.3.2}
  \smilesobabel*[width=66mm]{C1[C@@H](N/C(=c\2/nc3c(=CC(=O)C=C3)s2)/S1)C(=O)O}
  \caption{Firefly luciferin?: output from current Open Babel}
  SMILES: \verb|C1[C@@H](N/C(=c\2/nc3c(=CC(=O)C=C3)s2)/S1)C(=O)O|
\end{figure}

We can avoid all these problems by using \verb|\chemobabel| with \verb|.mol| or
\verb|.cdx| files, instead of \verb|\smilesobabel|.
However, the fact that many complex structures can be generated from
only one character string is very interesting, isn't it?

\clearpage

\section{Note for Compatibility}

\subsection{Advantages of \Lpack{chemobabel}}

The macros \verb|\smiles| (written by Noel O'Boyle \cite{NOB1}) and
\verb|\obabel| (depends on \Lpack{graphvizObabel.sty} by
Jakob Lykke Andersen's \cite{JLA}) can be used as follows:
\begin{verbatim}
%% ----- for \smiles command -----
\newcounter{smilescounter}
\setcounter{smilescounter}{1}
\newcommand{\smiles}[1]{
  \immediate\write18{obabel -:"#1" -O smilesimg\arabic{smilescounter}.png}
  \includegraphics{smilesimg\arabic{smilescounter}.png}
  \addtocounter{smilescounter}{1}
}
 ...
\smiles{CCO}
%% -----
\end{verbatim}
\begin{verbatim}
%% ----- for \obabel command -----
\usepackage{graphvizObabel}
 ...
\obabel[scale=0.6]{CCO}
%% -----
\end{verbatim}
However, \verb|\smiles| command creates raster graphics (.png) and
has no options to pass to \verb|\includegraphics|, and \verb|\obabel| command
sometimes does not work because of lack of file extension (.pdf) and
possibility of giving errors with empty optional parameters.
These problems are solved in \verb|\smilesobabel|.

\clearpage

\section{Limitations and Alternatives}

This method relies on Open Babel for generating structural formulas,
even without drawing anything by yourself.
Of course you can modify and customize these structures to some extent,
but this method will not be suitable for fine control of the output.
Also, computer-generated formulas may sometimes be unnatural and undesirable.
Therefore this method will be useful only when you need a simple method
for inserting structural formulas with minimal modification.
If you are not satisfied with the output, consider using {\XyMTeX} or
\Lpack{chemfig} packages instead.

I also found following packages which can be used for similar purpose:
\begin{itemize}
  \item \href{http://www.ctan.org/pkg/mol2chemfig}{\Lpack{mol2chemfig}}:
    convert chemical structures from MDL molfile format
    to \Lpack{chemfig} source code
\end{itemize}

\clearpage

\section{Technical information}
\label{detail}

According to
\href{http://www.daylight.com/meetings/summerschool98/course/dave/smiles-intro.html}{SMILES Tutorial},
special characters are used in SMILES syntax are the followings:
\begin{itemize}
\item Roman alphabets: \verb|A-Z|, \verb|a-z|
\item Numbers: \verb|1-10|
\item Brackets: \verb|[ ] ( )|
\item Others:
\begin{itemize}
\item \verb|*| (unspecified atomic number)
\item \verb|.| (disconnection)
\item \verb|+| (charge sign)
\item \verb|-| (single bond or charge sign)
\item \verb|=| (double bond)
\item \verb|#| (triple bond)
\item \verb|$| (quadruple bond)
\item \verb|:| (aromatic bond)
\item \verb|%| (used when more than 10 ring closures)
\item \verb|/|, \verb|\| (configuration around double bonds)
\item \verb|@| (tetrahedral chirality)
\item \verb|>| (reaction)
\end{itemize}
\end{itemize}

It is important to prevent these characters from being translated as
\LaTeX\ special characters.
However, a backslash (\verb|\|) is a default escape character in \LaTeX,
and a percent symbol (\verb|%|) also has a special meaning as a comment character.
In \Lpack{chemobabel} (higher than v0.7), all these characters are
handled properly by changing category codes temporarily (like \verb+\verb+). \\

\clearpage

\section{Version History}

\begin{table}[h]
\centering
\begin{tabular}{ll}
2014/12/01 v0.1  & Made public as \Lpack{smilesobabel.sty} \\
2014/12/02 v0.2  & Add options which can be passed to obabel. \\
2014/12/07 v0.3  & Change name of package: \Lpack{chemobabel.sty} \\
                 & Images are stored in \Lcode{chemobabelimgdir}. \\
                 & Add \verb|\chemobabel| command. \\
2014/12/09 v0.4  & Fix a bug: (Thanks: Yusuke Terada) \\
                 & Extra spaces at the end of lines are removed. \\
2014/12/20 v0.5  & Add \verb|extract| option. \\
2015/06/29 v0.6  & Improve warning messages. \\
2015/08/26 v0.7  & Solve \verb|\catcode|-related problems in \verb|\smilesobabel|. \\
2015/08/27 v0.8  & Improve \verb|\smilesobabel| a little. \\
2015/08/28 v0.9  & Improve \verb|\smilesobabel|: (Thanks: ZR) \\
                 & Exclude $\varepsilon$-\TeX\ dependency. \\
2015/08/29 v0.9a & Improve \verb|\chemobabel| a little. \\
2016/01/06 v0.9b & Support Lua\TeX-0.85.0 and later versions. \\
2016/02/09 v0.9c & Fix a bug; forgotten in v0.9b. \\
2016/02/28 v0.9d & Add \verb|eps| and \verb|pdf| options. \\
2016/03/07 v0.9e & Add \verb|librsvg| and \verb|inkscape| options. \\
2016/10/23 v0.9f & Incorporate \verb|extract| option into main package. \\
2018/01/23 v0.9g & Minor refactor of code. \\
2022/09/11 v0.9h & Support Inkscape version 1.0 command line syntax. \\
2022/09/12 v0.9i & Crop images before inclusion, add \verb|nocrop| option. \\
2022/09/19 v0.9j & Check shell-escape status to show better error message. \\
                 & This is the first release on CTAN! \\
2022/10/09 v0.9k & Add \verb|\chemobabel*| and \verb|\smilesobabel*|. \\
                 & Warn if a user need to run another \LaTeX. \\
                 & Improve \verb|[extract]| to take over user-given package options. \\
2022/10/22 v0.9l & Default to EPS mode if PDF inclusion is unsupported by the driver. \\
                 & Default \verb|clip| for image inclusion. \\
\end{tabular}
\end{table}

\textbf{Important!}
\begin{itemize}
\item In Version 0.2, the number of parameters set in \verb|\smilesobabel| is changed!
\item From Version 0.3, the package name is changed to \Lpack{chemobabel.sty}.
\item From Version 0.7, the \verb|\catcode|-related workaround is rather harmful.
\end{itemize}

\clearpage

\begin{thebibliography}{9}
\bibitem{NOB1}
\href{http://baoilleach.blogspot.jp/2012/03/cheer-up-your-latex-with-smiles-support.html}{Cheer up your \LaTeX\ with SMILES support} -- Noel O'Blog
\bibitem{NOB2}
\href{http://baoilleach.blogspot.jp/2012/04/cheer-up-your-latex-with-smiles-support.html}{Cheer up your \LaTeX\ with SMILES support II} -- Noel O'Blog
\bibitem{JLA}
\href{http://imada.sdu.dk/~jlandersen/}{\LaTeX: Graphviz and OpenBabel} -- Jakob Lykke Andersen
\bibitem{OKU}
\href{http://oku.edu.mie-u.ac.jp/tex/mod/forum/discuss.php?d=1411}{文章内の画像のみを表示する方法} -- \TeX\ Forum \\
(How to extract only figures in \LaTeX\ source)
\bibitem{ACE1}
\href{http://acetaminophen.hatenablog.com/entry/2014/11/02/130624}{化学構造式を\TeX で(1)：自動化による簡単生成} -- Acetaminophen's diary \\
(Chemical Structural Formula in \LaTeX\ (1): An Easy Method by Auto-generation)
\bibitem{ACE2}
\href{http://acetaminophen.hatenablog.com/entry/2014/11/02/130624}{化学構造式を\TeX で(2)：自動化の注意点と解消法} -- Acetaminophen's diary \\
(Chemical Structural Formula in \LaTeX\ (2): Important Notes for Auto-generation and Solution)
\bibitem{ACE3}
\href{http://acetaminophen.hatenablog.com/entry/2014/11/05/135927}{化学構造式を\TeX で(3)：補足事項} -- Acetaminophen's diary \\
(Chemical Structural Formula in \LaTeX\ (3): Supplement)
\end{thebibliography}

\noindent
\textbf{Note}: \href{http://acetaminophen.hatenablog.com/}{Acetaminophen's diary} is my own blog! (Sorry, but only in Japanese)

I added a post about this package on the 8th day of \href{http://www.adventar.org/calendars/553}{\TeX\ \& \LaTeX\ Advent Calendar 2014} (in Japanese):
\begin{itemize}
\item \href{http://acetaminophen.hatenablog.com/entry/2014/12/08/053519}{誰でも簡単！ 化学構造式を\LaTeX に取り込むパッケージ} -- Acetaminophen's diary \\
(An easy way to insert chemical structural formulas into \LaTeX\ documents)
\end{itemize}

\end{document}
\endinput
%%
%% End of file `chemobabel-en.tex'.
