Math & ScienceTypesetting "pH"

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

Typesetting "pH"

Post by chromatic »

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

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Typesetting "pH"

Post by localghost »

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
chromatic
Posts: 7
Joined: Thu Sep 27, 2012 9:59 pm

Re: Typesetting "pH"

Post by chromatic »

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.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Typesetting "pH"

Post by localghost »

You can define arbitrary units. Try something like this.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{siunitx}

\DeclareSIUnit{\pH}{pH}

\begin{document}
\SI{7}{\pH}
\end{document}
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Typesetting "pH"

Post by cgnieder »

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:

Code: Select all

\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

Typesetting "pH"

Post by chromatic »

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:

Code: Select all

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.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Re: Typesetting "pH"

Post by cgnieder »

Which version do you have? The newest one is v3.4 released about two weeks ago.

Regards
site moderator & package author
Post Reply