summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/notes/notes.sty
blob: de3ad0dcf34f575742f319af232015e98816eba9 (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
%%
%% This is file `notes.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% notes.dtx  (with options: `package')
%% 
%% Copyright (C) 2002 Duncan Webb
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN
%% archives in directory macros/latex/base/lppl.txt; either
%% version 1 of the License, or any later version.
%% 
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{notes}
[2002/10/29 v1.0.1 (Duncan Webb)]
\RequirePackage{graphics}
\newskip\noteskipamount \noteskipamount=6pt plus 4pt minus 0pt
\newdimen\textwidth     \textwidth=\hsize
\newdimen\marparsep     \marparsep=4pt
\newdimen\rulewd        \rulewd=0.4pt
\newdimen\ruleht        \ruleht=0.4pt
\newdimen\iconwd        \iconwd=0.8cm
\newdimen\iconht        \iconht=0.8cm
\newdimen\textwd        \textwd=.8\textwidth
\newdimen\vframegap     \vframegap=3pt
\newdimen\hframegap     \hframegap=6pt
\newif\if@debug@
\DeclareOption{debug}{%
  \global\@debug@true
}%
\newif\if@frames@
\DeclareOption{frames}{%
  \global\@frames@true
}%
\ProcessOptions*
\newcounter{notecnt}
\setcounter{notecnt}{0}
\newdimen\containerwd
\newdimen\textframeht
\newdimen\iconframeht
\newdimen\containerht
\newdimen\notesmargin
\newdimen\dbgrulewd \dbgrulewd=0pt
\newdimen\dbgruleht \dbgruleht=0pt
\if@frames@
  \dbgrulewd=0.01pt \dbgruleht=0.01pt
\fi
\def\noteskip{\vskip\noteskipamount}
\def\boxdbg#1{\hbox{%
  \vrule width \dbgrulewd\vbox{%
    \hrule height \dbgruleht%
    \hbox{#1}\hrule height \dbgruleht%
  }%
  \vrule width \dbgrulewd}%
}
\def\buildtextframe#1{%
  \vbox{%
    \hrule height \ruleht%
    \hbox{%
      \vrule width \rulewd\kern\vframegap%
      \vbox{\kern\hframegap#1\kern\hframegap}%
      \kern\vframegap\vrule width \rulewd%
    }%
    \hrule height \ruleht%
  }%
}
\def\buildiconbox#1{
  \if@debug@
    \raisebox{0pt}[0pt][0pt]{\makebox[0pt][c]{\tiny\thenotecnt}}%
  \fi
  \vbox{%
    \hsize \iconwd \noindent \hbox to \iconwd{%
      \hfil\resizebox*{\iconwd}{\iconht}{\includegraphics{#1}}\hfil%
    }%
  }%
}
\def\buildiconframe#1{%
  \vbox to \iconht{\vfil\hbox{\buildiconbox{#1}}\vfil}%
}%
\def\calccontainerht#1#2{
  \ifnum #1 > #2 #1 \else #2 \fi
}
\def\buildvcontainer#1#2{%
  \boxdbg{\vbox to #1{\vfil#2\vfil}}
}
\def\buildcontainer#1#2{%
  \if@twoside
    \ifodd\count0
      \hbox to \containerwd{%
        \hskip\notesmargin\hfil#1\hfil\hskip\marparsep#2%
      }
    \else
      \hbox to \containerwd{
        #2\hskip\marparsep\hfil#1\hfil\hskip\notesmargin%
      }
    \fi
  \else %single sided
    \hbox to \containerwd{%
      #2\hskip\marparsep\hfil#1\hfil\hskip\notesmargin%
    }
  \fi
}
\newbox\iconframe
\newbox\textframe
\newbox\iconcontainer
\newbox\textcontainer
\newbox\container
\newbox\notesbox
\newdimen\pageleft
\newdimen\notesboxht
\def\buildnotes#1#2{%
  \stepcounter{notecnt}
  \if@debug@
    \typeout{NOTE \thenotecnt \space started}
  \fi
  \setbox\textframe=\buildtextframe{#1}
  \setbox\iconframe=\buildiconframe{#2}
  \containerht=\calccontainerht{\ht\iconframe}{\ht\textframe}
  % check the page remaining
  \notesboxht=\containerht
  \advance\notesboxht by \dbgruleht
  \advance\notesboxht by \dbgruleht
  \advance\notesboxht by \dbgruleht
  \advance\notesboxht by \dbgruleht
  \advance\notesboxht by \dbgruleht
  \advance\notesboxht by \dbgruleht
  \noteskip % this forces the pagetotal to be updated
  \pageleft=\pagegoal
  \advance\pageleft by -\pagetotal
  \advance\pageleft by -\noteskipamount %
  \advance\pageleft by -\notesboxht
  \advance\pageleft by -\noteskipamount %
  \advance\pageleft by \pageshrink % I'm not sure about this
  % increase the space left on the page by a magic number.
  \advance\pageleft by 0.87083pt
  \if@debug@
    \typeout{pageleft(0)=\the\pageleft}
    \typeout{wd textframe=\the\wd\textframe}
    \typeout{wd iconframe=\the\wd\iconframe}
  \fi
  \setbox\textcontainer=\buildvcontainer{\containerht}{\box\textframe}
  \setbox\iconcontainer=\buildvcontainer{\containerht}{\box\iconframe}
  \notesmargin=\marparsep
  \advance\notesmargin by \wd\iconcontainer
  % calc the container width
  \containerwd=\textwidth
  \containerwd=355pt % \textwidth can be strange
  \advance\containerwd by \notesmargin
  \advance\containerwd by \notesmargin
  \if@debug@
    \typeout{notesboxht=\the\notesboxht}
    \typeout{containerht=\the\containerht}
    \typeout{containerwd=\the\containerwd}
    \typeout{pageshrink(1)=\the\pageshrink}
    \typeout{pagetotal(1)=\the\pagetotal}
    \typeout{pageleft(1)=\the\pageleft}
    \typeout{textframeht=\the\textframeht}
    \typeout{iconframeht=\the\iconframeht}
    \typeout{wd iconcontainer=\the\wd\iconcontainer}
  \fi
  % if there is insufficient space left eject the page
  \ifnum \pageleft < 0 \eject \fi
  % build the container box
  \setbox\container=\vbox{%
    \buildcontainer{\boxdbg{\copy\textcontainer}}{%
      \boxdbg{\copy\iconcontainer}%
    }%
  }
  \setbox\notesbox=\boxdbg{\copy\container}
  \notesboxht=\ht\notesbox
  \if@debug@\typeout{notesboxht=\the\notesboxht}\fi
  % build the container box
  \moveleft \notesmargin\copy\notesbox\noteskip
  % check the page remaining
  \pageleft=\pagegoal
  \advance\pageleft by -\pagetotal
  \advance\pageleft by -\notesboxht
  \if@debug@
    \typeout{pagetotal(2)=\the\pagetotal}
    \typeout{pageleft(2)=\the\pageleft}
    \typeout{NOTE \thenotecnt \space finished}
  \fi
}
\newbox\notebox
\newenvironment{importantnote}%
{%
\begingroup%
\setbox\notebox=\vbox\bgroup\hsize\textwd\noindent\bgroup\it%
}{
\egroup
\egroup
\buildnotes{\box\notebox}{hand}
\endgroup%
}
\newenvironment{warningnote}%
{%
\begingroup%
\setbox\notebox=\vbox\bgroup\hsize\textwd\noindent\bgroup\it%
}{
\egroup
\egroup
\buildnotes{\box\notebox}{warn}
\endgroup%
}
\newenvironment{informationnote}%
{%
\begingroup%
\setbox\notebox=\vbox\bgroup\hsize\textwd\noindent\bgroup\it%
}{
\egroup
\egroup
\buildnotes{\box\notebox}{info}
\endgroup%
}
\endinput
%%
%% End of file `notes.sty'.