By default, the hyperref package will add a cyan box around a URL:


How can I add such a cyan box around any piece of text that makes it looks like a URL but is not clickable? This box should not show in the printed version. A "demo":

    \fakeurl{any piece of code}

1 Answer 1


Hyperref boxed links are implemented using PDF annotations of subtype /Link. Most PDF viewers recognize this type and change the mouse cursor to the link icon on such an annotation, even if the link target is actually empty. This creates the appearance of being clickable, even if clicking such a 'link' actually does not have any effect when the link target is empty.

There are also other subtypes of annotations. One subtype is /Square, which is defined as follows in the PDF 1.4 reference:

Square and circle annotations (PDF 1.3) display, respectively, a rectangle or an ellipse on the page. When opened, they display a pop-up window containing the text of the associated note.

While at first this does not seem to satisfy the requirement "not clickable", in every PDF viewer that I tried this type of annotation without an action specification is indeed not clickable.

Moreover, you can set various Annotation Flags to the annotation, one of which is ReadOnly (set with /F 64). This flag is described as follows:

If set, do not allow the annotation to interact with the user. The annotation may be displayed or printed (depending on the settings of the NoView and Print flags), but should not respond to mouse clicks or change its appearance in response to mouse motions.

So, presumably (but maybe not), using the subtype /Square with the readonly flag set will convince most PDF viewers to show the box but don't change the mouse cursor or perform any action on click.

Hyperref has a separate definitions file for each compiler and toolchain (pdflatex, xelatex, lualatex, dvips, dvipdfm, ...). The following code is taken from hpdftex.def and is supposed to be used with pdflatex. Modify accordingly for other compilers. The code is copied from the definition of regular hyperlinks (\hyper@linkurl) where I changed the subtype, removed the action specification, and added the readonly flag.

       /F 64%

    \fakeurl{any piece of code}


enter image description here

The second box is not clickable and does not show up when printed for the viewers that I tested (Adobe Reader 9, Evince, Okular, Firefox pdf viewer).

You must log in to answer this question.

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