% From mitthesis package
% Version: 1.04, 2026/11/16
% Documentation: https://ctan.org/pkg/mitthesis

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% NB: the mhchem and listings packages are not compatible with tagged 
%%     pdf LaTeX formats in TeX Live 2026 and earlier! Fatal errors may 
%%     result from attempting to use pdf tagging with these packages.
%% See: https://latex3.github.io/tagging-project/tagging-status/full

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\chapter{Some additional \LaTeX{} packages}

\section{The \texttt{mhchem} package for chemical equations}

These examples of chemical formul\ae\ are copied from the documentation of the \texttt{mhchem} package, which was used to typeset them.
\begin{gather}
\ce{x Na(NH4)HPO4 ->[\Delta] (NaPO3)_x + x NH3 ^ + x H2O} \\[0.5em]
\ce{^234_90Th -> ^0_-1$\beta${} + ^234_91Pa} \\[0.5em]
\ce{SO4^2- + Ba^2+ -> BaSO4 v} \\[0.5em]
\ce{Zn^2+
<=>[+ 2OH-][+ 2H+]
$\underset{\textrm{amphoteric hydroxide}}{\ce{Zn(OH)2 v}}$
<=>[+ 2OH-][+ 2H+]
$\underset{\textrm{tetrahydroxozincate}}{\ce{[Zn(OH)4]^2-}}$
}
\end{gather}


\section{The \texttt{listings} package for computer code}

This example uses the \texttt{listings} package.

\lstdefinestyle{mystyle}{
    backgroundcolor=\color{CadetBlue!15!white}, % colors are from the xcolor package.
    commentstyle=\color{Red3},
    numberstyle=\tiny\color{gray},
    stringstyle=\color{Blue3},
    basicstyle=\small\ttfamily,
    breakatwhitespace=false,  % default        
    breaklines=true,                 
    numbers=left,                    
    numbersep=5pt,                  
    showspaces=false, % default               
    showstringspaces=false,
    showtabs=false,  % default              
    tabsize=2,
    aboveskip = \bigskipamount,
    keywordstyle=\bfseries\color{Green4},
}%

\begin{lstlisting}[language={[5.3]Lua},style=mystyle]
\begin{luacode*}
function print_rate(kappa,xMin,xMax,npoints,option)
     local function A(z)  -- asymptote of exp(z^2)*erfc(z)
         return (1/z - 1/(2*z^3) + 3/(4*z^5))/1.77245385
     end
     -- erfc() is defined elsewhere
     local c = 1-kappa*kappa
     local croot = math.sqrt(c)
     local psi = 0
     
     local xstep = (math.log(xMax)-math.log(xMin))/(npoints-1)    
     
     if option and option ~= "" then
         tex.sprint("\\addplot+["..option.."] coordinates{") 
         -- addplot+ for color cycle to work
     else
         tex.sprint("\\addplot+ coordinates{")
     end
     
     for i=0, (npoints-1) do
         local x = xMin*math.exp(i*xstep)
         local arg = math.sqrt(x/c)
         local karg = kappa*arg
         -- this test compensates for exp(karg^2), which multiplies the error in the erf approximation...
         if karg<5 then 
            local logpsi = -math.log(croot) + karg^2 + math.log(erfc(karg)-erfc(arg))
            psi = math.exp(logpsi)
         else
            -- this is the large x asymptote of the reaction rate
            psi = (A(karg) - math.exp(-x)*A(arg))/croot
         end
         tex.sprint("("..x..","..psi..")")
     end
     tex.sprint("}")
end
\end{luacode*}
\end{lstlisting}
