\PassOptionsToPackage{Scale=MatchLowercase,FakeStretch=0.85}{juliamono}
\documentclass[french,english]{pst-doc}
%\usepackage{babel}
%\usepackage{libertinus-otf}
%\usepackage[Scale=MatchLowercase,FakeStretch=0.85]{juliamono}

\usepackage{pst-titration}
\let\TitrationVersion\fileversion
\addbibresource{\jobname.bib}

\usepackage{pst-labo}

\usepackage[autostyle]{csquotes}
\usepackage{minted-code}
\usepackage{xltabular}
\usepackage{booktabs}

%\usepackage[colorlinks]{hyperref}

\newpsstyle{ChampagneSurface}{linecolor=gray,linewidth=2pt,fillstyle=solid,fillcolor=Beige}
\newpsstyle{ChampagneTube}{linecolor=gray,linewidth=2pt,fillstyle=solid,fillcolor=MonGris}
\newpsstyle{BleuCiel}{linecolor=gray,linewidth=2pt,fillstyle=solid,fillcolor=Bluea}
%
\newcommand*\titretab[1]{\multicolumn{1}{c}{\itshape#1}}
\def\Lcs#1{\texttt{\textbackslash#1}}

\title{Acid-Base pH Titration Curves with PSTricks}
\subtitle{Version \TitrationVersion}
%Courbes de titration pH-métrique acide-base avec \textsf{PSTricks}}
\author{Manuel Luque \and Herbert Voß}
%version 0.01\\
%documentation : version 2}
%\parindent=0pt

\begin{document}
\maketitle

\tableofcontents 

\begin{abstract}
This work is based  on the article by Marc Chapelet: B.U.P. No. 668.~\cite{chapelet}

»Titration (also known as titrimetry and volumetric analysis) 
is a common laboratory method of quantitative chemical analysis to 
determine the concentration of an identified analyte (a substance to 
be analyzed).~\cite{clark,koeln}  A reagent, termed the titrant or titrator, is prepared 
as a standard solution of known concentration and volume. 
The titrant reacts with a solution of analyte (which may also be 
termed the titrand[3]) to determine the analyte's concentration. 
The volume of titrant that reacted with the analyte is termed the 
titration volume.«~\cite{wikipedia}
\end{abstract}



