LaTeX forum ⇒ Math & ScienceTypesetting "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"

Postby chromatic » Thu Sep 27, 2012 10:01 pm

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:

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

Postby localghost » Thu Sep 27, 2012 10:05 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
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ 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

Postby chromatic » Thu Sep 27, 2012 10:19 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.

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

Postby localghost » Thu Sep 27, 2012 10:24 pm

You can define arbitrary units. Try something like this.
  1. \documentclass[11pt]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{siunitx}
  4.  
  5. \DeclareSIUnit{\pH}{pH}
  6.  
  7. \begin{document}
  8. \SI{7}{\pH}
  9. \end{document}
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


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

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Thu Sep 27, 2012 10:47 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:

  1. \documentclass{article}
  2. \usepackage{chemmacros,siunitx}
  3.  
  4. \begin{document}
  5.  
  6. The \pH\ of the solution is $\pH = \num{4.3}$
  7.  
  8. The \pKa of acetic acid is $\pKa = \num{4.7}$
  9.  
  10. \begin{align*}
  11. \Ka \times \Kb &= 10^{-14} \\
  12. \pKa + \pKb &= 14
  13. \end{align*}
  14.  
  15. \end{document}


Regards

BTW: the pH is not a unit! The Green Book again (emphasis by me): “The quantity pH is defined […]”
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

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

Postby chromatic » Thu Sep 27, 2012 11:11 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:

  1. Runaway argument?
  2. {\(\underset {\bool_if:NF \l_chemformula_name_width_bool {\width_to_dim:Nn \ETC
  3. .
  4. ! File ended while scanning use of \NewDocumentCommand.
  5. <inserted text>
  6. \par
  7. l.43 \bool_new:N
  8. \l_chemmacros_version_one_bool
  9. ?
Last edited by cgnieder on Fri Sep 28, 2012 12:38 pm, edited 1 time in total.
Reason: added inline code markup

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Thu Sep 27, 2012 11:14 pm

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

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 3 guests