summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/mnotes/mnotes.dtx
blob: babd0566a6cde74fd1722716124b4d0e27a50c9b (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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
% \iffalse meta-comment
%
%<*preamble>
% mnotes.dtx
%
% Copyright (C) 2013 by S Luz <luzs@acm.org>
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, either version 1.3 of this license
% or (at your option) any later version.  The latest version of this
% license is in 
%
%   http://www.latex-project.org/lppl.txt 
%
% and version 1.3 or later is part of all distributions of LaTeX
% version 2003/12/01 or later.
% 
% INSTALLATION:
%
% on Unix, run "make" to get the style file and the documentation;
% Alternatively, to generate the driver mnotes.ins run
%
%     $ pdflatex mnotes.dtx
%
% To generate the style file run
%
%     $ tex mnotes.ins
%
%%  @LaTeX-package-file{
%%     author          = "Saturnino Luz",
%%     version         = "0.6",
%%     date            = "18 April 2013",
%%     filename        = "mnotes.dtx",
%%     address         = "S Luz
%%                        Trinity College
%%                        Dublin, Ireland",
%%     URL             = "http://www.scss.tcd.ie/~luzs/",
%%     email           = "luzs@acm.org",
%%     codetable       = "ISO/ASCII",
%%     keywords        = "margin, notes, comments",
%%     supported       = "yes",
%%     docstring       = "This document describes the mnotes package.
%%  }
%% 
%
%</preamble>
%
%<*batchfile>
\begin{filecontents}{mnotes.ins}
\def\batchfile{mnotes.ins}
\input docstrip.tex
\askforoverwritefalse
\keepsilent
\preamble

This is a generated file.

Copyright (C) 2013 by S Luz <luzs@acm.org>

This work may be distributed and/or modified under the conditions of
the LaTeX Project Public License, either version 1.3 of this license
or (at your option) any later version.  The latest version of this
license is in 

http://www.latex-project.org/lppl.txt 

and version 1.3 or later is part of all distributions of LaTeX version
2003/12/01 or later.

\endpreamble
\generate{\file{mnotes.sty}{\from{mnotes.dtx}{package}}}

\obeyspaces
\Msg{*************************************************************}
\Msg{*                                                           *}
\Msg{* To finish the installation you have to move the following *}
\Msg{* file into a directory searched by TeX:                    *}
\Msg{*                                                           *}
\Msg{*     mnotes.sty                                            *}
\Msg{*                                                           *}
\Msg{* To produce the documentation run the file mnotes.dtx      *}
\Msg{* through LaTeX.                                            *}
\Msg{*                                                           *}
\Msg{* Happy TeXing!                                             *}
\Msg{*                                                           *}
\Msg{*************************************************************}
\endbatchfile
\end{filecontents}
%</batchfile>
%
%<*driver>
\ProvidesFile{mnotes.dtx}[%
%</driver>
%<package>\ProvidesPackage{mnotes}[%
%<*driver|package>
  2013/20/04 v0.7 margin notes for collaborative document editing]
%</driver|package>
%<*driver>
\documentclass{ltxdoc}
%%\usepackage{mnotes}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{mnotes.dtx}
  \PrintIndex
  \PrintChanges
\end{document}
%</driver>
% \fi
%
%  \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \changes{v0.4}{2013/04/18}{Clean-up}
% \changes{v0.5}{2013/04/20}{First release}
%
% \GetFileInfo{mnotes.dtx}
% 
%
% \title{\texttt{mnotes} --- annotate documents with margin comments\thanks{This document
%   corresponds to \textsf{mnotes}~\fileversion, dated \filedate.}}
% \author{S Luz\\ \texttt{luzs<at>acm.org} }
%
% \maketitle
%
% \begin{abstract}
%  This is a simple package to allow you to add comments to the margins
%  of your documents. It is primarily designed to support collaborative
%  document writing. The comments can be added to the text similarly
%  to \verb+\footnote+ and will be displayed on the margins in
%  text boxes connected by a thin line to the part of the text they refer
%  to. Thanks to the use of \texttt{sidenotes}, comments can float on
%  the margins to avoid overlaps. The text can optionally be scaled
%  down to allow comments to fit in otherwise narrow notes without
%  altering the document's template.  
% \end{abstract}
%
% \tableofcontents
%
% \section{Package options}
%
% The basic usage is to include a \verb+\usepackage{mnote}+ to the
% preamble of your \LaTeX\ document. 
% 
% The \textsf{mnotes} package also provides some basic
% customisation of the way comments are displayed. The interface to the
% package's options is, as usual, accessed through the \verb+\usepackage+
% command.
% 
% The package options are:
% \begin{itemize}
% \item[\texttt{scale}] This enlarges the physical page of the
%   document to allow comments to fit in the margin area. The default
%   \verb+\usepackage[scale]{mnotes}+ is to make the physical page 5\%
%   larger than the original paper size. You can pass a value to this
%   option to control the the amount of space allocated to the
%   margins. For instance \verb+\usepackage[scale=1.2]{mnotes}+ makes
%   the physical page 20\% larger. \textbf{Important:} when printing
%   your draft, make
%   sure that the printer is set to shrink the page to printable area.\\
%   Default: \texttt{scale=1.05}.
% \item[\texttt{mnwidth}] Sets the default width for the comment
%   boxes. \\ Default: \texttt{mnwidth=2.2cm}.
% \item[\texttt{boxcolour}] the colour of the box that encloses the
%   comments (and of the lines that connect comments to the
%   text). \\Default: \texttt{boxcolour=red}.
% \item[\texttt{hide}] Hides all notes. Useful for generating a final
%   (camera-ready) version without comments, without actually removing
%   the comments from the \LaTeX\ code.
% 
% \changes{v0.6}{2013/04/22}{Added nosidenotes option}
% \changes{v0.8}{2014/11/05}{By default don't use sidenotes. Specify
% sidenotes option to use it. marginnote allows placement of MNOTEs on
% floats; sidenote doesn't seem to.}
%
% \item[\texttt{sidenotes}] use sidenote package instead of plain marginnote. 
% \item[\texttt{basic}] This causes the note setting to fallback to
%   \LaTeX{} kernel's \verb+\marginpar+, in case \texttt{sidenotes} or
%   \texttt{tikz} isn't available.
% 
% \changes{v0.6}{2013/04/22}{Added reverseconnect option}
% 
% \item[\texttt{reverseconnect}] Some classes seem to call the right
%   column 'first column' (i.e. they set \verb+\if@firstcolumn+ to
%   \texttt{true} on the first column). This option tries to fix this,
%   so the lines link to the notes on the right side of the boxes
%   (west for right columns and east for left columns). The direction
%   of connection can also be reversed in the document through the
%   \verb+\ReverseMNConnect+ command.
% \end{itemize}
%
% \section{Usage}
%
% \DescribeMacro{\MNOTE} The \verb+\MNOTE[colour]{comments}+ places
% \texttt{comments} on the right margin of the document. Comments can
% contain any valid \LaTeX\ code, including  text, pictures, tables
% etc. Comments are enclosed in boxes and linked to specific places in
% the text by lines, except when the option \texttt{basic} is passed to
% \verb+\usepackage+. If you are generating a \texttt{pdf} file with
% \texttt{pdflatex} (or \texttt{pdftex}) you might have to run it
% at least twice in order to get \texttt{tikz} to find the correct
% coordinates for lines and boxes.
% 
% The aim was to keep the interface as simple as
% possible, so that the
% usage can be quickly explained to your collaborators, even if they
% are not regular \LaTeX\ users. The following example shows the basic
% usage: 
% \begin{verbatim}
%  The aim was to keep the interface as simple as
%  possible\MNOTE{Revise this text}, so that the
%  usage can be quickly explained to your collaborators, even if they
%  are not regular \LaTeX\ users.
% \end{verbatim}
%
% \DescribeMacro{\HideMNOTES} Comments can be ``switched off'' at any
% point in the text by adding a \verb+\HideMNOTES{}+ command anywhere
% in the text. 
% \DescribeMacro{\ShowMNOTES}
% They can be switched back on again through the
% \verb+\ShowMNOTES{}+ 
%
% \DescribeMacro{\ReverseMNConnect}
% Toggle the side to which the comment boxes are connected to the
% text, to be used in case \LaTeX\ looses track of it. Package option
% \verb+reverseconnect+ reverses these connections globally.
%
% \section{Required packages}
% 
%  \begin{description}
%  \item[kvoptions] for option processing
%  \item[sidenotes] for note placement, including floats. N.B.:
%    \texttt{sidenotes} is not required if \texttt{basic} or \texttt{nosidenotes}
%    is passed
%    as an option. In this case, note placement reverts to \LaTeX{}'s
%    kernel's \verb+\marginpar+ macro.
%  \item[tikz] for graphics (boxes and connectors).  N.B.:
%    \texttt{tikz} is note required if \texttt{basic} is passed as an
%    option.
%  \end{description}%
%
% \section{Bugs}
%
% The connectors sometimes go off the page when option
% \verb+nosidenotes+ is set (i.e. notes are set through \LaTeX\ kernnel's
% \verb+\marginpar+ macro).
% 
% \section{Implementation}
%
% \iffalse
%<*package>
% \fi
% Define some defaults: width of comment bcx, colour, font and paperwidth.
%    \begin{macrocode}
\expandafter\ifx\csname mnotespaperwidth\endcsname\relax
    \newdimen\mnotespaperwidth
    \mnotespaperwidth1.05\paperwidth
\fi
\newlength{\MNOTEWIDTH}
\setlength{\MNOTEWIDTH}{2.2cm}
\newcommand{\MNCOLOUR}{red}
\newcommand{\MNFONT}{\tiny}
\newif\if@mnotes@hide
\@mnotes@hidefalse
\newif\if@mnotes@basic
\@mnotes@basicfalse
\newif\if@mnotes@sidenotes
\@mnotes@sidenotesfalse
\newif\if@mnotes@scale
\@mnotes@scalefalse
\newif\if@mnotes@reverseconnect
\@mnotes@reverseconnectfalse
%    \end{macrocode}
% Get package options
%    \begin{macrocode}
\RequirePackage{kvoptions}
\DeclareVoidOption{basic}{\@mnotes@basictrue}
\DeclareVoidOption{sidenotes}{\@mnotes@sidenotestrue}
\DeclareVoidOption{hide}{\@mnotes@hidetrue \AtEndOfPackage{\HideMNOTES{}}}
\DeclareVoidOption{reverseconnect}{\@mnotes@reverseconnecttrue}
\SetupKeyvalOptions{family=mnotes, prefix=mnotes@}
\DeclareStringOption{scale}[1.05]
\define@key{mnotes}{scale}{\if@mnotes@hide\else%
\pdfpagewidth#1\paperwidth\@mnotes@scaletrue\fi}
\DeclareVoidOption{centre}{\if@mnotes@scale\hoffset\pdfpagewidth
    \advance\hoffset-\paperwidth
    \hoffset.5\hoffset\fi}
\DeclareStringOption{mnwidth}[\MNOTEWIDTH]
\define@key{mnotes}{mnwidth}{\setlength{\MNOTEWIDTH}{#1}}
\DeclareStringOption{boxcolour}
\define@key{mnotes}{boxcolour}{\renewcommand{\MNCOLOUR}{#1}}
\DeclareStringOption{fontsize}[6]
\define@key{mnotes}{fontsize}{%
\count1=#1 \multiply \count1 by 116 \divide \count1 by 100%
\def\MNFONT{\fontsize{#1}{\count1}\selectfont}}
 %\ExecuteOptions{}
\ProcessKeyvalOptions{mnotes}
%\ProcessOptions
%    \end{macrocode}
%  \changes{v0.7}{2013/04/24}{made basic option independent of
%  ifoddpage package}
%    \begin{macrocode}
\if@twocolumn\if@mnotes@scale\hoffset\pdfpagewidth
    \advance\hoffset-\paperwidth
    \hoffset.5\hoffset\fi\fi
\if@mnotes@basic
  \RequirePackage{color}
  \newif\ifoddpage %% define \ifoddpage even though it's not used to
\else              %% avoid  extra bracket error
  \if@mnotes@sidenotes
    \RequirePackage{sidenotes}
  \else
    \RequirePackage{marginnote}
    \renewcommand\marginpar\marginnote
  \fi
  \RequirePackage{tikz}
  \RequirePackage{ifoddpage}
\fi
%    \end{macrocode}
% \begin{macro}{\MNOTEon}
% This is the core of the notes macro. 
% \changes{v0.6}{2013/04/22}{Fixed problems with margins for
% twocolumn and twoside documents, so that connectors connect to the
% right side of the notes box. For some strange reason, article.cls
% seems to call the right column 'first column' (i.e. \texttt{if@firstcolumn}
% true). Created an option reverseconnect to fix that, so the lines
% link to the notes on the right side of the boxes (west for right
% columns and east for left columns). }
% \changes{v0.6}{2013/04/22}{Use reverseconnect to set the left and
% right margins correctly in some classes.}
%  \changes{v0.8}{2013/04/24}{replaced marginpar by marginnote on the
%  nosidenote option to allow MNOTES in floats.}
%    \begin{macrocode}
\if@mnotes@basic
\setlength{\marginparsep}{6pt}\setlength{\marginparwidth}{\MNOTEWIDTH}
\newcommand{\MNOTEon}[2][\MNCOLOUR]{%
\marginpar%
[{\MNFONT\raggedleft\color{#1}\em #2}]%
{\MNFONT\raggedright\color{#1}\em #2}}%
\else% not basic
\newcommand{\MNOTEon}[2][\MNCOLOUR]{
\setlength{\marginparsep}{6pt}\setlength{\marginparwidth}{\MNOTEWIDTH}
\begin{tikzpicture}[remember picture, baseline=-0.75ex]%
\node [coordinate] (textPOS) {};%
\end{tikzpicture}%
\if@mnotes@sidenotes
\sidenotetext[\tiny.]%
{\MNFONT\raggedright\em%
\begin{tikzpicture}[remember picture]%
\draw node [draw=#1,text width=\MNOTEWIDTH-1pt] (notePOS) {#2};%
\end{tikzpicture}
}%
\else
\marginpar%
[{\MNFONT\raggedleft\em\begin{tikzpicture}[remember picture]%
\draw node [draw=#1,text width=\MNOTEWIDTH-1pt] (notePOS) {#2};%
\end{tikzpicture}}]%
{{\MNFONT\raggedright\em%
\begin{tikzpicture}[remember picture]%
\draw node [draw=#1,text width=\MNOTEWIDTH-1pt] (notePOS) {#2};%
\end{tikzpicture}%
}}%
\fi%
\if@twocolumn%
  \if@firstcolumn%
    \if@mnotes@reverseconnect
      \mnoteswestlink{#1}%
    \else
      \mnoteseastlink{#1}%
    \fi
  \else%
    \if@mnotes@reverseconnect
      \mnoteseastlink{#1}%
    \else
      \mnoteswestlink{#1}%
    \fi
  \fi%
\else%
  \if@twoside%
    \checkoddpage%
    \ifoddpage%\ifodd\value{mn@abspage}%
      \mnoteswestlink{#1}%
    \else%
      \mnoteseastlink{#1}%
    \fi%
  \else%
    \mnoteswestlink{#1}%
  \fi%
\fi%
}%
\newcommand{\mnoteseastlink}[1]{%
\begin{tikzpicture}[remember picture, overlay]%
 \draw[#1,-]%
 ([yshift=-0.2cm] textPOS)%
  -|([xshift=-0.1pt] notePOS.east);%
    \end{tikzpicture}%
}
\newcommand{\mnoteswestlink}[1]{%
\begin{tikzpicture}[remember picture, overlay]%
\draw[#1,-]%
([yshift=-0.2cm] textPOS)%
-|([xshift=-0.1pt] notePOS.west);%
  \end{tikzpicture}%
}
\fi
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\MNOTE}
% User interface to \verb+\MNOTEon+
%    \begin{macrocode}
\newcommand{\MNOTE}{\MNOTEon}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\HideMNOTES}
% Hide notes from this point on.
%    \begin{macrocode}
\newcommand{\HideMNOTES}{\renewcommand{\MNOTE}[2][red]{}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ShowMNOTES}
% Show notes from this point on.
%    \begin{macrocode}
\newcommand{\ShowMNOTES}{\renewcommand{\MNOTE}{\MNOTEon}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ReverseMNConnect}
% Reverse the side of from which the lines connect to the MNOTE box.
%    \begin{macrocode}
\newcommand{\ReverseMNConnect}{%
\if@mnotes@reverseconnect\@mnotes@reverseconnectfalse
\else\@mnotes@reverseconnecttrue\fi}
%    \end{macrocode}
% \end{macro}
% \Finale
\endinput