\section{Presentation}
Marc Chapelet’s article appeared in the November 1984 issue of the 
»Bulletin de l’Union des Physiciens«.
% it is accessible via the following link:
%\url{https://bupdoc.udppc.asso.fr/consultation/article-bup.php?ID_fiche=8847}
»*Dosage acide-base à l’aide d’un micro-ordinateur« (Acid-Base Titration 
Using a Microcomputer).

%In the first version of \texttt{pst-titration}, I adapted and reproduced 
%his article—with the author’s permission—so one may, if necessary, 
%refer to the documentation for that earlier version.
%This version is no longer compatible with the old one; specifically—even 
%though 
The commands must be enclosed 
within a \verb|\begin{pspicture}(-0.5,-0.5)(16,15)...\end{pspicture}|  environment.
For example:

\begin{codeblockA}[title=Command example]
\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationAB[CA=0.0001,CB=0.0001,VA=8.5,unit=0.8,tangentes=true,pH1=4.5]
\end{pspicture}
\end{codeblockA}


\subsection{Titration of a Strong Acid with a Strong Base}
\subsubsection{The Command}

\begin{codeblockA}[title=The syntax]
\psTitrationAB[options]
\end{codeblockA}

\subsubsection{The parameter}
\begin{xltabular}{\linewidth}{@{}>{\bfseries\sffamily\color{blue}}lccX@{}}\toprule
  \titretab{Option} & \titretab{Type} & \titretab{Default}& \titretab{Description}\\\toprule
  VA      &number   &10& acid volume in mL \\
  CA        &number   &0.1& concentration of the acid solution in mol/L\\
  CB      &number   &0.1& concentration of the base solution in mol/L\\\midrule
  dpH &boolean   &true& plot $\displaystyle\frac{dpH}{dV_B}$\\
  dpHunit  &number   &1& scale factor for $\displaystyle\frac{dpH}{dV_B}$
\\\midrule
  Equivalence      &boolean   &true& marks equivalence point E\\
  valeurs   &boolean    &false & calculates and places the coordinates\\
  tangentes   &boolean  &false& tangents boolean false determines E using the
tangents method and plots the tangents\\
  pH1 &number  &5& pH value for the first tangency point\\
\midrule
  pHstyle     &setting  &redbold& parameter sequence redbold plot style for $\mathrm{pH=f(v_B)}$ \\
  dpHstyle      &setting  &bluenormal &  plot style for the pH derivative with respect to $\mathrm{v_B}$
\\
  tangentesstyle        &  setting &Darkgray& plot style for the tangents
\\\bottomrule
\end{xltabular}

\begin{codeblockA}[title=\Lcs{newpsstyle}]
\newpsstyle{redbold}{linecolor=red,linewidth=1.5\pslinewidth}
\newpsstyle{bluenormal}{linecolor=blue}
\newpsstyle{DarkGray}{linecolor=darkgray}
\end{codeblockA}



\subsection{Titration of a Strong Base with a Strong Acid}
\subsubsection{The command}

\begin{codeblockA}[title=Syntax of \Lcs{psTitrationBA}]
\psTitrationBA[options]
\end{codeblockA}

\subsubsection{Parameters}
These are identical to those for the titration of a strong acid with a strong base; 
the initial value of VB must be specified.


\begin{xltabular}{\linewidth}{@{}>{\bfseries\sffamily\color{blue}}lccX@{}}
  \toprule
  \titretab{Option} & \titretab{Type} & \titretab{Default}
& \titretab{Description}
\\\toprule
  VB      &number   &10& Base volume (in mL) \\
  CA      &number   &0.1& Acid solution concentration (in mol/L)\\
  CB      &number   &0.1& Basic solution concentration (in mol/L)
\\\bottomrule
\end{xltabular}


\subsection{Titration of a Weak Monoacid with a Strong Base}
\subsubsection{The command}

\begin{codeblockA}[title=Syntax of \Lcs{psTitrationAfBF}]
\psTitrationAfBF[options]
\end{codeblockA}


\subsubsection{Parameters}

As with the previous ones, the acid's $\mathrm{pK_A}$ must be specified.

\begin{xltabular}{\linewidth}{@{}>{\bfseries\sffamily\color{blue}}lccX@{}}\toprule
  \titretab{Option} & \titretab{Type} & \titretab{Default}& \titretab{Description}\\\toprule
  VA      &number   &10& Acid volume (in mL)\\
  CA      &number   &0.1& Acid solution concentration (in mol/L)\\
  CB      &number   &0.1& Base solution concentration (in mol/L)\\
  pKA     &number   &4.75& $\mathrm{pK_A}$ of the weak acid\\\bottomrule
\end{xltabular}





\subsection{Titration of a Weak Monobase with a Strong Acid}
\subsubsection{The Command}

\begin{codeblockA}[title=Syntax of \Lcs{psTitrationBfAF}]
\psTitrationBfAF[options]
\end{codeblockA}

\subsubsection{Parameters}

Identical to the previous ones; specify the volume of the base being 
titrated and its corresponding pKB value.

\begin{xltabular}{\linewidth}{@{}>{\bfseries\sffamily\color{blue}}lccX@{}}\toprule
  \titretab{Option} & \titretab{Type} & \titretab{Default}
& \titretab{Description}\\\toprule
  VB      &number   &10& Volume of acid in mL \\
  CA        &number   &0.1& Concentration of the acid solution in mol/L\\
  CB      &number   &0.1& Concentration of the basic solution in mol/L\\
  pKB     &number   &4.75& $\mathrm{pK_A}$ of the weak acid\\
\bottomrule
\end{xltabular}


\subsection{Titration of a Triacid with a Strong Base}
\subsubsection{The command}

\begin{codeblockA}[title=Syntax of \Lcs{psTitrationtriacide}]
\psTitrationtriacide[options]
\end{codeblockA}

\subsubsection{Paremeters}
Identical to the previous ones; specify the volume of the acid being 
titrated and the $\mathrm{pK_A}$ values for the different acidic steps.

\begin{xltabular}{\linewidth}{@{}>{\bfseries\sffamily\color{blue}}lccX@{}}
  \toprule
  \titretab{Option} & \titretab{Type} & \titretab{Default}
& \titretab{Description}\\\toprule
  VA      &number   &10& Volume of acid in mL \\
  CA        &number   &0.1& Concentration of the acid solution in mol/L\\
  CB      &number   &0.1& Concentration of the basic solution in mol/L\\
  pKA1     &number   &2.1& $\mathrm{pK_{A1}}$ \\
  pKA2     &number   &7.2& $\mathrm{pK_{A2}}$ \\
  pKA3     &number   &12& $\mathrm{pK_{A3}}$ \\\bottomrule
\end{xltabular}

\clearpage     


\section{Examples}
\psset{valeurs=true}

\subsection{Titration of a strong acid (molar concentration $C_A$, volume $V_A$) with a 
strong base of concentration $C_B$.}

With  $\mathrm{pH}=f(V_B)$ and
 $\dfrac{\mathrm{dpH}}{\mathrm{d}V_B}=g(V_B)$. $x=[\mathrm{H_3O^+}]$.

\[
V_B=V_A\frac{C_A+\dfrac{K_e}{x}-x}{C_B+x-\dfrac{K_e}{x}}
\]

\begin{codeblockA}[title={$x=[\mathrm{H_3O^+}]$}]
\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationAB[CA=0.0001,CB=0.0001,VA=8.5,tangentes=true,pH1=4.5]
\end{pspicture}
\end{codeblockA}

\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationAB[CA=0.0001,CB=0.0001,VA=8.5,tangentes=true,pH1=4.5]
\end{pspicture}


\begin{codeblockA}[title=with \Lcs{pstDosage}]
\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationAB[CA=0.001,CB=0.001,VA=8.5,unit=0.8,tangentes=true,pH1=4.5]
\end{pspicture}
\hspace{-3cm}\psscalebox{0.5}{%
  \pstDosage[glassType=becher,phmetre=true,niveauReactifBurette=25,niveauLiquide1=40,
             aspectLiquide1=ChampagneSurface]}
\end{codeblockA}

\makebox[\linewidth]{\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationAB[CA=0.001,CB=0.001,VA=8.5,unit=0.8,tangentes=true,pH1=4.5]
\end{pspicture}%
\hspace{-3cm}\raisebox{0.9cm}{\psscalebox{0.45}{%
   \pstDosage[glassType=becher,phmetre=true,niveauReactifBurette=25,niveauLiquide1=40,%
               aspectLiquide1=ChampagneSurface]}}}


At the equivalence point:
\[
V_{B}=\frac{C_A V_A}{C_B}\quad;\quad \mathrm{pH=7}
\]

\subsection{Titration of a strong base of concentration CB and volume VB 
with a strong acid of molar concentration CA.}

With $\mathrm{pH}=f(V_A)$ and
 $\dfrac{\mathrm{dpH}}{\mathrm{d}V_A}=g(V_A)$.
\[
V_A=V_B\frac{\dfrac{K_e}{x}-x-C_B}{x-\dfrac{K_e}{x}-C_A}
\]

\begin{codeblockA}[title=Titration of a strong base]
\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationBA[dpHunit=0.2,CA=0.12,CB=0.08,pH1=11.5,tangentes=true]
\end{pspicture}
\end{codeblockA}

\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationBA[dpHunit=0.2,CA=0.12,CB=0.08,pH1=11.5,tangentes=true]
\end{pspicture}


At the equivalence point:

\[
V_{A}=\frac{C_B V_B}{C_A}\quad;\quad \mathrm{pH=7}
\]


\subsection{Titration of a weak acid—with molar concentration CA and volume VA, 
and whose pKA is given—by a strong base of concentration CB, where $x=[\mathrm{H_3O^+}]$}


 \[
V_B=V_A\frac{\dfrac{C_A}{\dfrac{x}{K_A}+1}+\dfrac{K_e}{x}-x}{C_B+x-\dfrac{K_e}{x}}
\]

\begin{codeblockA}[title=\Lcs{psTitrationAfBF}]
\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationAfBF[pKA=4.75,VA=20,CB=0.1,CA=0.05,dpHunit=0.25,pH1=6,tangentes=true]
\end{pspicture}
\end{codeblockA}

\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationAfBF[pKA=4.75,VA=20,CB=0.1,CA=0.05,dpHunit=0.25,pH1=6,tangentes=true]
\end{pspicture}

At the equivalence point:

\[
V_{B}=\frac{C_A V_A}{C_B}\quad;\quad
pH=7+\frac{1}{2}pK_A+\frac{1}{2}\log\left(\frac{C_A
C_B}{C_A+C_B}\right)
\]

\subsection{Titration of a weak base—of molar concentration $C_B$ and volume $V_B$, 
for which the $\mathrm{pK_B}$
is given with a strong acid of concentration $C_A$.}

 \[
V_A=V_B\frac{\dfrac{C_A}{1+\dfrac{K_e}{xK_B}}-\dfrac{K_e}{x}+x}{C_A+\dfrac{K_e}{x}-x}
\]

\begin{codeblockA}[title=\Lcs{psTitrationBfAF}]
\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationBfAF[pKB=4.75,VB=20,CB=0.01,CA=0.02,dpHunit=0.25,tangentes=true,pH1=8]
\end{pspicture}
\end{codeblockA}

\subsection{pH Variation Curve: Ammonia/Hydrochloric Acid}

{\psset{unit=0.8}
\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationBfAF[pKB=4.75,VB=20,CB=0.01,CA=0.02,dpHunit=0.25,tangentes=true,pH1=8]
\end{pspicture}}

At the equivalence point:

\[
V_{A}=\frac{C_B V_B}{C_A}\quad;\quad
pH=7-\frac{1}{2}pK_B-\frac{1}{2}\log\left(\frac{C_A
C_B}{C_A+C_B}\right)
\]

\subsection{Another example of the titration of a weak acid with a strong base.}
\begin{codeblockA}[title=\Lcs{psTitrationAfBF}]
\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationAfBF[pKA=7.3,VA=20,CB=0.02,CA=0.01,dpHunit=2,pH1=8.5,tangentes=true]
\end{pspicture}
\end{codeblockA}

\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationAfBF[pKA=7.3,VA=20,CB=0.02,CA=0.01,dpHunit=2,pH1=8.5,tangentes=true]
\end{pspicture}
\clearpage

\subsection{Titration of a triacid $\mathrm{AH_3}$ of molar concentration $C_A$ and 
volume $V_A$, with acidity constants $K_{A1}$, $K_{A2}$, and $K_{A3}$ by a 
strong base B of concentration $C_B$}


\[V_B=V_A\frac{C_A\dfrac{\left(1+\dfrac{2K_{A1}}{x}+\dfrac{3K_{A2}K_{A3}}{x^2}\right)}
                                {\left(\dfrac{x}{K_{A1}}+1+\dfrac{K_{A2}}{x}+\dfrac{K_{A2}K_{A3}}{x^2}\right)}
                            + \dfrac{K_e}{x}-x}
                     {x-\dfrac{K_e}{x}+C_B}
\]
\begin{codeblockA}[title=\Lcs{psTitrationtriacide}]
\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationtriacide[VA=5,dpHunit=0.75]
\edn{pspicture}
\end{codeblockA}

\subsection{Determination of Phosphoric Acid using Sodium Hydroxide}

\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationtriacide[VA=5,dpHunit=0.75]
\end{pspicture}

\section{Changing the Graph Paper}
You can redefine the graph paper that was initially defined by:

\begin{codeblockA}[title=\Lcs{graphpaper}]
\newcommand\graphpaper{%
   \psset{gridwidth=1\pslinewidth}
   \psgrid[gridlabels=0,subgriddiv=10,subgridwidth=0.1\pslinewidth,subgridcolor=gray,gridcolor=orange](16,14)%
   \psgrid[gridlabels=0,subgriddiv=2,subgridwidth=0.4\pslinewidth,subgridcolor=orange,gridcolor=orange](16,14)%
   \psset{arrowscale=1.5,arrowinset=0.2}%
   \uput[l](0,14){\cadregris{\textsf{pH}}}%
   \psaxes{->}(16,14)}
\end{codeblockA}

By writing, for example::

\begin{codeblockA}[title=\Lcs{graphpaper}]
\renewcommand\graphpaper{%
   \psgrid[subgridwidth=0.2\pslinewidth,gridlabels=0pt](16,14)%
   \psaxes[arrowscale=1.5,arrowinset=0.2}]{->}(15,14)}[{},0][pH,90]
