summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/sttools/boundbox.dtx
blob: 3453b2128c6bbb3ee472cc068da47f501870dc39 (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
% \iffalse meta-comment
%
% Copyright (C) 2012 by Sigitas Tolu\v{s}is <sigitas@vtex.lt>
% ---------------------------------------------------------------------------
% 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 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Sigitas Tolu\v{s}is.
%
% This work consists of the files boundbox.dtx and boundbox.ins
% and the derived filebase boundbox.sty.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{boundbox.dtx}
%</driver>
%<*package>
%% Copyright (C) 1997-2012 by Sigitas Tolu\v{s}is <sigitas@vtex.lt>
%% VTeX Ltd., Akademijos 4, Vilnius, Lithuania
%% http://www.vtex.lt/tex/download/macros/
%% --------------------------------------------------------------------------
%% 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 2005/12/01 or later.
%%
%% PURPOSE: Calculate TeX bounding box in rounded points (LaTeX2e)
%%          from left top corner of the paper
%%
%</package>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{boundbox}
%<*package>
    [2012/05/29 v1.3 Calculate TeX bounding box in points]
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{boundbox}[2012/05/29]
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{boundbox.dtx}
  %%\PrintChanges
  %%\PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{186}
%
% \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{v1.3}{2012/05/29}{Source converted to DTX file}
% \changes{v1.3}{2012/05/29}{Added package option nospec}
%
% \DoNotIndex{\newcommand,\newenvironment}
%
% \providecommand*{\url}{\texttt}
% \GetFileInfo{boundbox.dtx}
% \title{The \textsf{boundbox} package}
% \author{Sigitas Tolu\v{s}is \\ \url{sigitas@vtex.lt}}
% \date{\fileversion~from \filedate}
%
% \maketitle
%
% \section{Introduction}
%
% The package is used to calculate textbox coordinates on the page.
% I guess that the most useable part of this package can be internal
% macro \verb|\roundtexdim| for rounding pt values to int numbers.
%
% \section{Usage}
%
% Just add package to the tex file as: \verb|\usepackage{boundbox}|. 
% \\\medskip
% Rounding tex dimension values:
% 
% \newdimen\testdim \testdim=1in\verb|\newdimen\testdim|
%
% \verb|\testdim=1in \the\testdim ->|
% \the\testdim
%
% \medskip
% \roundtexdim{\testdim}\foo\verb|\roundtexdim{\testdim}\foo \number\foo->|\number\foo
%
% \medskip
% \roundtexdim floor{\testdim}\foo\verb|\roundtexdim floor{\testdim}\foo \number\foo->|\number\foo
%
% \medskip
% \roundtexdim ceil{\testdim}\foo\verb|\roundtexdim ceil{\testdim}\foo \number\foo->|\number\foo
%
% \StopEventually{}
%
% \section{Implementation}
%
% \iffalse
%<*package>
% \fi
%
% The package contains two options:
%
% \meta{nofoot} -- do not include foot to the bbox.
%
% \meta{nospec} -- do not write specials with bbox info.
%
%    \begin{macrocode}
%
%%
\newif\if@withfoot \@withfoottrue
\newif\if@output@bbox@special \@output@bbox@specialtrue
\DeclareOption{nofoot}{\global\@withfootfalse}
\DeclareOption{nospec}{\global\@output@bbox@specialfalse}
\ProcessOptions
%%
% 
%    \end{macrocode}
%
% Definitions of special prefixes. 
%
%    \begin{macrocode}
\def\special@bbox@odd@prefix{mt:TeXBBox:odd}
\def\special@bbox@even@prefix{mt:TeXBBox:even}
%    \end{macrocode}
%
% \begin{macro}{\roundtexdim}
% \marg{round type}\marg{tex dimension}\marg{command}
% 
% \meta{tex dimension} value in pt rounded with \meta{round type}
% is defined as \meta{command}.
%
%    \begin{macrocode}
%
%%
\def\roundtexdim#1#{\round@tex@dim{#1}}
\def\round@tex@dim#1#2#3{%
  \expandafter\expandafter\csname get@#1@pt@data\endcsname\the#2\to#3\relax
  }
%    \end{macrocode}
% \end{macro}
%
%
% Internal macro for calculating rounded value to the floor.
%
%
% \begin{macro}{\get@floor@pt@data}
%
%    \begin{macrocode}
\def\get@floor@pt@data#1.#2#3\to#4{%
  \bgroup
    \@tempcnta=#1\relax
    \xdef#4{\the\@tempcnta}%
  \egroup
  }
