[Tex/LaTex] How to use `\texorpdfstring`. Characters disappear

bookmarkshyperrefmath-modesectioning

I'm using hyperref, which causes trouble when having math in my section title.

MWE:

\documentclass{report}
\usepackage{hyperref}
\usepackage{fixltx2e}
\begin{document}
\section{Basis for CO\texorpdfstring{\textsubscript{2}{ h}} heat}
\section{Basis for CO\texorpdfstring{\textsubscript{2}} heat}
\section{Basis for CO\texorpdfstring{$_2$} heat}
\end{document}

The first text line will be displayed correctly, but why do I have to add { h} (I know this is not the correct solution, but it works)? If I don't, the space and the h will disappear. I found out that I had to add it by trial and error. How should this be done?

Best Answer

\texorpdfstring has two arguments, the first is the normal TeX code, the second is a string, which can be used as replacement for the arbitrary TeX in the bookmarks.

If option unicode (or pdfencoding=auto) is enabled, then the subscript 2 is available as \texttwoinferior:

\documentclass{report}
\usepackage[pdfencoding=auto]{hyperref}
\usepackage{bookmark}% faster updated bookmarks
\begin{document}
\section{Basis for
  CO\texorpdfstring{\textsubscript{2}}{\texttwoinferior} heat}
\end{document}