\end{codeblockA}
%\clearpage

\renewcommand\graphpaper{%
        \psgrid[subgridwidth=0.2\pslinewidth,gridlabels=0pt](16,14)%
        \psaxes[arrowscale=1.5,arrowinset=0.2]{->}(16,14)[{},0][pH,90]}

\begin{codeblockA}[title=\Lcs{psTitrationBfAF}]
\psTitrationBfAF[pKB=5.2,VB=20,CB=0.01,CA=0.02,dpHunit=0.25,tangentes=true,pH1=7.5]%
\end{codeblockA}

{\psset{unit=0.8}
\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationBfAF[pKB=5.2,VB=20,CB=0.01,CA=0.02,dpHunit=0.25,tangentes=true,pH1=7.5]%
\end{pspicture}}


\section{Superimposing different curves}

\renewcommand\graphpaper{%
  \psgrid[gridwidth=0.4pt,
    gridcolor=red!20,%default: black
    griddots=0,%default: 0
    gridlabels=0pt,%default: 10pt
    gridlabelcolor=blue,%default: black
    subgriddiv=5,%default: 5
    subgridwidth=0.2pt,%default: 0.4pt
    subgridcolor=green!20,%default: gray
subgriddots=0%default: 0
](16,14)%
        \psset{arrowscale=1.5,arrowinset=0.2}%
        \uput[-90](16,0){$\cadregris{\mathsf{v_B\,mL}}$}
        \uput[l](0,14){\cadregris{\textsf{pH}}}%
        \psaxes{->}(16,14)}
