# makeidx and pdfcomment packages are not working together

I noticed recently that if I'm using pdfcomment package together with makeidx in one document, highlighted comments are not added to the PDF output. for example, you may run the following with LaTeX:

\documentclass[a4paper,12pt,oneside,titlepage]{report}
\usepackage[x11names,table]{xcolor}
\usepackage{makeidx}
\usepackage{pdfcomment}

\makeindex

\begin{document}

\pdfmarkupcomment[author={Oleksandr},subject={test},color=green!25]{I will}{or, maybe not} put here some text, formulas, tables, comments, and some other things.
Here comes a \index{formula} formula.

\clearpage
\phantomsection
\printindex

\end{document}


and see that in the output no comments are added. However, if you comment out lines

\usepackage{makeidx}


and

\clearpage
\phantomsection
\printindex


and re-run the typeset, you will see that comment is now added. Workaround is obvious - first, run the document without makeidx package, and then add it in the end, but it is not very good.

Why is there such behavior of the pdfcomment package and how to fix it?

Edited:

I accept answer of egreg, however, I see some strange behavior of imakeidx in my computer. To illustrate it, I put a picture there, so you can see that sub-entry of the index is not formatted properly.

• It's not makeidx; just a \clearpage command suffices. – egreg Feb 18 '14 at 20:38
• I just tried to comment out \clearpage command in the initial source code, but it did not help. Or, what do you mean? – Oleksandr Feb 18 '14 at 20:44
• if I remove \clearpage and \printindex, then it works. but it still does not solve the issue. – Oleksandr Feb 18 '14 at 20:47
• It's kind of a known problem of soulpos.sty (only used by pdfmarkupcomment - it works e.g. with pdftooltip). Under certain circumstances soulpos.sty only produces its upa files but no upb (with the positions) files, see: tex.stackexchange.com/questions/132973/… and bitbucket.org/kleberj/pdfcomment/issue/13/…. I contacted Javier Be­zos but unfortunately never got a reply. – Josef Feb 18 '14 at 21:06
• Same problem without pdfcomment: \documentclass{report} \usepackage{soulpos} \usepackage[rgb]{xcolor} \ulposdef{\ulflag}{% \mbox{% \color{red}\rule[-.85ex]{.25\ulwidth}{1.5pt}% \color{yellow}\rule[-.85ex]{.5\ulwidth}{1.5pt}% \color{red}\rule[-.85ex]{.25\ulwidth}{1.5pt}}} \begin{document} \ulflag{TestTestTest} \clearpage \end{document} – Josef Feb 18 '14 at 21:27

The problem is quite subtle. If the index has not yet been compiled, the \clearpage command does essentially nothing and there is no next page, so pdfcomment can't complete its job, because no page is shipped out after the one in which the comment is.

Solution: use imakeidx that also avoid the need of a separate run of MakeIndex.

\documentclass[a4paper,12pt,oneside,titlepage]{report}
\usepackage[x11names,table]{xcolor}
\usepackage{imakeidx}
\usepackage{pdfcomment}

\makeindex

\begin{document}

\chapter{X}

\pdfmarkupcomment[
author={Oleksandr},
subject={test},
color=green!25,
]{I will}{or, maybe not}
put here some text, formulas, tables, comments, and some other things.
Here comes a \index{formula} formula.

\printindex

\end{document}


• in this case I'm loosing possibility to use makeidx sub-entries of form \index{formula!variance!way one}. they do not work in the same way in imakeidx. – Oleksandr Feb 18 '14 at 21:05
• @Oleksandr really? – egreg Feb 18 '14 at 21:10
• i tried, and it produces some strange output. with makeidx subentry is placed as it should - under main entry with indentation. with imakeidx it is placed on the same line with main entry. just put \index{formula!test} to your code and typeset it, and you will see. – Oleksandr Feb 18 '14 at 21:19
• @Oleksandr No, I can't see it: “test” is placed below “formula” and indented. You are mistaken by the fact that imakeidx balances the last column. – egreg Feb 18 '14 at 21:44
• @Oleksandr If you don't want the index to have its last column balanced, call \usepackage[original]{imakeidx}; but what you see in that image is no error: it's just that the subentry goes to the second column because of balancing. – egreg Feb 19 '14 at 9:20