## LaTeX forum ⇒ Math & Science ⇒ Typesetting "pH"

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
chromatic
Posts: 7
Joined: Thu Sep 27, 2012 9:59 pm

### Typesetting "pH"

Sorry for asking a mundane question, but it's quite difficult to search for a two letter term.

Should I typeset "pH" in mathmode, or is it ok to use textmode? Technically it's a mathmatical function but I'm not sure...!

Thanks

Tags:

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
In which mode ever you have to typeset it, you should the excellent siunitx package. The units of chemical or physical quantities are always typeset upright. The package will take care of the correct formatting.

Best regards and welcome to the board
Thorsten
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

chromatic
Posts: 7
Joined: Thu Sep 27, 2012 9:59 pm
Thanks localghost.

Turns out I already had siunitx installed - quite new to all this! But, it doesn't seem to recognise "pH" as a unit and I couldn't find any information about it in the instructions [just to check i tried "\si{\meter}" and that works]. I guess I should just leave it as normal text in a paragraph, the paper I'm reading at the moment has it formatted as normal text so I'm sure it's ok.

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
You can define arbitrary units. Try something like this.
\documentclass[11pt]{article}\usepackage[T1]{fontenc}\usepackage{siunitx} \DeclareSIUnit{\pH}{pH} \begin{document}\SI{7}{\pH}\end{document}
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

cgnieder
Site Moderator
Posts: 1993
Joined: Sat Apr 16, 2011 7:27 pm
May I cite the IUPAC Green Book:
The operator p [...] shall be printed in Roman type. (p 103)

That being said, chemmacros offers commands for pH as well as for pKa and pKb and other uses of the p operator:

\documentclass{article}\usepackage{chemmacros,siunitx} \begin{document} The \pH\ of the solution is $\pH = \num{4.3}$ The \pKa of acetic acid is $\pKa = \num{4.7}$ \begin{align*}  \Ka \times \Kb &= 10^{-14} \\  \pKa + \pKb    &= 14\end{align*} \end{document}

Regards

BTW: the pH is not a unit! The Green Book again (emphasis by me): “The quantity pH is defined […]”
site moderator & package author

chromatic
Posts: 7
Joined: Thu Sep 27, 2012 9:59 pm
that looks great cgnieder. Only problem is I keep getting errors when I put \usepackage{chemmacros} in the preamble and I can't figure it out.

Console says:

Runaway argument?{\(\underset {\bool_if:NF \l_chemformula_name_width_bool {\width_to_dim:Nn \ETC.! File ended while scanning use of \NewDocumentCommand.<inserted text>                  \par l.43 \bool_new:N                  \l_chemmacros_version_one_bool?
Last edited by cgnieder on Fri Sep 28, 2012 12:38 pm, edited 1 time in total.

cgnieder
Site Moderator
Posts: 1993
Joined: Sat Apr 16, 2011 7:27 pm
Which version do you have? The newest one is v3.4 released about two weeks ago.

Regards
site moderator & package author