Debian Codegraph @

texmf-dist/source/latex/postage/postage.dtx

raw
1 % \iffalse meta-comment
2 % !TEX program = pdfLaTeX
3 %<*internal>
4 \iffalse
5 %</internal>
6 %<*readme>
7 ----------------------------------------------------------------
8 postage --- Franking letters with »Deutsche Post«'s online postage service »Internetmarke«
9 E-mail: [email protected]
10 Released under the LaTeX Project Public License v1.3c or later
11 See http://www.latex-project.org/lppl.txt
12 ----------------------------------------------------------------
13
14 Franking letters with »Deutsche Post«'s online postage service »Internetmarke«.
15 %</readme>
16 %<*internal>
17 \fi
18 \def\nameofplainTeX{plain}
19 \ifx\fmtname\nameofplainTeX\else
20 \expandafter\begingroup
21 \fi
22 %</internal>
23 %<*install>
24 \input docstrip.tex
25 \keepsilent
26 \askforoverwritefalse
27 \preamble
28 ----------------------------------------------------------------
29 postage --- Franking letters with »Deutsche Post«'s online postage service »Internetmarke«
30 E-mail: [email protected]
31 Released under the LaTeX Project Public License v1.3c or later
32 See http://www.latex-project.org/lppl.txt
33 ----------------------------------------------------------------
34
35 \endpreamble
36 \postamble
37
38 Copyright (C) 2018 by Jan Heinrich Reimer <[email protected]>
39
40 This work may be distributed and/or modified under the
41 conditions of the LaTeX Project Public License (LPPL), either
42 version 1.3c of this license or (at your option) any later
43 version. The latest version of this license is in the file:
44
45 http://www.latex-project.org/lppl.txt
46
47 This work is "maintained" (as per LPPL maintenance status) by
48 Jan Heinrich Reimer.
49
50 This work consists of the file postage.dtx
51 and the derived files postage.ins,
52 postage.pdf and
53 postage.sty.
54
55 \endpostamble
56 \usedir{tex/latex/postage}
57 \generate{
58 \file{\jobname.sty}{\from{\jobname.dtx}{package}}
59 }
60 %</install>
61 %<install>\endbatchfile
62 %<*internal>
63 \usedir{source/latex/postage}
64 \generate{
65 \file{\jobname.ins}{\from{\jobname.dtx}{install}}
66 }
67 \nopreamble\nopostamble
68 \usedir{doc/latex/postage}
69 \generate{
70 \file{README.txt}{\from{\jobname.dtx}{readme}}
71 }
72 \ifx\fmtname\nameofplainTeX
73 \expandafter\endbatchfile
74 \else
75 \expandafter\endgroup
76 \fi
77 %</internal>
78 %<*package>
79 \NeedsTeXFormat{LaTeX2e}
80 \ProvidesPackage{postage}[2018/05/29 v1.0 Franking letters with »Deutsche Post«'s online postage service »Internetmarke«]
81
82 \RequirePackage{graphicx}
83 \RequirePackage{tikz}
84 \RequirePackage{calc}
85 \RequirePackage{keyval}
86 %</package>
87 %<*driver>
88 \documentclass{ltxdoc}
89 \usepackage[a4paper,top=3cm,bottom=3cm,left=5cm,right=3cm]{geometry}
90 \usepackage[english]{babel}
91 \usepackage[utf8]{inputenc}
92 \usepackage[T1]{fontenc}
93 \usepackage[default,regular,bold]{sourceserifpro}
94 \usepackage[semibold]{sourcesanspro}
95 \usepackage{sourcecodepro}
96 \usepackage{\jobname}
97 \usepackage[numbered]{hypdoc}
98 \usepackage{hyperref}
99 \usepackage{xcolor}
100 \usepackage{titlesec}
101 \usepackage{listings}
102 \usepackage{float}
103 \hypersetup{
104 colorlinks = false,
105 }
106 \lstset{
107 language=TeX,
108 basicstyle=\ttfamily,
109 breakatwhitespace=false,
110 breaklines=true,
111 prebreak={\mbox{$\hookleftarrow$}},
112 numbers=left,
113 numberstyle=\scriptsize,
114 numbersep=1pt,
115 % commentstyle=\color{lscomment},
116 keepspaces=true,
117 % keywordstyle=\bfseries\color{lskeyword},
118 stringstyle=\color{lsstring},
119 tabsize=4,
120 xleftmargin=1em,
121 }
122 \titleformat{\section}{\sf\LARGE\bfseries}{\thesection}{1em}{}
123 \titleformat{\subsection}{\sf\Large\bfseries}{\thesubsection}{1em}{}
124 \titleformat{\subsubsection}{\sf\large\bfseries}{\thesubsubsection}{1em}{}
125 \setlength{\parindent}{0pt}
126 \EnableCrossrefs
127 \CodelineIndex
128 \RecordChanges
129 \begin{document}
130 \DocInput{\jobname.dtx}
131 \end{document}
132 %</driver>
133 % \fi
134 %
135 %\GetFileInfo{\jobname.sty}
136 %
137 %\title{\sf\fontseries{sb}^^A
138 % The \textbf{postage} package^^A
139 % \footnote{This document describes version \fileversion, last revised \filedate.}^^A
140 %}
141 %\author{\sf ^^A
142 % Jan Heinrich Reimer^^A
143 % \footnote{Address: Barfüßerstraße 7, 06108 Halle (Saale), Germany} \\
144 % \texttt{\small [email protected]}^^A
145 %}
146 %\date{\sf^^A
147 % Released \filedate
148 %}
149 %
150 %\maketitle
151 %
152 %\tableofcontents
153 %
154 %\section{Introduction}
155 %
156 % The \textsf{postage} package is used for franking letters
157 % with \frqq Deutsche Post\flqq's
158 % online postage service \frqq Internetmarke\flqq.
159 %
160 %\changes{v1.0}{2018/05/29}{First public release}
161 %
162 %\section{Usage}
163 %
164 %\subsection{Requirements}
165 %
166 % Note that in order to print valid stamps
167 % the \marg{file} argument of any of this package's commands
168 % \emph{must} point to a valid PDF
169 % of \frqq Deutsche Post\flqq's \frqq Ausdruck 4-spaltig (DIN A4)\flqq{} format.^^A
170 % \footnote{See also section \ref{outlook}.}
171 %
172 %\subsection{Commands}
173 %
174 %\addcontentsline{toc}{subsection}{\cs{includestamp}}\label{sec:includestamp}
175 %\DescribeMacro{\includestamp}
176 % The \cs{includestamp}\oarg{options}\marg{file} command loads a single stamp
177 % from the file spceified in its mandatory \marg{file} argument
178 % and draws it on the page.
179 % The additional \hyperref[sec:includestamp:options]{\oarg{options}} can be used to
180 % specify the stamps position in the \marg{file}
181 % and the stamp's appearance.
182 %
183 %\subsubsection*{Options \oarg{options}}\label{sec:includestamp:options}
184 %
185 %\DescribeMacro{style=$\langle$normal$\vert$compact$\rangle$}
186 % The stamp's appearance; may either be \texttt{normal} or \texttt{compact}.
187 %
188 %\DescribeMacro{normal}
189 % Set the stamp's appearance to \texttt{normal}. Same as \texttt{style=normal}.
190 %
191 %\DescribeMacro{compact}
192 % Set the stamp's appearance to \texttt{compact}. Same as \texttt{style=compact}.
193 %
194 %\DescribeMacro{page=$\langle$1\textellipsis$\rangle$}
195 % The stamp's page from which to copy the stamp from the stamps PDF file. Pages count from 1.
196 %
197 %\DescribeMacro{row=$\langle$1\textellipsis8$\rangle$}
198 % The stamp's row on the page. Rows count from 1 to 8.
199 %
200 %\DescribeMacro{column=$\langle$1\textellipsis4$\rangle$}
201 % The stamp's column on the page. Rows count from 1 to 4.
202 %
203 %\subsubsection*{Example}
204 %
205 % The following code generates figure \ref{fig:sample:1}:
206 % \iffalse
207 %<*example>
208 % \fi
209 \begin{lstlisting}[language=tex]
210 \includestamp{sample-stamps}
211 \end{lstlisting}
212 % \iffalse
213 %<*example>
214 % \fi
215 % or
216 % \iffalse
217 %</example>
218 % \fi
219 \begin{lstlisting}[language=tex]
220 \includestamp[page=1,row=1,column=1,normal]{sample-stamps}
221 \end{lstlisting}
222 % \iffalse
223 %</example>
224 % \fi
225 %
226 % \begin{figure}[H]
227 % \centering
228 % \includestamp{sample-stamps}%
229 % \quad%
230 % \frame{\includestamp{sample-stamps}}
231 % \caption{A normal-sized stamp (taken from \frqq Deutsche Post\flqq's sample PDF).}\label{fig:sample:1}
232 % \end{figure}
233 %
234 % The following code generates figure \ref{fig:sample:2}:
235 % \iffalse
236 %<*example>
237 % \fi
238 \begin{lstlisting}[language=tex]
239 \includestamp[compact]{sample-stamps}
240 \end{lstlisting}
241 % \iffalse
242 %</example>
243 % \fi
244 % or
245 % \iffalse
246 %<*example>
247 % \fi
248 \begin{lstlisting}[language=tex]
249 \includestamp[row=1,column=1,style=normal]{sample-stamps}
250 \end{lstlisting}
251 % \iffalse
252 %</example>
253 % \fi
254 %
255 % \begin{figure}[H]
256 % \centering
257 % \includestamp[compact]{sample-stamps}%
258 % \quad%
259 % \frame{\includestamp[compact]{sample-stamps}}
260 % \caption{The same stamp in its compact representation.}\label{fig:sample:2}
261 % \end{figure}
262 %
263 %\iffalse
264 %<*package>
265 %\fi
266 %
267 %\section{Implementation}
268 %
269 %\subsection{Initialization}
270 %
271 %\subsubsection{Options}
272 %
273 % Define the stamp's display styles, the default display style
274 % and the according command options
275 % \texttt{style}, \texttt{compact} and \texttt{normal}.
276 % \begin{macrocode}
277 \def\postage@stamp@style@normal{normal}
278 \def\postage@stamp@style@compact{compact}
279 \let\postage@current@stamp@style\postage@stamp@style@normal
280 \define@key{postage}{style}{%
281 \def\postage@current@stamp@style{#1}%
282 }
283 \define@key{postage}{compact}[true]{%
284 \let\postage@current@stamp@style\postage@stamp@style@compact%
285 }
286 \define@key{postage}{normal}[true]{%
287 \let\postage@current@stamp@style\postage@stamp@style@compact%
288 }
289 % \end{macrocode}
290 %
291 % Define the stamp's page, row and column
292 % on the \frqq Internetmarke\flqq{} PDF,
293 % their defaults and the according command options
294 % \texttt{page}, \texttt{row} and \texttt{column}.
295 % \begin{macrocode}
296 \def\postage@current@stamp@page{1}
297 \def\postage@current@stamp@row{1}
298 \def\postage@current@stamp@column{1}
299 \define@key{postage}{page}{%
300 \def\postage@current@stamp@page{#1}%
301 }
302 \define@key{postage}{row}{%
303 \def\postage@current@stamp@row{#1}%
304 }
305 \define@key{postage}{column}{%
306 \def\postage@current@stamp@column{#1}%
307 }
308 % \end{macrocode}
309 %
310 %\subsubsection{Lengths}
311 %
312 % Create the lengths describing the stamp's
313 % position, height and width on the PDF page
314 % as well as each stamp's parts relative to
315 % the stamp's position.
316 % \begin{macrocode}
317 \newlength{\postage@page@width}
318 \newlength{\postage@page@height}
319 \newlength{\postage@grid@width}
320 \newlength{\postage@grid@height}
321 \newlength{\postage@grid@x}
322 \newlength{\postage@grid@y}
323 \newlength{\postage@stamp@content@width}
324 \newlength{\postage@stamp@content@height}
325 \newlength{\postage@stamp@content@x}
326 \newlength{\postage@stamp@content@y}
327 \newlength{\postage@stamp@barcode@width}
328 \newlength{\postage@stamp@barcode@height}
329 \newlength{\postage@stamp@barcode@x}
330 \newlength{\postage@stamp@barcode@y}
331 \newlength{\postage@stamp@barcode@text@width}
332 \newlength{\postage@stamp@logo@width}
333 \newlength{\postage@stamp@logo@height}
334 \newlength{\postage@stamp@logo@x}
335 \newlength{\postage@stamp@logo@y}
336 % \end{macrocode}
337 %
338 % Save the lengths describing
339 % \frqq Deutsche Post\flqq's \frqq Internetmarke\flqq
340 % in its \frqq Ausdruck 4-spaltig (DIN A4)\flqq{} format.
341 % All measurments below have been taken
342 % from \frqq Deutsche Post\flqq's
343 % official sample PDF using the Inkscape vector editor
344 % with a precision of $\pm$0.0005mm
345 % \begin{macrocode}
346 \setlength{\postage@page@width}{209.99979mm}
347 \setlength{\postage@page@height}{296.99973mm}
348 \setlength{\postage@grid@width}{40mm}
349 \setlength{\postage@grid@height}{32.999mm}
350 \setlength{\postage@grid@x}{22.5mm}
351 \setlength{\postage@grid@y}{14.05473mm}
352 \setlength{\postage@stamp@content@width}{31.639mm}
353 \setlength{\postage@stamp@content@height}{22.473mm}
354 \setlength{\postage@stamp@content@x}{3.024mm}
355 \setlength{\postage@stamp@content@y}{2.855mm}
356 \setlength{\postage@stamp@barcode@width}{30.862mm}
357 \setlength{\postage@stamp@barcode@height}{11.01mm}
358 \setlength{\postage@stamp@barcode@x}{3.009mm}
359 \setlength{\postage@stamp@barcode@y}{11.029mm}
360 \setlength{\postage@stamp@barcode@text@width}{15.732mm}
361 \setlength{\postage@stamp@logo@width}{31.639mm}
362 \setlength{\postage@stamp@logo@height}{5.282mm}
363 \setlength{\postage@stamp@logo@x}{3.024mm}
364 \setlength{\postage@stamp@logo@y}{2.855mm}
365 % \end{macrocode}
366 %
367 % Create temporary lengths that are calculated individually
368 % for each stamp.
369 % \begin{macrocode}
370 \newlength{\postage@current@stamp@x}
371 \newlength{\postage@current@stamp@y}
372 \newlength{\postage@current@stamp@trim@left}
373 \newlength{\postage@current@stamp@trim@bottom}
374 \newlength{\postage@current@stamp@trim@right}
375 \newlength{\postage@current@stamp@trim@top}
376 % \end{macrocode}
377 %
378 %\subsection{Calculating position}
379 %
380 %\begin{macro}{\postage@calculate@current@stamp@position}
381 % Calculate the current stamp's position on the page
382 % based on its \texttt{row}
383 % and \texttt{column} options.
384 % \begin{macrocode}
385 \newcommand{\postage@calculate@current@stamp@position}{
386 \setlength{\postage@current@stamp@x}{
387 \postage@grid@x +
388 \postage@grid@width *
389 (\postage@current@stamp@column - 1)
390 }%
391 \setlength{\postage@current@stamp@y}{
392 \postage@grid@y +
393 \postage@grid@height *
394 (\postage@current@stamp@row - 1)
395 }%
396 }
397 % \end{macrocode}
398 %\end{macro}
399 %
400 %\subsection{Drawing}
401 %
402 %\begin{macro}{\postage@draw@current@stamp@part}
403 % Draw a part of the current stamp whose trim offsets
404 % were previously calculated using \cs{postage@calculate@current@stamp@position}.
405 % \begin{macrocode}
406 \newcommand{\postage@draw@current@stamp@part}[1][]{%
407 \includegraphics[page=\postage@current@stamp@page, trim={
408 {1\postage@current@stamp@trim@left}
409 {1\postage@current@stamp@trim@bottom}
410 {1\postage@current@stamp@trim@right}
411 {1\postage@current@stamp@trim@top}
412 }, clip, #1]{\postage@current@stamp@file}%
413 }
414 % \end{macrocode}
415 %\end{macro}
416 %
417 %\begin{macro}{\postage@draw@current@stamp@content}
418 % Draw the current stamp's whole content trimming whitespace around it.
419 % \begin{macrocode}
420 \newcommand{\postage@draw@current@stamp@content}{%
421 \setlength{\postage@current@stamp@trim@top}{
422 \postage@current@stamp@y +
423 \postage@stamp@content@y
424 }%
425 \setlength{\postage@current@stamp@trim@left}{
426 \postage@current@stamp@x +
427 \postage@stamp@content@x
428 }%
429 \setlength{\postage@current@stamp@trim@bottom}{
430 \postage@page@height -
431 \postage@current@stamp@trim@top -
432 \postage@stamp@content@height
433 }%
434 \setlength{\postage@current@stamp@trim@right}{
435 \postage@page@width -
436 \postage@current@stamp@trim@left -
437 \postage@stamp@content@width
438 }%
439 \postage@draw@current@stamp@part%
440 }
441 % \end{macrocode}
442 %\end{macro}
443 %
444 %\begin{macro}{\postage@draw@current@stamp@barcode}
445 % Draw only the current stamp's barcode (and the included number code).
446 % \begin{macrocode}
447 \newcommand{\postage@draw@current@stamp@barcode}{%
448 \setlength{\postage@current@stamp@trim@top}{
449 \postage@current@stamp@y +
450 \postage@stamp@barcode@y
451 }%
452 \setlength{\postage@current@stamp@trim@left}{
453 \postage@current@stamp@x +
454 \postage@stamp@barcode@x
455 }%
456 \setlength{\postage@current@stamp@trim@bottom}{
457 \postage@page@height -
458 \postage@current@stamp@trim@top -
459 \postage@stamp@barcode@height}%
460 \setlength{\postage@current@stamp@trim@right}{
461 \postage@page@width -
462 \postage@current@stamp@trim@left -
463 \postage@stamp@barcode@width
464 }%
465 \postage@draw@current@stamp@part%
466 }
467 % \end{macrocode}
468 %\end{macro}
469 %
470 %\begin{macro}{\postage@draw@current@stamp@logo}
471 % Draw only the current stamp's \frqq Deutsche Post\flqq{} logo.
472 % \begin{macrocode}
473 \newcommand{\postage@draw@current@stamp@logo}{%
474 \setlength{\postage@current@stamp@trim@top}{
475 \postage@current@stamp@y +
476 \postage@stamp@logo@y
477 }%
478 \setlength{\postage@current@stamp@trim@left}{
479 \postage@current@stamp@x +
480 \postage@stamp@logo@x
481 }%
482 \setlength{\postage@current@stamp@trim@bottom}{
483 \postage@page@height -
484 \postage@current@stamp@trim@top -
485 \postage@stamp@logo@height
486 }%
487 \setlength{\postage@current@stamp@trim@right}{
488 \postage@page@width -
489 \postage@current@stamp@trim@left -
490 \postage@stamp@logo@width
491 }%
492 \postage@draw@current@stamp@part[%
493 width={1\postage@stamp@barcode@text@width}
494 ]%
495 }
496 % \end{macrocode}
497 %\end{macro}
498 %
499 %\begin{macro}{\postage@draw@current@stamp@style@compact}
500 % Draw the current stamp's compact representation.
501 % This will print a scaled-down version of the
502 % \frqq Deutsche Post\flqq{} logo in the upper-right corner
503 % of the barcode and trim the big logo
504 % and \frqq Internetmarke\flqq{} URL instead.
505 % \begin{macrocode}
506 \newcommand{\postage@draw@current@stamp@style@compact}{%
507 \begin{tikzpicture}
508 \node[anchor=north east, inner sep=0] at (0,0)
509 {\postage@draw@current@stamp@barcode};
510 \node[anchor=north east, inner sep=0] at (0,0)
511 {\postage@draw@current@stamp@logo};
512 \end{tikzpicture}%
513 }
514 % \end{macrocode}
515 %\end{macro}
516 %
517 %\begin{macro}{\postage@draw@current@stamp@style@normal}
518 % Draw the current stamp's whole content
519 % including the big \frqq Deutsche Post\flqq{} logo
520 % and \frqq Internetmarke\flqq{} URL,
521 % yet trimming whitespace around it.
522 % \begin{macrocode}
523 \newcommand{\postage@draw@current@stamp@style@normal}{%
524 \postage@draw@current@stamp@content%
525 }
526 % \end{macrocode}
527 %\end{macro}
528 %
529 %\begin{macro}{\includestamp}
530 % See the \hyperref[sec:includestamp]{usage documentation}.
531 % \begin{macrocode}
532 \newcommand{\includestamp}[2][]{%
533 \setkeys{postage}{#1}%
534 \def\postage@current@stamp@file{#2}%
535 \postage@calculate@current@stamp@position%
536 %
537 \ifx\postage@current@stamp@style\postage@stamp@style@compact%
538 \postage@draw@current@stamp@style@compact%
539 \else%
540 \postage@draw@current@stamp@style@normal%
541 \fi%
542 }
543 % \end{macrocode}
544 %\end{macro}
545 %\iffalse
546 %</package>
547 %\fi
548 %
549 %\section{Outlook}\label{outlook}
550 %
551 % In future this library may be extended
552 % to other postage service (potentially outside Germany).
553 % Then a \texttt{service} option could be set up to decide
554 % which format to use.
555 %
556 % Speaking of formats one could also think about implementing
557 % \frqq Deutsche Post\flqq's \frqq Ausdruck 3-spaltig (DIN A4)\flqq{} format
558 % to support more stamp types such as enrolls and/or mail tracking,
559 % which at the time of writing this package aren't supported in
560 % the \frqq Deutsche Post\flqq's \frqq Internetmarke\flqq{}
561 % in \frqq Ausdruck 4-spaltig (DIN A4)\flqq{} format.
562 %
563 %\StopEventually{^^A
564 % \PrintChanges
565 % \PrintIndex
566 %}
567 %
568 %\Finale
569 \endinput