I need to modify the definitions of \item
and of paragraphs
in such a way that a command is inserted automatically at the begin and end thereof.
My use case comes from the necessity of injecting a bounding box annotation into PDF for some text areas. So far I am here with a minimal example:
\usepackage{zref-savepos}
\newcounter{meas}
\def\a{\zsavepos{Start\themeas}\expandafter\pdfannot width \dimexpr\zposx{End\themeas} sp -\zposx{Start\themeas} sp +0.1cm height \dimexpr -0.1cm + \zposy{End\themeas} sp -\zposy{Start\themeas} sp depth 0.0cm {
/Subtype /Square
/Contents (\themeas)
}}
\def\e{\hfill\zsavepos{End\themeas}\stepcounter{meas}}
\begin{document}
\begin{itemize}
\item\a First\e
\item\a Second\e
\item\a Third - a very long line which uses more than one line of the page for some interesting reason.\e
\end{itemize}
\a This \e
\end{document}
```
The remaining problem now is to get the ```\a``` and ```\e``` inserted automatically and not to have to do this manually.
I have not even a clue where to start, as the definition of ```\item``` looks ...umm...strange to me. With paragraphs it is even worse...