Debian Codegraph @

texmf-dist/doc/latex/quickreaction/quickreaction.tex

raw
1 %% Copyright 2023 Francesco Lambertini
2 %
3 % This work may be distributed and/or modified under the
4 % conditions of the LaTeX Project Public License, either version 1.3c
5 % of this license or any later version.
6 % The latest version of this license is in
7 % http://www.latex-project.org/lppl.txt
8 % and version 1.3c or later is part of all distributions of LaTeX
9 % version 2023/04/17 or later.
10 %
11 % This work has the LPPL maintenance status `maintained'.
12 %
13 % The Current Maintainer of this work is Francesco Lambertini.
14 %
15 % This work consists of the files quickreaction.sty, quickreaction.tex and quickreaction.pdf.
16 %
17 % v1.02.01 2023/04/17
18 \documentclass{scrarticle}
19 \usepackage[utf8]{inputenc}
20 \usepackage[T1]{fontenc}
21 \usepackage[english]{babel}
22 \usepackage{microtype}
23 \usepackage{siunitx}
24
25 \usepackage{amsmath}
26 \usepackage{amssymb}
27
28 \usepackage[dvipsnames ]{xcolor}
29 \definecolor{unipd}{RGB}{176, 0, 0}
30
31 \usepackage{xparse}
32 \usepackage{tikz}
33 \usepackage{chemfig}
34 \usepackage{mol2chemfig}
35
36 \usepackage[iupac]{quickreaction}
37
38
39 %molecules
40 %C1=COC=C1
41 \newcommand{\furan}{\chemfig{-[:180,,,,dbl={73}{73}]-[:252]O-[:324]-[:36,,,,dbl={73}{73}](-[:108])}}
42 %CC(=O)[Cl]
43 \newcommand{\acetylchloride}{\chemfig{-[:90](=[:150]O)-[:30]Cl}}
44 %CC(=O)C1=CC=CO1
45 \newcommand{\acetylfuran}{\chemfig{-[:294](=[:234]O)-[:354]-[:300,,,,dbl={73}{73}]-[:12]-[:84,,,,dbl={73}{73}]-[:156]O(-[:228])}}
46 %C(CC(=O)OCC)(=O)OCC
47 \newcommand{\diethylmalonate}{\chemfig{-[:30]-[:-30]O-[:30](=[:90]O)-[:-30]-[:30](=[:90]O)-[:-30]O-[:30]-[:-30]}}
48 %4-chlorobenzaldehyde
49 \newcommand{\chlorobenzaldehyde}{\chemfig{O=[:300](-[:-120]H)--[:300,,,,dlh]--[:60,,,,dlh](-Cl)-[:120]-[:180,,,,dlh](-[:240])}}
50 %CC(=O)CC(C1=CC=C(C=C1)Cl)O
51 \newcommand{\clhydroxybutanone}{\chemfig{-[:300](=[:240]O)--[:60](<:[:120,,,2]HO)--[:300,,,,dlh]--[:60,,,,dlh](-Cl)-[:120]-[:180,,,,dlh](-[:240])}}
52 %CC(=O)C
53 \newcommand{\acetone}{\chemfig{-[:30](=[:90]O)-[:-30]}}
54 %C1C[C@H](NC1)C(=O)O
55 \newcommand{\Lproline}{\chemfig{O=[:132](-[:72,,,1]OH)>[:192]-[:138]-[:210]-[:282]-[:354]\mcfbelow{N}{H}(-[:66])}}
56
57
58 \usepackage{listings}
59 \lstset{%
60 columns=fullflexible ,
61 basicstyle=\small\ttfamily,
62 language={[LaTeX]TeX},
63 breaklines=true,
64 frame=single,
65 framexleftmargin=3mm,
66 xleftmargin=3mm,
67 prebreak = {\hbox{\textcolor{gray}{\%}}},
68 backgroundcolor=\color{blue!5},
69 rulecolor=\color{black},
70 morekeywords={printatom, setchemfig, chemfig, arrowlength, quickarrow, fixrow},
71 %keywordstyle=[2]{\color{gray}},
72 %morekeywords=[2]{tikz, xparse, chemfig, quickreaction},
73 moredelim=[is][\ttfamily]{|}{|},
74 literate=*{\&}{{\textcolor{red}{\&}}}{1},
75 keywordstyle=\color[rgb]{0,0,1},
76 commentstyle=\color[RGB]{128,128,128},
77 stringstyle=\color[rgb]{0.627,0.126,0.941}
78 }
79
80 \usepackage{hyperref}
81 \hypersetup{
82 colorlinks=true,
83 urlcolor=ForestGreen,
84 linkcolor=black,
85 }
86
87
88 \begin{document}
89
90 \begin{center}
91 \textbf{\Huge quickreaction}
92
93 \vspace{0.5cm}
94
95 v1.02.01 \hspace{1cm} 2023/04/17
96
97 \vspace{0.5cm}
98
99 Simple and fast way to typeset chemical reactions
100
101 \vspace{0.5cm}
102
103 Francesco Lambertini
104
105 \vspace{0.5cm}
106
107 \href{mailto: [email protected]}{[email protected]}
108 \end{center}
109
110
111 \tableofcontents
112
113 \section{Licence}
114 This work may be distributed and/or modified under the conditions of the \LaTeX~Project Public License, version 1.3c or later. The latest version of this license is at \url{https://www.latex-project.org/lppl.txt}.
115
116 \section{Requirements}
117 \lstinline{quickreaction} needs the packages \href{https://ctan.org/pkg/xparse}{\ttfamily xparse} and \href{https://ctan.org/pkg/tikz-page}{\ttfamily tikz}. It loads tiks libraries \href{https://tikz.dev/library-matrix}{\ttfamily matrix} and \href{https://tikz.dev/tikz-shapes#sec-17.5}{\ttfamily positioning}.
118
119 \section{Motivations}
120 The aim of this package is to provide a simple and fast way to typeset elementary chemical reactions. There are already some packages that provide many and more sophisticated ways to draw all kinds of schemes, but all of them require a lot of effort. When you try to typeset a reaction, problems arise when it is time to align all reactants and, most of all, to align their names. For simple compounds, it is not so difficult to get good results, but for larger molecules, you have to spend a lot of time in order to do it. In addition, there are many commands and environments that provide various types of arrows to use in reaction schemes, but none of them have all the necessary functions: an arrow must extend with the text, support arguments of any type, and have the ability to use parboxes for any numbered indications, which are common in chemistry.
121
122 This package is nothing else than a bunch of macros I used to create reactions in the fastest way when an incoming project is imminent, but I decided to publish it in order to help everyone who gets stuck at first and decides to switch to other programs which, even if they can be powerful reaction setters, often do not match the style of the document with different fonts, graphical styles and blurred images that, when inserted, irremediably compromise the style of the document. A chemist-proof way to create reactions may help to initiate newbies and expand the use of \LaTeX \ in chemistry.
123
124 \section{Options}
125
126 Using \href{https://www.ctan.org/pkg/chemfig}{\ttfamily chemfig} as a chemical structure drawer, the option {\ttfamily iupac} sets the style of bonds following what I have inferred and summarized from the \href{https://iupac.qmul.ac.uk/drawing/drawing.html}{\ttfamily IUPAC reccomendations}. Without this option, the chemfig style will be the standard one. In case you want your own configuration, simply copy and paste the code below in your preamble to change it as you like. You can find the explanation of the terms and more options in the \href{https://ctan.mirror.garr.it/mirrors/ctan/macros/generic/chemfig/chemfig-en.pdf}{\ttfamily chemfig manual}.
127
128 \begin{lstlisting}
129 \renewcommand{\printatom}[1]{%
130 \fontsize{8pt}{10pt}\selectfont{\ensuremath{\mathsf{#1}}}}
131 \setchemfig{
132 cram rectangle=false,
133 cram width=2.5pt,
134 cram dash width=0.5pt,
135 cram dash sep=1.5pt,
136 atom sep=16pt,
137 bond offset=1pt,
138 double bond sep=2pt,
139 bond join = true,
140 bond style={line width=0.5pt}
141 }
142 \end{lstlisting}
143
144 \section{Basic Usage}
145 This package provides the \lstinline{quickreaction} environment and the command \lstinline{\quickarrow}. It is based on the \href{https://tikz.dev/tikz-matrices}{\ttfamily TikZ matrix of nodes} and aligns all the reactants and products at the center of the TikZ box in which they are contained. For most cases, it is a sufficient setting to get good results, but to achieve perfection, one can use many other packages, for example, \href{https://www.ctan.org/pkg/chemfig}{\ttfamily chemfig} itself or \href{https://www.ctan.org/pkg/mychemistry}{\ttfamily mychemistry}. An example is worth more than a thousand words:
146
147 \begin{lstlisting}
148 %Preamble
149 |\usepackage{xparse}
150 \usepackage{tikz}
151 \usepackage{chemfig}
152 \usepackage[iupac]{quickreaction}|
153 %Document
154 \begin{quickreaction}
155 \chemfig{[:30]-(-[:90])=_[:-30]--[:-30]} \& \quickarrow[\chemfig{O_3}][\chemfig{DMS}] \& \chemfig{[:30]-(-[:90])=_[:-30]O} \& + \& \chemfig{O=_[:-30]-[:30]-[:-30]} \\
156 2-methyl-2-pentene \& \& |acetone| \& \& 1-propanone \\
157 \end{quickreaction}
158 \end{lstlisting}
159
160 \begin{center}
161 \begin{quickreaction}
162 \chemfig{[:30]-(-[:90])*6(=-(-[:-30]))} \& \quickarrow[\chemfig{O_3}][\chemfig{DMS}] \& \chemfig{-[:30](=[:90]O)-[:-30]} \& + \& \chemfig{H-[:30](=[:90]O)-[:-30]-[:30]} \\
163 2-methyl-2-pentene \& \& acetone \& \& 1-propanone \\
164 \end{quickreaction}
165 \end{center}
166
167 The structure of the reaction simply follows the TikZ matrix syntax: the separator between cells is \lstinline{\&} and for rows is \lstinline{\\}. I changed the cell separator from the standard \lstinline{&} to \lstinline{\&} to avoid beamer issues.
168
169 The \lstinline{\quickarrow} command has two optional arguments: one for the label above and one for the label below. The minimum arrow length is set at \qty{1}{\centi \m}.
170 \begin{center}
171 \lstinline{\quickarrow[label above][label below]}
172 \end{center}
173
174
175 \section{Advises for Ultra-fast Reaction Typeset}
176
177 As far as I know, with the introduction of this package, the combo \href{https://www.ctan.org/pkg/mol2chemfig}{\ttfamily mol2chemfig} and \lstinline{quickreaction} can lead to the fastest way to draw chemical reactions with \LaTeX. \href{https://www.ctan.org/pkg/mol2chemfig}{\ttfamily mol2chemfig} is a Python program that generates the chemfig code just from the SMILES (Simplified Molecular Input Line Entry System), which can be obtained from any graphical software for drawing molecules or from any online database. The unofficial version available for Python3 is downloadable at \url{https://pypi.org/project/mol2chemfigPy3/}. To obtain the chemfig string, I usually use the command
178 \begin{center}
179 \lstinline{|mol2chemfig -zwf -i direct "SMILES"|}
180 \end{center}
181
182 Once obtained, the chemfig code can be slapped into the \lstinline{quickreaction} environment without any knowledge of what you are doing, but obtaining almost instantly the desired result.
183
184 \section{Examples}
185 Chemfig string can be very long so in the next examples I will create a macro for every compound with a \lstinline{\newcommand} in the preamble in order to keep the environment clean and to focus on the examples aspects.
186
187 \subsection{Labels Aligment}
188 It is common in chemistry to specify the order of multiple separate steps in a reaction.
189
190 \begin{lstlisting}
191 %Preamble
192 |\usepackage{xparse}
193 \usepackage{tikz}
194 \usepackage{chemfig}
195 \usepackage{mol2chemfig}
196 \usepackage[iupac]{quickreaction}|
197
198 %C1=COC=C1
199 \newcommand{\furan}{\chemfig{-[:180,,,,dbl={73}{73}]-[:252]O-[:324]-[:36,,,,dbl={73}{73}](-[:108])}}
200 %CC(=O)[Cl]
201 \newcommand{\acetylchloride}{\chemfig{-[:90](=[:150]O)-[:30]Cl}}
202 %CC(=O)C1=CC=CO1
203 \newcommand{\acetylfuran}{\chemfig{-[:294](=[:234]O)-[:354]-[:300,,,,dbl={73}{73}]-[:12]-[:84,,,,dbl={73}{73}]-[:156]O(-[:228])}}
204
205 %Document
206 \begin{quickreaction}
207 \furan \& + \& \acetylchloride \& \quickarrow[1) \chemfig{BF_3}][2)\chemfig{H_2O}] \& \acetylfuran \\
208 furan \& \& acetyl chloride \& \& 2-acetylfuran \\
209 \end{quickreaction}
210 \end{lstlisting}
211
212 \begin{center}
213 \begin{quickreaction}
214 \furan \& + \& \acetylchloride \& \quickarrow[1) \chemfig{BF_3}][2) \chemfig{H_2O}] \& \acetylfuran \\
215 furan \& \& acetyl chloride \& \& 2-acetylfuran \\
216 \end{quickreaction}
217 \end{center}
218
219 Usually, when there are no steps, arrow labels above and below are centered but when there are multiple steps labels are left aligned, as in a list. In the above example labels are centered by default and the numbers result not correctly aligned. The use of a properly sized \lstinline{\parbox} solves the problem:
220
221 \begin{lstlisting}
222 \begin{quickreaction}
223 \furan \& + \& \acetylchloride \& \quickarrow[\parbox{1.2cm}{1) \chemfig{BF_3}}][\parbox{1.2cm}{2) \chemfig{H_2O}}] \& \acetylfuran \\
224 |furan| \& \& |acetyl chloride| \& \& |2-acetylfuran| \\
225 \end{quickreaction}
226 \end{lstlisting}
227
228 \begin{center}
229 \begin{quickreaction}
230 \furan \& + \& \acetylchloride \& \quickarrow[\parbox{1.2cm}{1) \chemfig{BF_3}}][\parbox{1.2cm}{2) \chemfig{H_2O}}] \& \acetylfuran \\
231 furan \& \& acetyl chloride \& \& 2-acetylfuran \\
232 \end{quickreaction}
233 \end{center}
234
235 \subsection{Multiple Labels}
236 Similarly to the previous example, reactions with multiple consecutive steps can be set using \lstinline{\parbox}.
237
238 \begin{lstlisting}
239 %Preamble
240 |\usepackage{xparse}
241 \usepackage{tikz}
242 \usepackage{chemfig}
243 \usepackage[iupac]{quickreaction}|
244
245 %C(CC(=O)OCC)(=O)OCC
246 \newcommand{\diethylmalonate}{\chemfig{-[:30]-[:-30]O-[:30](=[:90]O)-[:-30]-[:30](=[:90]O)-[:-30]O-[:30]-[:-30]}}
247 \newcommand{\malonicproduct}{\chemfig{HO-[:30](=[:90]O)-[:-30](-[:-90]R_2)-[:30]R_1}}
248 %Document
249 \begin{quickreaction}
250 \diethylmalonate \& \quickarrow[\parbox{1.8cm}{1) \chemfig{OEt^{-}} \\ 2) \chemfig{R_1-Br}}][\parbox{1.8cm}{3) \chemfig{OEt^{-}} \\ 4) \chemfig{R_2-Br} \\ 5) \chemfig{H_3O^{+}}, $\Delta$}] \& \malonicproduct \\
251 diethylmalonate \& \& \\
252 \end{quickreaction}
253
254 \end{lstlisting}
255
256 \begin{center}
257 \begin{quickreaction}
258 \diethylmalonate \& \quickarrow[\parbox{1.8cm}{1) \chemfig{OEt^{-}} \\ 2) \chemfig{R_1-Br}}][\parbox{1.8cm}{3) \chemfig{OEt^{-}} \\ 4) \chemfig{R_2-Br} \\ 5) \chemfig{H_3O^{+}}, $\Delta$}] \& \chemfig{HO-[:30](=[:90]O)-[:-30](-[:-90]R_2)-[:30]R_1} \\
259 diethylmalonate \& \& \\
260 \end{quickreaction}
261 \end{center}
262
263 \subsection{Adjusting Column and Row Spacing}
264 This is only the application of some examples from the \href{https://tikz.dev/tikz-matrices#sec-20.3.2}{\ttfamily Tikz manual}. To adjust the spacing between two specific columns or rows you can add a positive or negative length value as \lstinline{[length]} after \lstinline{\&} for adjusting row spacing or after \lstinline{\\} for adjusting column spacing.
265
266 \begin{lstlisting}
267 %Document
268 \begin{quickreaction}
269 \diethylmalonate \& \quickarrow[\parbox{1.8cm}{1) \chemfig{OEt^{-}} \\ 2) \chemfig{R_1-Br}}][\parbox{1.8cm}{3) \chemfig{OEt^{-}} \\ 4) \chemfig{R_2-Br} \\ 5) \chemfig{H_3O^{+}}, $\Delta$}] \& \malonicproduct \\[-1cm]
270 |diethylmalonate| \& \& \\
271 \end{quickreaction}
272 \end{lstlisting}
273
274 \begin{center}
275 \begin{quickreaction}
276 \diethylmalonate \& \quickarrow[\parbox{1.8cm}{1) \chemfig{OEt^{-}} \\ 2) \chemfig{R_1-Br}}][\parbox{1.8cm}{3) \chemfig{OEt^{-}} \\ 4) \chemfig{R_2-Br} \\ 5) \chemfig{H_3O^{+}}, $\Delta$}] \& \chemfig{HO-[:30](=[:90]O)-[:-30](-[:-90]R_2)-[:30]R_1} \\[-1cm]
277 diethylmalonate \& \& \\
278 \end{quickreaction}
279 \end{center}
280
281 \begin{lstlisting}
282 %Document
283 \begin{quickreaction}
284 \diethylmalonate \&[0.5cm] \quickarrow[\parbox{1.8cm}{1) \chemfig{OEt^{-}} \\ 2) \chemfig{R_1-Br}}][\parbox{1.8cm}{3) \chemfig{OEt^{-}} \\ 4) \chemfig{R_2-Br} \\ 5) \chemfig{H_3O^{+}}, $\Delta$}] \&[0.5cm] \chemfig{HO-[:30](=[:90]O)-[:-30](-[:-90]R_2)-[:30]R_1} \\
285 |diethylmalonate| \& \& \\
286 \end{quickreaction}
287 \end{lstlisting}
288
289 \begin{center}
290 \begin{quickreaction}
291 \diethylmalonate \&[0.5cm] \quickarrow[\parbox{1.8cm}{1) \chemfig{OEt^{-}} \\ 2) \chemfig{R_1-Br}}][\parbox{1.8cm}{3) \chemfig{OEt^{-}} \\ 4) \chemfig{R_2-Br} \\ 5) \chemfig{H_3O^{+}}, $\Delta$}] \&[0.5cm] \chemfig{HO-[:30](=[:90]O)-[:-30](-[:-90]R_2)-[:30]R_1} \\
292 diethylmalonate \& \& \\
293 \end{quickreaction}
294 \end{center}
295
296 \subsection{Auto-adjusting Column Spacing for Large Labels}
297 When the above arrow label is higher than the depth of the deepest molecule, molecules names get shifted down to preserve the symmetry of the entire reaction box.
298 \begin{lstlisting}
299 %Preamble
300 |\usepackage{xparse}
301 \usepackage{tikz}
302 \usepackage{chemfig}
303 \usepackage{mol2chemfig}
304 \usepackage[iupac]{quickreaction}|
305
306 %CC(=O)C
307 \newcommand{\acetone}{\chemfig{-[:90](-[:150])=[:30]O}}
308 %C1=CC(=CC=C1C=O)Cl
309 \newcommand{\chlorobenzaldehyde}{\chemfig{O=[:300](-[:-120]H)--[:300,,,,dlh]--[:60,,,,dlh](-Cl)-[:120]-[:180,,,,dlh](-[:240])}}
310 %C1C[C@H](NC1)C(=O)O
311 \newcommand{\Lproline}{\chemfig{O=[:132](-[:72,,,1]OH)>[:192]-[:138]-[:210]-[:282]-[:354]\mcfbelow{N}{H}(-[:66])}}
312 \newcommand{\clhydroxybutanone}{\chemfig{-[:300](=[:240]O)--[:60](<:[:120,,,2]HO)--[:300,,,,dlh]--[:60,,,,dlh](-Cl)-[:120]-[:180,,,,dlh](-[:240])}}
313
314 %Document
315 \begin{quickreaction}
316 \acetone \& + \& \chlorobenzaldehyde \& \quickarrow[\Lproline] \& \clhydroxybutanone\\
317 acetone \& \& 4-chlorobenzaldehyde \& \& 4-(4-chlorophenyl)-4-hydroxy-2-butanone \\
318 \end{quickreaction}
319 \end{lstlisting}
320
321 \begin{center}
322 \begin{quickreaction}
323 \acetone \& + \& \chlorobenzaldehyde \& \quickarrow[\Lproline] \& \clhydroxybutanone\\
324 acetone \& \& 4-chlorobenzaldehyde \& \& 4-(4-chlorophenyl)-4-hydroxy-2-butanone \\
325 \end{quickreaction}
326 \end{center}
327
328 To replace them at their standard distance, add the deepest molecule and the entire \lstinline{\quickarrow[\Lproline]} as two optional argument of the environment to compute and store the negative shift to apply and specify the stored length with \lstinline{\fixrow}.
329
330 \begin{lstlisting}
331 %Document
332 \begin{quickreaction}[\quickarrow[\Lproline]][\clhydroxybutanone]
333 \acetone \& + \& \chlorobenzaldehyde \& \quickarrow[\Lproline] \& \clhydroxybutanone\\[\fixrow]
334 |acetone| \& \& |4-chlorobenzaldehyde| \& \& 4-(4-chlorophenyl)-4-hydroxy-2-butanone \\
335 \end{quickreaction}
336 \end{lstlisting}
337
338 \begin{center}
339 \begin{quickreaction}[\clhydroxybutanone][\quickarrow[\Lproline]]
340 \acetone \& + \& \chlorobenzaldehyde \& \quickarrow[\Lproline] \& \clhydroxybutanone\\[\fixrow]
341 acetone \& \& 4-chlorobenzaldehyde \& \& 4-(4-chlorophenyl)-4-hydroxy-2-butanone \\
342 \end{quickreaction}
343 \end{center}
344
345 \end{document}