summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/pdfmarginpar/pdfmarginpar.sty
blob: 94cf991674bb84e6c22369db4183c290e728e43b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
%--------------------------------------------
%
% Package pdfmarginpar.sty
%
% A simple package which allows to create PDF Annotations using
% \pdfmarginpar in the same way as one would use \marginpar. It is
% intended to simplify communication between multiple authors of the
% same document. It has the following features:
% - Easy to use annotation as with \marginpar,
% - Annotations stay in the document,
% - High Quality output using Adobe's Annotations: popup windows,
%   minimize, move etc.
% - File generation is not limited to Acrobat Reader security settings
%
% It relies on pdftex's command \pdfannot. In fact, it is nothing more
% than \pdfannot, some trivial TeX commands and key-value pairs for
% common PDF Annotation variables as they can be found in the public PDF
% Documentation. It is also possible to set low-level pdf options
% directly.
%
% It is not compatible with dvips or dvipdf[m|mx] and friends.
%
% Copyright 2007/2008 by Christian Feuersänger.
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
% 
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
% 
% You should have received a copy of the GNU General Public License
% along with this program.  If not, see <http://www.gnu.org/licenses/>.
%
%--------------------------------------------
\ProvidesPackage{pdfmarginpar}[2011/08/05 Version 0.92]

\RequirePackage{pgfkeys}

\def\pdfmarginparset#{\pgfqkeys{/pdfmarginpar}}

\def\pdfmarginpar@empty{}%

\pgfqkeys{/pdfmarginpar}{
	Subtype/.is choice,
	Subtype/Text/.code={\def\pdfmarginpar@SubType{/Text}},
	Subtype/FreeText/.code={\def\pdfmarginpar@SubType{/FreeText}\pgfkeysalso{Name=none}},
	Subtype/Other/.code={\def\pdfmarginpar@SubType{/#1}},
	Subtype=Text,
	Open/.is choice,
	Open/true/.code={\def\pdfmarginpar@OPEN{true}},
	Open/false/.code={\def\pdfmarginpar@OPEN{false}},
	Open=true,
	FreeText/.style={Subtype/FreeText},
	%
	caption/.code={\def\pdfmarginpar@textlabel{#1}},
	%
	voffset/.initial=0pt,
	hoffset/.initial=0pt,
	%
	width/.initial=,
	height/.initial=,
	depth/.initial=,
	%
	Name/.is choice,
	Name/Comment/.code={\def\pdfmarginpar@NAME{/Comment}},
	Name/Key/.code={\def\pdfmarginpar@NAME{/Key}},
	Name/Note/.code={\def\pdfmarginpar@NAME{/Note}},
	Name/Help/.code={\def\pdfmarginpar@NAME{/Help}},
	Name/NewParagraph/.code={\def\pdfmarginpar@NAME{/NewParagraph}},
	Name/Paragraph/.code={\def\pdfmarginpar@NAME{/Paragraph}},
	Name/Insert/.code={\def\pdfmarginpar@NAME{/Insert}},
	Name/none/.code={\def\pdfmarginpar@NAME{}},
	%
	Comment/.style={Name=Comment,voffset=1.3\baselineskip},
	Key/.style={Name=Key,voffset=\baselineskip},
	Note/.style={Name=Note,voffset=\baselineskip},
	Help/.style={Name=Help,voffset=\baselineskip},
	Paragraph/.style={Name=Paragraph,voffset=\baselineskip},
	Insert/.style={Name=Insert,voffset=0pt,hoffset=-1.5ex},
	NewParagraph/.style={Name=NewParagraph,voffset=0pt,hoffset=-1.5ex,CA=0.7},
	none/.style={},
	%
	Comment,
	C/.initial={[1 1 0]},
	color/.style={C={#1}},
	CA/.initial=0.5,
	opacity/.style={CA={#1}},
	Subj/.store in=\pdfmarginpar@Subj,
	Subject/.style={Subj={#1}},
	Subj={Comment},
	caption=Author's Note,
}

% Usage:
%
% - \pdfmarginpar{All wrong in this place!}
% - \pdfmarginpar{Insert ','}
\newcommand{\pdfmarginpar}[2][]{{%
	\pgfqkeys{/pdfmarginpar}{#1}%
	\toks0={#2}%
	\toks1=\expandafter{\pdfmarginpar@Subj}%
	\toks2=\expandafter{\pdfmarginpar@textlabel}%
	\pgfkeysgetvalue{/pdfmarginpar/voffset}\pdfmarginpar@voffset
	\pgfkeysgetvalue{/pdfmarginpar/hoffset}\pdfmarginpar@hoffset
	\pgfkeysgetvalue{/pdfmarginpar/width}\pdfmarginpar@wd
	\pgfkeysgetvalue{/pdfmarginpar/height}\pdfmarginpar@ht
	\pgfkeysgetvalue{/pdfmarginpar/depth}\pdfmarginpar@dp
	\def\pdfmarginpar@rulespec{}%
	\ifx\pdfmarginpar@wd\pdfmarginpar@empty
	\else
		\expandafter\def\expandafter\pdfmarginpar@rulespec\expandafter{%
			\pdfmarginpar@rulespec
			width \pdfmarginpar@wd\space
		}%
	\fi
	\ifx\pdfmarginpar@ht\pdfmarginpar@empty
	\else
		\expandafter\def\expandafter\pdfmarginpar@rulespec\expandafter{%
			\pdfmarginpar@rulespec
			height \pdfmarginpar@ht\space
		}%
	\fi
	\ifx\pdfmarginpar@dp\pdfmarginpar@empty
	\else
		\expandafter\def\expandafter\pdfmarginpar@rulespec\expandafter{%
			\pdfmarginpar@rulespec
			depth \pdfmarginpar@dp\space
		}%
	\fi
	%
	%\ifvmode\noindent\fi
	\vbox to 0pt{\hsize=0pt
		\vss
		\noindent
		\raise\pdfmarginpar@voffset
		\hbox to 0pt{\vsize=0pt%
			\hskip\pdfmarginpar@hoffset
			\expandafter\pdfannot \pdfmarginpar@rulespec {
				/Subtype	\pdfmarginpar@SubType
				/Open		\pdfmarginpar@OPEN
				\ifx\pdfmarginpar@NAME\pdfmarginpar@empty
				\else
					/Name		\pdfmarginpar@NAME
				\fi
				/T			(\the\toks2)
				/C			\pgfkeysvalueof{/pdfmarginpar/C}
				/CA			\pgfkeysvalueof{/pdfmarginpar/CA}
				/Subj		(\the\toks1)
				/Contents	(\the\toks0)
				/F 4 % print it!
			}%
			\hss
		}%
		%\vss
	}%
}}%