Debian Codegraph @

latex/style/dbk_annot.sty

raw
1 %%
2 %% PDF Text Annotations to handle comments/remarks
3 %%
4 %% This code has been based on the following sources, where other variants can be
5 %% found too:
6 %%
7 %% * http://www.tug.org/pipermail/pdftex/2002-December/003330.html
8 %% * http://www.ce.cmu.edu/~kijoo/latex2pdf.pdf
9 %% * ConTeXt
10 %%
11 %% See also the Adobe PDF Reference directly for the syntax of the Annotation object:
12 %%
13 %% * http://partners.adobe.com/public/developer/en/pdf/PDFReference16.pdf
14 %% (section 8.4 Annotations)
15 %%
16 %% Example of use: \comment[width=5cm,symbol=Balloon,title={Note}]{...}
17 %%
18 \NeedsTeXFormat{LaTeX2e}
19 \ProvidesPackage{dbk_annot}[2006/11/19 v0.1 PDF Text Annotations]
20
21 \@ifundefined{define@key}{\RequirePackage{keyval}}{}%
22
23
24 %% Default text annotation parameter values
25 \let\defaultPDFlocation\empty%
26 \let\defaultPDFopen\empty
27 \let\defaultPDFtitle\empty
28 \let\defaultPDFheight\baselineskip
29 \def\defaultPDFwidth{10cm}
30 \def\defaultPDFdepth{0cm}
31
32 \def\commentdefault{%
33 \let\PDFsymbol\empty%
34 \let\PDFlocation\defaultPDFlocation%
35 \let\PDFtitle\defaultPDFtitle%
36 \let\PDFopen\defaultPDFopen%
37 \let\PDFwidth\defaultPDFwidth%
38 \let\PDFheight\defaultPDFheight%
39 \let\PDFdepth\defaultPDFdepth%
40 }
41
42 %% Set values from key values
43 \def\commentsetsymbol#1{%
44 \expandafter\ifx\csname PDFsymbol#1\endcsname\relax%
45 \else\def\PDFsymbol{/Name \csname PDFsymbol#1\endcsname}\fi}
46
47 \define@key{comment}{symbol}{\commentsetsymbol{#1}}
48 \define@key{comment}{width}{\def\PDFwidth{#1}}
49 \define@key{comment}{height}{\def\PDFheight{#1}}
50 \define@key{comment}{depth}{\def\PDFdepth{#1}}
51 \define@key{comment}{title}{\def\PDFtitle{/T (#1)}}
52 \define@key{comment}{location}{\def\PDFlocation{#1}}
53 \define@key{comment}{open}[true]{%
54 \ifthenelse{\equal{#1}{true}}%
55 {\def\PDFopen{/Open true}}%
56 {\let\PDFopen\empty}%
57 }
58
59 %% Actions to do for default setting
60 \define@key{defcomment}{width}{\def\defaultPDFwidth{#1}}
61 \define@key{defcomment}{height}{\def\defaultPDFheight{#1}}
62 \define@key{defcomment}{depth}{\def\defaultPDFdepth{#1}}
63 \define@key{defcomment}{title}{\def\defaultPDFtitle{/T (#1)}}
64 \define@key{defcomment}{location}{\def\defaultPDFlocation{#1}}
65 \define@key{defcomment}{open}[true]{%
66 \ifthenelse{\equal{#1}{true}}%
67 {\def\defaultPDFopen{/Open true}}%
68 {\let\defaultPDFopen\empty}%
69 }
70
71 %% Text annotation symbols
72 \def\PDFsymbolBalloon {/Comment}
73 \def\PDFsymbolHelp {/Help}
74 \def\PDFsymbolNew {/Insert}
75 \def\PDFsymbolKey {/Key }
76 \def\PDFsymbolAddition {/NewParagraph}
77 \def\PDFsymbolNote {/Note}
78 \def\PDFsymbolParagraph {/Paragraph}
79
80 %% Global comment setup
81 \def\commentsetup#1{\setkeys{defcomment}{#1}}
82
83 %% Insert a remark/comment as a text annotation
84 \def\comment{\@ifnextchar[\docomment{\docomment[]}}
85
86 \def\docomment[#1]#2{%
87 \begingroup%
88 \commentdefault%
89 \setkeys{comment}{#1}%
90 \ifthenelse{\equal{\PDFlocation}{margin}}%
91 {\marginpar{\dodocomment{#2}}}%
92 {\dodocomment{#2}}%
93 \endgroup%
94 }
95
96 \def\dodocomment#1{%
97 \pdfstringdef\@tempa{#1}%
98 \pdfannot width \PDFwidth height \PDFheight depth \PDFdepth{%
99 /Subtype /Text
100 /Contents (\@tempa)
101 \PDFtitle
102 \PDFopen
103 \PDFsymbol
104 }%
105 \let\@tempa\relax%
106 }
107
108 %% Apply only when using pdflatex
109 \RequirePackage{ifpdf}
110 \ifpdf
111 \else
112 \def\docomment[#1]#2{}
113 \fi