\begin{codeblockA}[title=\Lcs{psTitrationAfBF}]
\begin{pspicture}(-0.5,-0.5)(16,15)
\psset{pKA=4.75,VA=10,dpH=false,Equivalence=false,pH1=6,tangentes=false}
\psTitrationAfBF[CB=1,CA=1]
\renewcommand\graphpaper{}%
\multido{\i=-1+-1}{4}{%
\psTitrationAfBF[CB=10 \i\space exp,CA=10 \i\space exp]}
\end{pspicture}
\end{codeblockA}

\begin{pspicture}(-0.5,-0.5)(16,15)
\psset{pKA=4.75,VA=10,dpH=false,Equivalence=false,pH1=6,tangentes=false}
\psTitrationAfBF[CB=1,CA=1]
\renewcommand\graphpaper{}%
\multido{\i=-1+-1,\n=0.0+0.2}{4}{%
\newpsstyle{redbold}{linecolor={[hsb]{\n,1,1}},linewidth=2\pslinewidth}
\psTitrationAfBF[CB=10 \i\space exp,CA=10 \i\space exp]}
\uput[r](16,13.4){$\stackrel{\displaystyle C_A=1}{C_B=1}$}
\uput[r](16,12.4){$\stackrel{\displaystyle C_A=0,1}{C_B=0,1}$}
\uput[r](16,11.4){$\stackrel{\displaystyle C_A=10^{-2}}{C_B=10^{-2}}$}
\uput[r](16,10.4){$\stackrel{\displaystyle C_A=10^{-3}}{C_B=10^{-3}}$}
\uput[r](16,9.4){$\stackrel{\displaystyle C_A=10^{-4}}{C_B=10^{-4}}$}
\end{pspicture}

