6

Consider the following example:

\documentclass{article}
\usepackage{pdfcomment}
\begin{document}
  \pdfmarkupcomment[markup=Highlight]{aa}{Highlight}
  \pdfmarkupcomment[markup=Highlight]{AA}{Highlight}
  \pdfmarkupcomment[markup=Highlight]{gg}{Highlight}
  \pdfmarkupcomment[markup=Highlight]{Ag}{Highlight}
\end{document}

The different highlighted markups have different heights. Normally, many pdf reader produce for all three types the latter height.

Can I enforce the usage of a minimal height of the latter sort?

(It should still properly increase height for other non-standard letters like umlauts, e.g. Ä.)

I tried the height option. But this seems not to have an effect on the markup.

ps. You might need to compile a couple of times to see the highlight properly (https://tex.stackexchange.com/q/330276/36836).

2
  • 2
    You can add a \strut: \pdfmarkupcomment[markup=Highlight]{\strut aa}{Highlight} Sep 19, 2016 at 9:50
  • Your comment was faster than my answer! ;-)
    – Josef
    Sep 19, 2016 at 10:05

2 Answers 2

4

You can patch \pdfmarkupcomment so that every appearance of #2 becomes \strut#2

\documentclass{article}
\usepackage{pdfcomment}
\usepackage{regexpatch}

\makeatletter
\xpatchcmd*{\pdfmarkupcomment}
 {#2}
 {\strut#2}
 {}{}
\makeatother

\begin{document}
  \pdfmarkupcomment[markup=Highlight]{aa}{Highlight}
  \pdfmarkupcomment[markup=Highlight]{AA}{Highlight}
  \pdfmarkupcomment[markup=Highlight]{gg}{Highlight}
  \pdfmarkupcomment[markup=Highlight]{Ag}{Highlight}
\end{document}

but beware that this will apply \strut everywhere, not only when some markup comments are near to each other.

Alternative patching:

\documentclass{article}
\usepackage{pdfcomment}
\usepackage{letltxmacro}

\LetLtxMacro\originalpdfmarkupcomment\pdfmarkupcomment
\renewcommand{\pdfmarkupcomment}[3][]{%
  \originalpdfmarkupcomment[#1]{\strut#2}{#3}%
}

\begin{document}
  \pdfmarkupcomment[markup=Highlight]{aa}{Highlight}
  \pdfmarkupcomment[markup=Highlight]{AA}{Highlight}
  \pdfmarkupcomment[markup=Highlight]{gg}{Highlight}
  \pdfmarkupcomment[markup=Highlight]{Ag}{Highlight}
\end{document}

enter image description here

You might use the height of capital letters and the depth of y, but beware that capital letters usually overshoot:

\documentclass{article}
\usepackage{pdfcomment}
\usepackage{letltxmacro}

\LetLtxMacro\originalpdfmarkupcomment\pdfmarkupcomment
\renewcommand{\pdfmarkupcomment}[3][]{%
  \originalpdfmarkupcomment[#1]{%
    \hbox{\vrule height \fontcharht\font`A depth \fontchardp\font`y width 0pt}%
    #2%
  }{#3}%
}

\begin{document}
  \pdfmarkupcomment[markup=Highlight]{aa}{Highlight}
  \pdfmarkupcomment[markup=Highlight]{AA}{Highlight}
  \pdfmarkupcomment[markup=Highlight]{gg}{Highlight}
  \pdfmarkupcomment[markup=Highlight]{Ag}{Highlight}
\end{document}

enter image description here

You can fix the overshoot by using 1.1\fontcharht\font`A and the result would be

enter image description here

and you may want to do similarly for the depth.

4
  • Thanks. The \strut seems to be slightly larger than the extremes letters A and g. Do you happen to know the \rule that would make it exactly the height of the letters?
    – Daniel
    Sep 19, 2016 at 12:01
  • @Daniel You can use \vrule height \fontcharht`A\font depth \fontchardp`y\font width 0pt instead of \strut
    – egreg
    Sep 19, 2016 at 12:50
  • Are you sure this is the correct command? I just get a bunch of errors... Sorry, I was a bit too quick with accepting the answer. The height does not yet match the desired from the question.
    – Daniel
    Sep 19, 2016 at 17:35
  • 2
    @Daniel Yes, I always put \font in the wrong position.
    – egreg
    Sep 19, 2016 at 17:40
3

You can simply use \strut to get the height of a base line. Or define your own \boxheight as in the example. You must define it in a macro without argument, otherwise it will not survive the SOUL parser used by pdfcomment.

\documentclass{article}
\usepackage{pdfcomment}
\newcommand\pdfstrutmc[3][\strut ]%
{%
  \pdfmarkupcomment{#1#2}{#3}%
}%
\newcommand\boxheight{\raisebox{-3pt}{\rule{0pt}{15pt}}}
%
\begin{document}
  \pdfstrutmc{aa}{Highlight}
  \pdfstrutmc{AA}{Highlight}
  \pdfstrutmc{gg}{Highlight}
  \pdfstrutmc{Ag}{Highlight}

  \bigskip
  \pdfstrutmc[\boxheight]{Aa}{Highlight}
  \pdfstrutmc[\boxheight]{AA}{Highlight}
  \pdfstrutmc[\boxheight]{gg}{Highlight}
  \pdfstrutmc[\boxheight]{Ag}{Highlight}
\end{document}

pdfcomment minimal box height

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .