summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/quickreaction/quickreaction.sty
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/pgf/contrib/quickreaction/quickreaction.sty')
-rw-r--r--graphics/pgf/contrib/quickreaction/quickreaction.sty99
1 files changed, 99 insertions, 0 deletions
diff --git a/graphics/pgf/contrib/quickreaction/quickreaction.sty b/graphics/pgf/contrib/quickreaction/quickreaction.sty
new file mode 100644
index 0000000000..9aafdc199b
--- /dev/null
+++ b/graphics/pgf/contrib/quickreaction/quickreaction.sty
@@ -0,0 +1,99 @@
+ %% Copyright 2023 Lambertini Francesco
+ %
+ % This work may be distributed and/or modified under the
+ % conditions of the LaTeX Project Public License, either version 1.3
+ % of this license or any later version.
+ % The latest version of this license is in
+ % http://www.latex-project.org/lppl.txt
+ % and version 1.3 or later is part of all distributions of LaTeX
+ % version 2023/04/11 or later.
+ %
+ % This work has the LPPL maintenance status `maintained'.
+ %
+ % The Current Maintainer of this work is Lambertini Francesco.
+ %
+ % This work consists of the files quickreaction.sty, quickreaction.tex and quickreaction.pdf.
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{quickreaction}[2023/04/11]
+
+\RequirePackage{tikz}
+\RequirePackage{xparse}
+
+\usetikzlibrary{matrix}
+\usetikzlibrary{positioning}
+
+\DeclareOption{iupac}{%
+\renewcommand{\printatom}[1]{%
+\fontsize{8pt}{10pt}\selectfont{\ensuremath{\mathsf{#1}}}}
+\setchemfig{
+cram rectangle=false,
+cram width=2.5pt,
+cram dash width=0.5pt,
+cram dash sep=1.5pt,
+atom sep=16pt,
+bond offset=1pt,
+double bond sep=2pt,
+bond join = true,
+bond style={line width=0.5pt}
+}
+}
+\ProcessOptions\relax
+
+\makeatletter
+\newcommand{\settomaxwidth}[1]{\saltyarrow@settomax{\wd}{#1}}
+\newcommand{\saltyarrow@settomax}[3]{%
+\newdimen\pippo
+\pippo=1cm
+ #2\pippo
+ \@for\next:=#3\do{%
+ \sbox\z@{\next}%
+ \ifdim#1\z@>#2%
+ #2=#1\z@
+ \fi}%
+}
+\makeatother
+
+\newlength{\saltyarrowmax}
+
+\newlength{\fixrow}
+
+\NewDocumentEnvironment{quickreaction}{O{} O{} b}{%
+%
+\newbox\fixa
+\newbox\fixb
+\savebox{\fixa}{#1}
+\savebox{\fixb}{#2}
+\def\a{\the\dp\fixa}
+\def\aa{\the\ht\fixa}
+\def\b{\the\dp\fixb}
+\def\bb{\the\ht\fixb}
+\pgfmathsetlength{\fixrow}{(\a+\aa-\b-\bb)/2)}
+%
+\newcommand{\reactionbody}{#3}
+ \begin{tikzpicture}[baseline=(current bounding box.center)]
+ \matrix (reaction) [%
+ ampersand replacement=\&,
+ matrix of nodes,
+ column sep=\pgflinewidth,
+ row sep=\pgflinewidth,
+ nodes={anchor=center},
+ ] {\reactionbody};
+ \end{tikzpicture}%
+ }{}
+
+%\AddToHook{env/quickreaction/begin}{\catcode`\&\active}
+
+\NewDocumentCommand{\quickarrow}{O{} O{}}{%
+\newcommand{\argone}{#1}%
+\newcommand{\argtwo}{#2}%
+\settomaxwidth{\saltyarrowmax}{\argone, \argtwo}%
+\begin{tikzpicture}
+ \draw [-stealth] (-0.5,0) -- node[anchor=center] (X) {} (\the\saltyarrowmax,0);
+ \node (A) [above= 0pt of X] {\argone};
+ \node (B) [below= 0pt of X] {\argtwo};
+ \phantom{ \node (AA) [below= 0pt of X] {\argone};}
+ \phantom{ \node (BB) [above= 0pt of X] {\argtwo};}
+\end{tikzpicture}
+}
+
+