In XeTeX, I would like to include comments such as "LABEL234" into the code of a PDF file, at the current TeX location but neither changing the visual appearance of the document nor changing the text obtained by copy operations.

I first tried \special{pdf:content LABEL234} but this introduced invalid PDF code in the document (and I didn't found any notion of comment inside a BT ... ET flow in the PDF specification).

I then tried to use a very small font and introduce \rlap{\smash{LABEL234}} in font size 0.01pt and white color, this indeed is invisible when previewing, but when I copy-paste the text it appears in the pasted text.

I tried to include "LABEL234" as the name of an image 1pixel.png which contains only a single invisible pixel, using \special{pdf:image @LABEL234 (1pixel.png)} but then in the resulting PDF file I don't get the name of the picture, only the picture.

I need the information to be connected to the page in which the command appears in the TeX file, not to appear in some global dictionary (like XMP metadata comments and the like).

Do you have any idea on how I can sneak this information into the PDF code, so that it is not visible in PDF viewers but it is accessible when reading the PDF code, so that its page can be traced in the PDF file, and so that it does not affect copy-and-paste operations?

Thanks in advance for any hint

  • 1
    what do you mean by "accessible when reading the PDF code"? What is the purpose of the Label? Commented Mar 9 at 14:51
  • Define "invisible"...do you want the comment to show up with copy/paste (you say no)? Do you want it to appear when he mouse is hovered over the special location? Commented Mar 9 at 14:54
  • Invisible: does not appear in previewers, does not affect copy and paste. Accessible: when I read the PDF file as a binary file, moving from the table to the different objects, I can find the text string in some object that is connected to the page in which the surrounding text belongs in the TeX file.
    – yannis
    Commented Mar 9 at 14:56
  • The purpose is to find out in which page something is located. In DVI I was doing it by adding \special{html:LABEL234} commands, these appear exactly at the current location in the DVI file, they do not affect previewing, neither copy and paste. Ideally I would need something similar.
    – yannis
    Commented Mar 9 at 14:58

1 Answer 1


You could an 0-sized annotation or a bmc-Marker:

%bmc marker


The bmc-Marker is then in the stream:

/Label123 BMC EMC

The annotation is recorded in the page resources, and contains the position as rectangle:

<</Type/Annot/Contents (Label123)/Rect[167.253 657.235 167.253 657.235]>>
  • Thanks, I'm testing it. How can I include it inside a TeX macro? When I try \def\try#1{\ExplSyntaxOn \pdfannot_box:nnnn{0pt}{0pt}{0pt}{/Contents~(YHYHYH#1)} \pdf_bmc:n{YHYHYH#1}\pdf_emc: \ExplSyntaxOff} , it doesn't work
    – yannis
    Commented Mar 9 at 15:20
  • \ExplSyntaxOn and Off must be on the outside, around the command, inside they are too late to change catcodes. Commented Mar 9 at 15:21
  • It works like a charm. I have no words to express my gratitude to Ulrike…
    – yannis
    Commented Mar 9 at 20:28

You must log in to answer this question.

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