summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/papermas/papermas.sty
blob: 2d7b0f514a9c16b937eee195568837ed467bbb2e (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
%%
%% This is file `papermas.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% papermas.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% IMPORTANT NOTICE:
%% The package takes options.
%% 
%% The usual disclaimers apply:
%% If it doesn't work right that's your problem.
%% (Nevertheless, send an e-mail to the maintainer
%%  when you find an error in this package.)
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version. This version of this license is in
%%    http://www.latex-project.org/lppl/lppl-1-3c.txt
%% and the latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3c 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 H.-Martin Muench
%% (Martin dot Muench at Uni-Bonn dot de).
%% 
%% This work consists of the main source file papermas.dtx
%% and the derived files
%%    papermas.sty, papermas.pdf, papermas.ins, papermas.drv,
%%    papermas-example.tex.
%% 
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{papermas}[2010/06/24 v1.0c
            Computes paper mass of a printout (HMM)]%

%% Allows to compute the number of sheets of paper
%% needed to print a document as well as the
%% mass of that printed version of the document,
%% useful e. g. when sending it by mail to determine the postage.
%% Warning/Disclaimer: Mass of (printer's) ink has to be added
%% (and that of envelope, address sticker, stamps,...)!
%% So, this is only an estimation without guarantee -
%% do not sue me, if you have got to pay excess postage!
%% Further this package allows to compute
%%  "base to the power of exponent" inside TeX.

\RequirePackage{kvoptions}[2010/02/22]% v3.7
\RequirePackage{pagesLTS}[2010/06/24]% v1.1c
%% papermas may work with earlier versions of those packages,
%% but this was not tested. Please consider updating your packages
%% to the most recent version (if they are not already the most
%% recent version).

\SetupKeyvalOptions{family = papermas,prefix = papermas@}
\DeclareStringOption[4]{format}[4]%        paper foormat, ISO A...,
                                  %         default: (ISO A) 4
\DeclareStringOption[80]{masss}[80]%       specific mass of the paper,
                                   %        default: 80 (g/(m^2))
\DeclareStringOption[2]{pagespersheet}[2]% number of pages per sheet,
                                         %  for duplex printing this is 2.
\DeclareStringOption[.]{decimalsep}[.]%    decimal separator,
             % e. g. "." or ",": decimalsep={,} - brackets are needed!!!
             % decimalsep={,\,} does not work for screen, aux, log output!

\ProcessKeyvalOptions*

%% Code from tcilatex.tex, Macros for Scientific Word and Scientific WorkPlace 5.5 <06 Oct 2005> %%
%% Copyright (C) 2005 Mackichan Software, Inc.                                                   %%
%% That macro file is NOT proprietary and may be freely copied and distributed.                  %%
%% \def was changed to \gdef                                                                     %%
  \gdef\unit#1{\mathord{\thinspace\rm #1}}%
%% End of code from tcilatex.tex                                                                 %%

\ifx\papermasstotal\undefined \gdef\papermasstotal{\textbf{??}}%
\fi
\ifx\papermasstotal\undefined \gdef\papermasstotal{\textbf{??}}%
\fi
\ifx\papermasformat\undefined \gdef\papermasformat{\textbf{??}}%
\fi
\ifx\papermasmasss\undefined \gdef\papermasmasss{\textbf{??}}%
\fi
\ifx\papermaspagespersheet\undefined \gdef\papermaspagespersheet{\textbf{??}}%
\fi
\ifx\papermassheets\undefined \gdef\papermassheets{\textbf{??}}%
\fi

\newcounter{papermas@rerun}
\newcounter{papermas@base}
\newcounter{papermas@exp}
\newcounter{papermas@result}
\newcounter{papermas@ini}
\setcounter{papermas@ini}{1}

\newcommand\papermas@powerof[2]{%
  \setcounter{papermas@base}{#1}
  \setcounter{papermas@exp}{#2}
  \ifnum \value{papermas@ini}=1
    \setcounter{papermas@result}{\value{papermas@base}}
    \setcounter{papermas@ini}{0}
    \ifnum \value{papermas@exp}=0%
      \setcounter{papermas@result}{1}
    \else
      \addtocounter{papermas@exp}{-1}
    \fi
  \fi
  \ifnum \value{papermas@exp}=0%
    \setcounter{papermas@ini}{1}
  \else
    \multiply \value{papermas@result} \value{papermas@base}
    \addtocounter{papermas@exp}{-1}
    \papermas@powerof{#1}{\value{papermas@exp}}
  \fi%
  }

\newcommand\papermas@totmass{%
  \newcounter{papermasA}% paper mass for ISO A...
  \setcounter{papermasA}{\papermas@format}% e. g. 4
  \ifnum \value{papermasA}<0%
    \PackageError{papermas}{Option format has no valid value}%
     {The format option of the papermas package\MessageBreak%
      only takes whole, non-negative numbers (0, 1, 2, 3,...),\MessageBreak%
      because this should be the paper format\MessageBreak%
      ISO A 0, 1, 2, 3,...\MessageBreak%
      Found instead: \papermas@format \MessageBreak%
     }
  \else%
    \newcounter{papermasmasss}% always 0
    \setcounter{papermasmasss}{\papermas@masss}% default: 80
    \multiply \value{papermasmasss} 100 % default: 8000
    \ifnum \value{papermasmasss}<1%
      \PackageError{pagesLTS}{Option masss has no valid value}%
       {The masss option of the papermas package\MessageBreak%
        only takes positive numbers,\MessageBreak%
        because this should be the mass per square meter\MessageBreak%
        of a single sheet of your paper.\MessageBreak%
        Found instead: \papermas@masss \MessageBreak%
       }
    \else
      \newcounter{papermasPPS}% is 0
      \setcounter{papermasPPS}{\papermas@pagespersheet}% default 2
      \ifnum \value{papermasPPS} < 1%
        \PackageError{papermas}{%
          The number of pages per sheet must be positive.}{%
          You cannot print less than one TeX page per sheet of paper.\MessageBreak%
          The value found was \papermas@pagespersheet .\MessageBreak%
          }
      \else
        \newcounter{papermas@sheets}
        \setcounter{papermas@sheets}{\arabic{pagesLTS.pagenr}}%
        \divide \value{papermas@sheets} by \value{papermasPPS}%
        \newcounter{papermas@tmpn}
        \setcounter{papermas@tmpn}{\arabic{papermas@sheets}}%
        \multiply \value{papermas@tmpn} \value{papermasPPS}%
        \ifnum \value{papermas@tmpn}=\value{pagesLTS.pagenr}
          \relax
        \else
          \addtocounter{papermas@sheets}{1}%
        \fi
        \multiply \value{papermasmasss} \value{papermas@sheets}
  % default:                  8000       (no default for this)
        \papermas@powerof{2}{\value{papermasA}}
        \divide \value{papermasmasss} by \value{papermas@result}
  % default:               16000      /   2^(\value{papermasA})
        % for the example 297 is used
        \newcounter{papermas@tmpm}
        \setcounter{papermas@tmpm}{\arabic{papermasmasss}}%   m:297 n:    o:  p:  q:
        \setcounter{papermas@tmpn}{\arabic{papermasmasss}}%   m:291 n:291 o:  p:  q:
        \divide \value{papermas@tmpn} by 100%                 m:297 n:2   o:  p:  q:
        \newcounter{papermas@tmpo}
        \setcounter{papermas@tmpo}{\arabic{papermas@tmpn}}%   m:291 n:2   o:2 p:  q:
        \multiply \value{papermas@tmpn} 10%                   m:297 n:20  o:2 p:  q:
        \divide \value{papermas@tmpm} by 10%                  m:29  n:20  o:2 p:  q:
        \newcounter{papermas@tmpp}
        \setcounter{papermas@tmpp}{\arabic{papermas@tmpm}}
        \addtocounter{papermas@tmpp}{-\arabic{papermas@tmpn}}%m:29  n:20  o:2 p:9 q:
        %        29              - 20 = 9
        \multiply \value{papermas@tmpm} 10%                   m:290 n:20  o:2 p:9 q:
        \newcounter{papermas@tmpq}
        \setcounter{papermas@tmpq}{\arabic{papermasmasss}}
        \addtocounter{papermas@tmpq}{-\arabic{papermas@tmpm}}%m:290 n:20  o:2 p:9 q:7
        %       297              - 290 = 7
        \ifnum\value{papermas@tmpq}>4
          \addtocounter{papermas@tmpp}{1}%                    m:290 n:20 o:2 p:10 q:7
          \ifnum\value{papermas@tmpp}>9%                      m:290 n:20 o:2 p:10 q:7
            \addtocounter{papermas@tmpo}{1}%                  m:290 n:20 o:3 p:10 q:7
            \setcounter{papermas@tmpp}{0}%                    m:290 n:20 o:3 p:0  q:7
          \fi
        \fi
        \edef\papermastmpr{\arabic{papermas@tmpo}\papermas@decimalsep\arabic{papermas@tmpp}}%
        \edef\papermastmpformat{\papermas@format}%
        \edef\papermastmpmasss{\papermas@masss}%
        \edef\papermastmppagespersheet{\papermas@pagespersheet}%
        \edef\papermastmpt{\arabic{papermas@sheets}}%
        \pagesLTS@ifcounter{papermassttl}
        \ifnum\value{papermassttl}=\value{papermasmasss}
          \relax
        \else
          \PackageWarningNoLine{papermas}{%
            Number of pages may have changed.\MessageBreak%
            Rerun to get it right.\MessageBreak%
            }%
        \fi
        \setcounter{papermassttl}{\arabic{papermasmasss}}
        \edef\papermastmps{\arabic{papermasmasss}}%
        \if@filesw%
          \immediate\write\@auxout{\string
            \pagesLTS@ifcounter{papermassttl}}%
          \immediate\write\@auxout{\string
            \setcounter{papermassttl}{\papermastmps}}%
          \immediate\write\@auxout{\string
            \gdef\string\papermasstotal{\papermastmpr}}%
          \immediate\write\@auxout{\string
            \gdef\string\papermasformat{\papermastmpformat}}%
          \immediate\write\@auxout{\string
            \gdef\string\papermasmasss{\papermastmpmasss}}%
          \immediate\write\@auxout{\string
            \gdef\string\papermaspagespersheet{\papermastmppagespersheet}}%
          \immediate\write\@auxout{\string
            \gdef\string\papermassheets{\papermastmpt}}%
        \fi%
      \fi%
    \fi%
  \fi%
  }

\AtBeginDocument{%
  \def\papermas@undefined{\textbf{??}}
  \setcounter{papermas@rerun}{0}
  \ifx\papermasstotal\papermas@undefined        \addtocounter{papermas@rerun}{000001} \fi
  \ifx\papermasstotal\papermas@undefined        \addtocounter{papermas@rerun}{000010} \fi
  \ifx\papermasformat\papermas@undefined        \addtocounter{papermas@rerun}{000100} \fi
  \ifx\papermasmasss\papermas@undefined         \addtocounter{papermas@rerun}{001000} \fi
  \ifx\papermaspagespersheet\papermas@undefined \addtocounter{papermas@rerun}{010000} \fi
  \ifx\papermassheets\papermas@undefined        \addtocounter{papermas@rerun}{100000} \fi
  }

\AfterLastShipout{%
  \papermas@totmass%
  }%

\AtVeryEndDocument{%
  \ifnum\value{papermas@rerun}>0
    \PackageWarningNoLine{papermas}{!\MessageBreak%
      Variable(s) still undefined.\MessageBreak%
      (Error code \arabic{papermas@rerun}.)\MessageBreak%
      Rerun to get the variable(s) right.\MessageBreak%
    }%
  \else
    \message{papermas: ***************************************************}
    \message{papermas: * This document consists of \arabic{pagesLTS.pagenr} pages. *}
    \message{papermas: * When printing \papermaspagespersheet\space pages on one sheet of paper, *}
    \message{papermas: * \papermassheets\space sheets will be needed. *}
    \message{papermas: * For ISO A \papermasformat\space paper of \papermasmasss\space g/m^2 specific mass, *}
    \message{papermas: * the printout will have a mass of about \papermasstotal\space g. *}
    \message{papermas: ***************************************************}
    \PackageInfo{papermas}{***************************************************\MessageBreak%
      * This document consists of \arabic{pagesLTS.pagenr} pages. *\MessageBreak%
      * When printing \papermaspagespersheet\space pages on one sheet of paper, *\MessageBreak%
      * \papermassheets\space sheets will be needed. *\MessageBreak%
      * For ISO A \papermasformat\space paper of \papermasmasss\space g/m^2 specific mass, *\MessageBreak%
      * the printout will have a mass of about \papermasstotal\space g. *\MessageBreak%
      ***************************************************\MessageBreak%
    }%
  \fi%
  }

\endinput
%%
%% End of file `papermas.sty'.