# Preserve label spacing dimensions when using mailmerge

I am making a sheet of address labels. Here is my first iteration:

\documentclass[letterpaper,12pt]{article}

\usepackage[newdimens]{labels}
\LabelCols=4
\LabelRows=6
\LeftPageMargin=20mm
\RightPageMargin=20mm
\TopPageMargin=13mm
\BottomPageMargin=12.5mm
\InterLabelColumn=8mm
\InterLabelRow=5mm
\LeftLabelBorder=0.2mm
\RightLabelBorder=0.2mm
\TopLabelBorder=0.2mm
\BottomLabelBorder=0mm

\LabelGridtrue % show grid for labels
\LabelInfotrue % show info for labels

\begin{document}

\begin{labels}
A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X
\end{labels}

\end{document}


Rather than manually writing all the labels in the body of the document, I wanted to store them in an external file. So I used the textmerg package, like in other questions.

\documentclass[letterpaper,12pt]{article}

\usepackage{textmerg}

\usepackage[newdimens]{labels}
\LabelCols=4
\LabelRows=6
\LeftPageMargin=20mm
\RightPageMargin=20mm
\TopPageMargin=13mm
\BottomPageMargin=12.5mm
\InterLabelColumn=8mm
\InterLabelRow=5mm
\LeftLabelBorder=0.2mm
\RightLabelBorder=0.2mm
\TopLabelBorder=0.2mm
\BottomLabelBorder=0mm

\LabelGridtrue % show grid for labels
\LabelInfotrue % show info for labels

\usepackage{filecontents}

\begin{filecontents*}{\jobname.dat}
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
\end{filecontents*}

\begin{document}

\Fields{\mylabel}

\Merge{\jobname.dat}{%
\mylabel
}%
}%

\end{document}


Unfortunately, the formatting has been disturbed in the switch. In particular, when I measure the column spacing with the Measure tool in Adobe Acrobat Reader DC, it comes to about 9.5 mm instead of 8 mm. This is a serious problem when printing onto sticky labels.

Here is a comparison of the two:

The original is in black, the second in red.

How can I iterate over an external file while keeping the original dimensions?

(If there is a way to use textmerg for this, I would be fine with that, but a method with, say, datatool or catchfile would be fine too.)

Here is a link to a Github repo to try it yourself if you're curious:

https://github.com/nbeaver/textmerg-labels-example

Edit: pull request has been submitted and accepted.

There's a spurious space in the package's definition of \ParseFields. This is a bug and should be reported to the maintainer.

In the meanwhile, you can provide a corrected definition in the preamble.

\def\ParseFields#1{%
\ifx#1\EndParseFields
\let\NextParse\relax
\else
\let\NextParse\ParseFields
\ifx#1+\DontAllowBlank
\else
\ifx#1-\AllowBlank
\fi
\fi
\fi\NextParse}


\begin{filecontents*}{\jobname.dat}
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
\end{filecontents*}
\documentclass[letterpaper,12pt]{article}
\usepackage{geometry}% without this I get A4
\usepackage{textmerg}

\usepackage[newdimens]{labels}
\LabelCols=4
\LabelRows=6
\LeftPageMargin=20mm
\RightPageMargin=20mm
\TopPageMargin=13mm
\BottomPageMargin=12.5mm
\InterLabelColumn=8mm
\InterLabelRow=5mm
\LeftLabelBorder=0.2mm
\RightLabelBorder=0.2mm
\TopLabelBorder=0.2mm
\BottomLabelBorder=0mm

\LabelGridtrue % show grid for labels
\LabelInfotrue % show info for labels

\usepackage{background}
\backgroundsetup{contents=\includegraphics{\jobname-a},scale=1,angle=0,opacity=1}

\def\ParseFields#1{%
\ifx#1\EndParseFields
\let\NextParse\relax
\else
\let\NextParse\ParseFields
\ifx#1+\DontAllowBlank
\else
\ifx#1-\AllowBlank
\fi
\fi
\fi\NextParse}

\begin{document}
\Fields{\mylabel}%
\Merge{\jobname.dat}{%
\mylabel
}%
}%
\end{document}

• I have a typo: letter should be letterpaper. This should fix the paper size issue. – Nathaniel M. Beaver Jul 25 '18 at 13:27
• The \unskip fixes horizontal column spacing, but messes up vertical spacing. I don't mean to shift the goalposts, but I'm going to add a full sheet so it's more apparent. – Nathaniel M. Beaver Jul 25 '18 at 13:34
• I can confirm that the fix works on my end. Sending a patch upstream is a commendable suggestion, but both the maintainers for the textmerg package are listed as inactive, and I got a bounce off the only email address listed in the documentation. – Nathaniel M. Beaver Jul 27 '18 at 12:54
• @NathanielM.Beaver Send it to the CTAN people in that case and include a link to this so they can tell what needs changing quickly. They may or may not do it, but they might. – cfr Jul 27 '18 at 22:26
• more of a holding group than maintainers but it looks like a clear bug, thanks for the PR – David Carlisle Jun 25 at 21:27