Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Extract from dvipdfmx documentation:

Warning: No annotation will be constructed if the content between pdf:bann and pdf:eann is an empty box.

My MWE (via xelatex):

\documentclass{article}

\begin{document}

\special{pdf:bann << /Subtype /Link
  /BS << /Type /Border /W 0.5 /S /S >>
  /A << /S /URI
    /URI (http://www.tug.org) >> >>}%
http://www.tug.org%
\special{pdf:eann}

\special{pdf:bann << /Subtype /Link
  /BS << /Type /Border /W 0.5 /S /S >>
  /A << /S /URI
    /URI (http://www.tug.org) >> >>}%
\phantom{http://www.tug.org}%
\special{pdf:eann}

\special{pdf:bann << /Subtype /Link
  /BS << /Type /Border /W 0.5 /S /S >>
  /A << /S /URI
    /URI (http://www.tug.org) >> >>}%
\rule{1cm}{1cm}
\special{pdf:eann}

\end{document}

The second and third annotations do not work!

How to make a non-empy box with invisible content?

Subsidiary question: why this limitation?

share|improve this question
2  
With a "not really" empty box it works; for instance the TS1 encoding (\usepackage{textcomp}) has a \textcapitalcompwordmark invisible character and you can put it at the start and end of a box with the right dimensions. When fontenc is loaded, use some invisible character, such as U+00A0. –  egreg Jan 27 '13 at 15:38
add comment

3 Answers

up vote 10 down vote accepted

It seems that annotations require at least a real character, so \phantom or \rule don't do any good.

If you're using "standard" fonts, then you can use the textcomp package that sports a \textcapitalcompwordmark character which is invisible and as high as the capital letters. So

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{textcomp}
\newcommand{\myinvchar}{\textcapitalcompwordmark}

\newcommand{\emptybox}[1]{%
  \sbox0{#1}\makebox[\wd0][s]{\myinvchar\hss\myinvchar}%
}

\begin{document}

X\special{pdf:bann << /Subtype /Link
  /BS << /Type /Border /W 0.5 /S /S >>
  /A << /S /URI
    /URI (http://www.tug.org) >> >>}%
http://www.tug.org%
\special{pdf:eann}X

X\special{pdf:bann << /Subtype /Link
  /BS << /Type /Border /W 0.5 /S /S >>
  /A << /S /URI
    /URI (http://www.tug.org) >> >>}%
\emptybox{http://www.tug.org}%
\special{pdf:eann}X

\end{document}

will produce a "clickable space":

enter image description here

If you're using OpenType fonts via fontspec, an invisible character might be U+00A0:

\newcommand{\myinvchar}{\char\string"00A0 }
share|improve this answer
    
Thanks for these solutions. I need this to complete my ocgx package. Is textcomp solution (\textcapitalcompwordmark) usable in any case? (What do you mean by "standard" fonts?) –  Paul Gaborit Jan 27 '13 at 17:27
    
It seems so. You might want to do also \fontfamily{lmr}\selectfont in the box, in order to avoid spurious messages and do some tricks for adjusting the height. –  egreg Jan 27 '13 at 17:32
    
If I add \usepackage{fontspec} in your code, the height of annotation change. Why? –  Paul Gaborit Jan 27 '13 at 17:38
    
@PaulGaborit That's a good question. Also for the "non empty" box. –  egreg Jan 27 '13 at 17:41
add comment

It seems that you need a character there. If you are using a Unicode font you can use U200B which is a zero width space:

enter image description here

\documentclass{article}
\font\zzz="[lmroman10-regular]" at 10pt

\begin{document}
\zzz

\special{pdf:bann << /Subtype /Link
  /BS << /Type /Border /W 0.5 /S /S >>
  /A << /S /URI
    /URI (http://www.tug.org) >> >>}%
http://www.tug.org%
\special{pdf:eann}


a


\special{pdf:bann << /Subtype /Link
  /BS << /Type /Border /W 0.5 /S /S >>
  /A << /S /URI
    /URI (http://www.tug.org) >> >>}%
\mbox{\strut ^^^^200b\phantom{http://www.tug.org}^^^^200b}%
\special{pdf:eann}



b


\special{pdf:bann << /Subtype /Link
  /BS << /Type /Border /W 0.5 /S /S >>
  /A << /S /URI
    /URI (http://www.tug.org) >> >>}%
 ^^^^200b\rule{1cm}{1cm} ^^^^200b
\special{pdf:eann}

\end{document}
share|improve this answer
    
why is the second box wider? (you said ^^^^200b took up no space). –  jfbu Jan 27 '13 at 16:44
    
@jfbu Because I left a space after the rule before the ^^^^200b. I must have done that on purpose, surely I wouldn't have left in white space by mistake:-) –  David Carlisle Jan 27 '13 at 16:47
    
ok, but I was referring to the phantom one... I must be missing something obvious! –  jfbu Jan 27 '13 at 16:49
    
@jfbu oh I see, no idea:-) –  David Carlisle Jan 27 '13 at 17:20
add comment

From this tugboat article you can use pdf:ann if you want a box taking up no space. I know nothing to all this but just tried:

\documentclass{article}

\begin{document}

A\special{pdf:ann bbox 0 0 12 12 << /Subtype /Link
  /BS << /Type /Border /W 0.5 /S /S >>
  /A << /S /URI
    /URI (http://www.tug.org) >> >>}%
B

\end{document}

And indeed the output contains a clickable box taking up no space (B follows A immediately). (it is as if the clickable area had been done with an rlap).

share|improve this answer
    
You can add \hspace*{12bp} in front of B. Or enclose the \special in \makebox[12bp][l]{...} –  egreg Jan 27 '13 at 16:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.