]> mj.ucw.cz Git - ucwmac.git/commitdiff
Added ucw-labels: simple macros for typesetting of labels (stickers)
authorMartin Mares <mj@ucw.cz>
Sat, 3 Aug 2013 11:07:58 +0000 (13:07 +0200)
committerMartin Mares <mj@ucw.cz>
Sat, 3 Aug 2013 11:07:58 +0000 (13:07 +0200)
Makefile
test-labels.tex [new file with mode: 0644]
ucw-labels.tex [new file with mode: 0644]

index 61f6b1d2f89dabacc6954ee1106a9fded9701f44..0f1fe1da9361d02795ce84be7afc2dd538b80581 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 VERSION=1.0
 ARCHIVE=ucwmac-$(VERSION).tar.gz
 
-all: test.ps
+all: test.pdf test-labels.pdf
 
 %.dvi: %.tex
        csplain $<
diff --git a/test-labels.tex b/test-labels.tex
new file mode 100644 (file)
index 0000000..ceb68b6
--- /dev/null
@@ -0,0 +1,21 @@
+\input ucwmac.tex
+\input ucw-labels.tex
+
+\setuplabels{3}{7}
+\labelrulestrue
+% \labelcropmarkstrue
+
+\label{xyzzy1 \vfil}
+\label{xyzzy2 \vfil}
+\label{xyzzy3 \vfil}
+\label{xyzzy4 \vfil}
+\label{xyzzy5 \vfil}
+\label{xyzzy6 \vfil}
+\label{xyzzy7 \vfil}
+\labels{3}{BRUM \vfil}
+
+\vfill\eject
+
+\labelfill{\hrule\vss\centerline{\it Arbiter Elegantiarum}\vss\hrule}
+
+\bye
diff --git a/ucw-labels.tex b/ucw-labels.tex
new file mode 100644 (file)
index 0000000..f6730b5
--- /dev/null
@@ -0,0 +1,90 @@
+%% Macros for typesetting of labels
+
+% Default page parameters. You can change them before calling \setuplabels.
+\setmargins{0pt}
+\setuppage
+
+% Do we want rules around each label?
+\newif\iflabelrules
+\labelrulesfalse
+
+% Do we want cropmarks?
+\newif\iflabelcropmarks
+\labelcropmarksfalse
+\def\labelcropm{\iflabelcropmarks\hbox to 0pt{\hss\vbox to \labelh{\crosshair{5pt}\vss\crosshair{5pt}}}\fi}
+
+% Margins of each label
+\newdimen\labelhmargin
+\labelhmargin=5mm
+
+\newdimen\labelvmargin
+\labelvmargin=5mm
+
+% Internals
+\newdimen\labelw
+\newdimen\labelh
+\newcount\labelnum
+
+% Prepare of typesetting of #2 rows per #1 labels
+\def\setuplabels#1#2{
+       \labelw=\hsize
+       \divide\labelw by #1
+       \labelh=\vsize
+       \divide\labelh by #2
+       \labelnum=#1
+       \multiply\labelnum by #2
+       \offinterlineskip
+       \parindent=0pt
+       \parskip=0pt
+       \rightskip=0pt plus 0.1pt
+}
+
+% Typeset one label as a box (in most cases, you want to use \label instead)
+\long\def\labelbox#1{\hbox to \labelw{%
+  \labelcropm
+  \iflabelrules\vrule\fi
+  \hss
+  \vbox to \labelh{%
+    \iflabelrules\hrule\fi
+    \vss
+    \hbox to \labelw{%
+      \hss
+      \vbox to \labelh{%
+        \vss
+        \dimen0=\labelh
+        \advance\dimen0 by -2\labelvmargin
+        \vbox to \dimen0{%
+          \hsize=\labelw
+          \advance\hsize by -2\labelhmargin
+          \normalbaselines
+          #1
+       }%
+        \vss
+      }%
+      \hss
+    }
+    \vss
+    \iflabelrules\hrule\fi
+  }%
+  \hss
+  \labelcropm
+  \iflabelrules\vrule\fi
+  }%
+}
+
+% Typeset one label (#1 is expected to have the exact height, so it usually ends with a \vfil)
+\long\def\label#1{\leavevmode\labelbox{#1}\penalty -100}
+
+% Typeset #1 copies of label #2
+\newcount\labelcount
+\long\def\labels#1#2{{\leavevmode\setbox0=\labelbox{#2}%
+  \labelcount=#1%
+  \loop
+    \copy0
+    \penalty -100
+    \advance\labelcount by -1
+  \ifnum\labelcount>0\repeat
+}}
+
+% Fill the whole page with copies of a label
+\long\def\labelfill#1{\labels\labelnum{#1}}