[pdftex] line breaking in pdfannot
Heiko Oberdiek
oberdiek at uni-freiburg.de
Tue Mar 24 16:00:31 CET 2009
On Tue, Mar 24, 2009 at 02:15:02PM +0300, kuzn at htsc.mephi.ru wrote:
> \def\tip#1#2{%
> \pdfannot width 0pt height 0pt depth 0pt {
> /Subtype /Text
> /Open false
> /T (sample)
> /Contents (#1)
> /NM (ctip Text 0)
> }%
> }
>
> used with pdflatex provides the following output in annotation
>
> \tip{a
> b} -> a b
>
> \tip{a\n b} % newline recommended by PDF 1.7
> ! Undefined control sequence.
> <argument> a\n
Manually: \string\n
But be aware, that #1 can contain code that breaks the PDF structure,
e.g. unmatched parentheses. Therefore there is \pdfescapestring.
\def\tip#1#2{%
% keep definition of \n locally
\begingroup
% define \n to be LF with catcode 12
\begingroup
\lccode`\9=10 % (13 for CR)
\lowercase{\endgroup
\def\n{9}%
}%
\pdfannot ...
...
/Contents (\pdfescapestring{#1})
...
\relax
\endgroup
}
If you are using hyperref:
\pdfstringdefDisableCommands{%
\let\n\textLF
}
\newcommand*{\tip}[2]{%
\pdfstringdef\ContentsString{#1}
\pdfannot ...
...
/Contents (\ContentsString)
...
\relax
}
Yours sincerely
Heiko <oberdiek at uni-freiburg.de>
--
More information about the pdftex
mailing list