summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/papermas/papermas.sty
blob: 4b52b2fd111709600f563f253d80c9b47b4487be (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
%%
%% 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.
%% 
%% Project: papermas
%% Version: 2011/08/22 v1.0h
%% 
%% Copyright (C) 2010, 2011 by
%%     H.-Martin M"unch <Martin dot Muench at Uni-Bonn dot de>
%% 
%% The usual disclaimer applys:
%% 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.
%% 
%% 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}[2009/09/24]
\ProvidesPackage{papermas}[2011/08/22 v1.0h
            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!

\RequirePackage{kvoptions}[2010/12/23]% v3.10
\RequirePackage{pageslts}[2011/08/08]% v1.2a
\RequirePackage{intcalc}[2007/09/27]%  v1.1; for intcalcPow
%% papermas may work with earlier versions of LaTeX and those
%% packages, but this was not tested. Please consider updating
%% your LaTeX and 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*

\gdef\unit#1{\mathord{\thinspace\mathrm{#1}}}%

\@ifundefined{papermasstotal}{\gdef\papermasstotal{\textbf{??}}}{}
\@ifundefined{papermasstotal}{\gdef\papermasstotal{\textbf{??}}}{}
\@ifundefined{papermasformat}{\gdef\papermasformat{\textbf{??}}}{}
\@ifundefined{papermasmasss}{\gdef\papermasmasss{\textbf{??}}}{}
\@ifundefined{papermaspagespersheet}{\gdef\papermaspagespersheet{\textbf{??}}}{}
\@ifundefined{papermassheets}{\gdef\papermassheets{\textbf{??}}}{}

\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{papermas}{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)
        \divide \value{papermasmasss} by \intcalcPow{2}{\value{papermasA}}
  % 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}}%
        \xdef\papermas@mbs{\arabic{papermas@tmpo}}%
        \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
          \AtEndAfterFileList{%
            \PackageWarningNoLine{papermas}{%
              Number of pages may have changed.\MessageBreak%
              Rerun to get it right%
             }%
            }%
        \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{%
  \gdef\papermas@undefined{\textbf{??}}
  \gdef\papermas@rerun{0}
  \ifx\papermasstotal\papermas@undefined        \gdef\papermas@rerun{1} \fi
  \ifx\papermasformat\papermas@undefined        \gdef\papermas@rerun{1} \fi
  \ifx\papermasmasss\papermas@undefined         \gdef\papermas@rerun{1} \fi
  \ifx\papermaspagespersheet\papermas@undefined \gdef\papermas@rerun{1} \fi
  \ifx\papermassheets\papermas@undefined        \gdef\papermas@rerun{1} \fi
  \ifx\papermas@rerun\pagesLTS@one
    \AtEndAfterFileList{
      \PackageWarningNoLine{papermas}{%
        Variable(s) still undefined!\MessageBreak%
        Rerun to get the variable(s) right%
       }
     }
  \fi
  }

\AfterLastShipout{%
  \papermas@totmass%
  }%

\newcommand{\papermas@log}[1]{%
  \ifnum#1>9%
    \addtocounter{pagesLTS.pnc.0}{1}%
    \papermas@log{\intcalcDiv{#1}{10}}%
  \fi%
  }

\newcommand{\papermas@spaces}[2]{%
  \edef\papermas@remember{\arabic{pagesLTS.pnc.0}}%
  \setcounter{pagesLTS.pnc.0}{1}%
  \papermas@log{#1}%
  \addtocounter{pagesLTS.pnc.0}{-#2}%
  \multiply \value{pagesLTS.pnc.0} -1%
  \papermas@space{\arabic{pagesLTS.pnc.0}}%
  \message{*^^J}%
  \setcounter{pagesLTS.pnc.0}{\papermas@remember}%
  }

\newcommand{\papermas@space}[1]{%
  \ifnum \value{pagesLTS.pnc.0}>0%
    \message{}%
  \fi%
  \setcounter{pagesLTS.pnc.0}{#1}%
  \addtocounter{pagesLTS.pnc.0}{-1}%
  \ifnum \value{pagesLTS.pnc.0}>0%
    \papermas@space{\arabic{pagesLTS.pnc.0}}%
  \fi%
  }

\AtEndAfterFileList{%
  \ifx\papermas@rerun\pagesLTS@zero%
    \message{^^J}%
    \message{papermas: ******************** Paper mass ********************^^J}%
    \message{papermas: * This document consists of \arabic{pagesLTS.pagenr} pages.}
    \papermas@spaces{\arabic{pagesLTS.pagenr}}{16}%
    \message{papermas: * When printing \papermaspagespersheet\space pages on one sheet of paper,}
    \papermas@spaces{\papermaspagespersheet}{6}%
    \message{papermas: * \papermassheets\space sheets will be needed.}
    \papermas@spaces{\papermassheets}{26}%
    \message{papermas: * For ISO A \papermasformat\space paper of \papermasmasss\space g/m^2 specific mass,}
    \papermas@spaces{\papermasmasss}{7}%
    \message{papermas: * the printout will have a mass of about \papermasstotal\space g.}
    \papermas@spaces{\papermas@mbs}{5}%
    \message{papermas: ****************************************************^^J}
    \message{^^J}
  \fi%
  }

\newcommand\papermas@powerof[2]{%
  \PackageError{papermas}{Obsolete command \string\papermas@powerof\space used}{%
    The command \string\papermas@powerof\space has been removed from the papermas package.\MessageBreak%
    Please use e.g. \string\intcalcPow\space from the intcalc package instead.\MessageBreak%
    You can now just type Return to continue, but this error message will be\MessageBreak%
    issued again when using \string\papermas@powerof,\space and the command might be\MessageBreak%
    removed completely from future versions of the papermas package.\MessageBreak%
   }%
  \AtEndAfterFileList{%
    \message{^^J%
      papermas: Please remember to replace the \string\papermas@powerof\space command!^^J^^J%
     }%
   }%
  \pagesLTS@ifcounter{papermas@result}%
  \setcounter{papermas@result}{\intcalcPow{#1}{#2}}%
  }

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