summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/interaction/interaction-attachments.tex
blob: 6ae9b63103c8959719f2b96c3f0d135bb4193e37 (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
162
163
164
165
166
167
168
169
170
171
172
173
174
% language=uk

% Written while intermittently watching those always positive "Walk off the Earth"
% videos to keep me in the mood. They make what's normally not my kind of music
% into something very interesting. I hope that this chapter is kind of interesting
% in the end too.

\environment interaction-style

\enabletrackers[attachments.anchors]

\setupattachment
  [location=inmargin]

\startcomponent interaction-attachments

\startchapter[title=Attachments]

Attachments are (normally) embedded files that the reader can extract. A viewer
can decide to just show the content or call an associated program to deal with
the file (which one depends on the operating system). As with other annotations
they started out depicted by symbols but then browsers started showing them in
lists next to the displayed page.

\startbuffer
\attachment
  [attachment 1]
  [file=interaction-attached-001.txt,
   title=Just some text,
   width=2em,
   height=2em,
   author=Hans,
   subtitle=Plain text]

\attachment
  [attachment 2]
  [file=cow.mp,
   title=Just a graphic,
   author=Hans,
   subtitle=Some MetaPost,
   method=hidden]
\stopbuffer

\typebuffer \getbuffer

These two attachments differ in one aspect: the second one is hidden, i.e. it has
no icon in the text. However, the attachment is in the file and is (often)
visible in the side bar. The symbol for the visible one is in the margin, which
is achieved with:

\starttyping
\setupattachment
  [location=inmargin]
\stoptyping

You can use your own icon, for instance:

\startbuffer
\startuniqueMPgraphic{cow}{height,s:color}
    loadfigure "cow.mp" number 1 ;
    refill currentpicture withcolor "\MPvar{color}"    ;
    currentpicture := currentpicture ysized \MPvar{height} ;
\stopuniqueMPgraphic

\definesymbol
  [attachment-normal]
  [\uniqueMPgraphic{cow}{height=4ex,color=darkblue}]
\definesymbol
  [attachment-down]
  [\uniqueMPgraphic{cow}{height=4ex,color=darkyellow}]
\stopbuffer

\typebuffer \getbuffer

% \startattachment[hello][symbol={attachment-normal,attachment-down}]
%     oeps
% \stopattachment

\attachment
  [symbol={attachment-normal,attachment-down},
   file=cow.pdf,
   title=A cow,
   author=Hans,
   subtitle=graphic]

This time we get a cow as icon and the cow is also embedded as image. When
writing this manual a click in Sumatra just opens the \PDF\ file, but when I
embed an mp3 file, a save-as window pops up.

The previous examples directly injected the attachment using the \type
{\attachment} commands with the appropriate arguments. You can add titles, define
a name that will be used when the attachment is saved:

\starttyping
\attachment[sometag][extra specs]
\attachment[test.tex]
\attachment[file=test.tex]
\attachment[file=test.tex,method=hidden]
\attachment[name=newname,file=test.tex]
\attachment[title=mytitle,name=newname,file=test.tex]
\stoptyping

but there's also a more indirect way, for instance here we define some
attachments:

\starttyping
\defineattachment[whatever-1][file=test.tex]
\defineattachment[whatever-2][file=test.tex,method=hidden]
\stoptyping

that later can be called up with:

\starttyping
\attachment[whatever-1][method=hidden]
\attachment[whatever-2]
\stoptyping

where of course hidden is to be omitted when you want an icon. The commands that
are used to define and tune an instance are:

\showsetup{defineattachment}

\showsetup{setupattachment}

There is one predefined instance:

\starttyping
\defineattachment[attachment]
\stoptyping

So we have:

\showsetup{startattachment:instance}

\showsetup{attachment:instance}

Yet another level of abstraction can be achieved with:

\showsetup{registerattachment}

For example:

\starttyping
\registerattachment
  [sometag]
  [name=fool.txt,
   file=foo.txt,
   title=Fool me,
   subtitle=Not you,
   author= Joker]
\stoptyping

This is the \MKIV\ replacement for the \MKII\ method:

\starttyping
\useattachment[test.tex]
\useattachment[whatever][test.tex]
\useattachment[whatever][newname][test.tex]
\useattachment[whatever][title][newname][test.tex]
\stoptyping

or with all options:

\starttyping
\useattachment[name][file][author][title][subtitle]
\stoptyping

The \type {\use...} variant stays around for old times sake and just maps onto
\type {\registerattachment}, you can better use that one because it frees you
from remembering which arguments is what for.

\stopchapter

\stopcomponent