\newpage

\section{Observations on a Graph}

Titration of a 1:10 diluted vinegar solution with a sodium hydroxide solution. 
Demonstration of the buffer region around the half-equivalence point.

\begin{codeblockA}[title=\Lcs{psTitrationAfBF}]
\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationAfBF[CA=0.133333,CB=0.1,VA=10,dpH=false,pKA=4.76,valeurs,tangentes,pH1=6]
\psline[linecolor=blue](0,4.76)(6.66,4.76)(6.66,0)
\uput[l](0,4.76){$pK_A$}
\uput[d](6.66,-0.2){$\mathbf{V_{1/2}}$}
\psframe[fillstyle=hlines,hatchwidth=0.02](5,4.4)(8,4.95)
\end{codeblockA}

\begin{pspicture}(-0.5,-0.5)(16,15)
\psTitrationAfBF[CA=0.133333,CB=0.1,VA=10,dpH=false,pKA=4.76,valeurs,tangentes,pH1=6]
\psline[linecolor=blue](0,4.76)(6.66,4.76)(6.66,0)
\uput[l](0,4.76){$pK_A$}
\uput[d](6.66,-0.2){$\mathbf{V_{1/2}}$}
\psframe[fillstyle=hlines,hatchwidth=0.02](5,4.4)(8,4.95)
\end{pspicture}
\newpage

\section{Marking a curve using only points}

\begin{codeblockA}[title=\Lcs{psTitrationAfBF}]
\begin{pspicture}(-0.5,-0.5)(16,15)
\newpsstyle{despoints}{showpoints,linecolor=red,linewidth=3\pslinewidth}
\psTitrationAfBF[pHstyle=despoints,CA=0.133333,CB=0.12,VA=10,dpH=false,pKA=4.76,
            Equivalence=false,plotpoints=20,linestyle=none,dotstyle=B+]
\end{codeblockA}

\begin{pspicture}(-0.5,-0.5)(16,15)
\newpsstyle{despoints}{showpoints,linecolor=red,linewidth=3\pslinewidth}
\psTitrationAfBF[pHstyle=despoints,CA=0.133333,CB=0.12,VA=10,dpH=false,pKA=4.76,
            Equivalence=false,plotpoints=20,linestyle=none,dotstyle=B+,
            %unit=0.9
]
\end{pspicture}

\printbibliography


\end{document}