%    \end{macrocode}
% \end{macro}
%
%
% Internal macro for calculating rounded value by first number after point.
%
%
% \begin{macro}{\get@round@pt@data}
%
%    \begin{macrocode}
\def\get@round@pt@data#1.#2#3\to#4{%
  \bgroup
    \@tempcnta=#1\relax
    \ifnum#2>4\relax
      \advance\@tempcnta by\@ne
    \fi
    \xdef#4{\the\@tempcnta}%
  \egroup  
  }
\let\get@@pt@data\get@round@pt@data
%    \end{macrocode}
% \end{macro}
%
%
% Internal macro for calculating rounded value to the ceiling.
%
%
% \begin{macro}{\get@ceil@pt@data}
%
%    \begin{macrocode}
\def\get@ceil@pt@data#1.#2#3\to#4{%
  \bgroup
    \@tempcnta=#1\relax
    \afterassignment\@gobbletwo
    \@tempcntb=#2#3\relax
    \ifnum\@tempcntb>0\relax
      \advance\@tempcnta by\@ne
    \fi
    \xdef#4{\the\@tempcnta}%
  \egroup
  }
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@calculate@bbox}
%
%  Internal macro \verb|\@calculate@bbox|  calculates TeX box dimensions: 
%
%  \begin{itemize}
%  \item \verb|\bbox@odd@top@pt| and \verb|\bbox@even@top@pt|:
%       distance in rounded ``floor'' points from the top of paper to the top of TeX box
%       (including head)  (the same for odd and even pages);
%  \item \verb|\bbox@odd@left@pt| and \verb|\bbox@even@left@pt|:
%       distance in rounded ``floor'' points from the left side of paper
%       to the left side of TeX box for odd and even pages;
%  \item \verb|\bbox@odd@right@pt| and \verb|\bbox@even@right@pt|:
%        distance in rounded ``ceil'' points from the left side of paper to the right
%        side of TeX box accordingly for odd and even pages;
%  \item \verb|\bbox@odd@bottom@pt| and \verb|\bbox@even@bottom@pt|:
%        distance in rounded ``ceil''  points from the top of paper to the bottom of TeX
%        box (including foot by default; with option "nofoot" without
%        foot) (the same for odd and even pages).
%  \end{itemize}
%
%    \begin{macrocode}
\def\@calculate@bbox{%
  \bgroup
    \@tempdima=1in\relax
    \advance\@tempdima by\hoffset
    \advance\@tempdima by\oddsidemargin
    \roundtexdim floor{\@tempdima}\bbox@odd@left@pt
    \advance\@tempdima\textwidth
    \roundtexdim ceil{\@tempdima}\bbox@odd@right@pt
    \@tempdima=1in\relax
    \advance\@tempdima by\hoffset
    \advance\@tempdima by\evensidemargin
    \roundtexdim floor{\@tempdima}\bbox@even@left@pt
    \advance\@tempdima\textwidth
    \roundtexdim ceil{\@tempdima}\bbox@even@right@pt
    \@tempdima=1in\relax
    \advance\@tempdima by\voffset
    \advance\@tempdima by\topmargin
    \roundtexdim floor{\@tempdima}\bbox@odd@top@pt
    \global\let\bbox@even@top@pt\bbox@odd@top@pt
    \advance\@tempdima by\headheight
    \advance\@tempdima by\headsep
    \advance\@tempdima\textheight
    \if@withfoot
      \advance\@tempdima\footskip
    \fi
    \roundtexdim ceil{\@tempdima}\bbox@odd@bottom@pt
    \global\let\bbox@even@bottom@pt\bbox@odd@bottom@pt
  \egroup
  }
%    \end{macrocode}
% \end{macro}
%
% Without package option \meta{nospec} two specials are written to the
% output file. Prefix of particular special is defined by:
% \verb|\special@bbox@odd@prefix| and \verb|\special@bbox@even@prefix|.
%
%    \begin{macrocode}
%
%%
\AtBeginDocument{%
  \@calculate@bbox
  \if@output@bbox@special
    \special{\special@bbox@odd@prefix\space
           left=\csname bbox@odd@left@pt\endcsname\space
           top=\csname bbox@odd@top@pt\endcsname\space 
           right=\csname bbox@odd@right@pt\endcsname\space 
           bottom=\csname bbox@odd@bottom@pt\endcsname
           }%
    \special{\special@bbox@even@prefix\space
           left=\csname bbox@even@left@pt\endcsname\space
           top=\csname bbox@even@top@pt\endcsname\space 
           right=\csname bbox@even@right@pt\endcsname\space 
           bottom=\csname bbox@even@bottom@pt\endcsname
           }%
  \fi
  }
\endinput
%    \end{macrocode}
%
% \iffalse
%</package>
% \fi
%
% \Finale