5

I want to create labels with barcodes. The individual barcodes should be a sequence of numbers which identify objects. After some trial and error, the GS1 package seemed to work for me.

Since I have a sequence of numbers, it seems natural to use a for loop. The problem which arises is that the generated barcodes are all 0-valued.

Maybe the problem is that \EANBarcode expects a string instead of an integer. I don't know how LaTeX handles variable types and how to convert the number 1 to the string "1" and if this is relevant here.

\documentclass[a4paper]{article}
\usepackage{labels}
\usepackage{GS1}
\usepackage{forloop}

\LabelCols=4
\LabelRows=11

\GSSetup{module_height=15mm}

\begin{document}
    \newcounter{loop}
    \forloop{loop}{1}{\value{loop} < 45}{
        \addresslabel{
            \EANBarcode{\arabic{loop}}
        }
    }
\end{document}
1
  • Hi. Pay attention to the fact that the EAN last digit is a checksum that depends on the first twelve. So, the loop fail to build correct input code for the EAN barcode symbology.
    – robitex
    Feb 25, 2020 at 14:34

1 Answer 1

4

You have to pass \EANBarcode an explicit number:

\documentclass[a4paper]{article}
\usepackage{labels}
\usepackage{GS1}
\usepackage{forloop}

\LabelCols=4
\LabelRows=11

\GSSetup{module_height=15mm}

\begin{document}

\newcounter{loop}
\forloop{loop}{1}{\value{loop} < 45}{%
  \addresslabel{%
    \expandafter\EANBarcode\expandafter{\the\value{loop}}%
  }%
}

\end{document}

enter image description here

Shorter code with expl3:

\documentclass[a4paper]{article}
\usepackage{labels}
\usepackage{GS1}
\usepackage{expl3}

\LabelCols=4
\LabelRows=11

\GSSetup{module_height=15mm}

\begin{document}

\ExplSyntaxOn
\int_step_inline:nnnn { 1 } { 1 } { 44 }
 {
  \addresslabel{\EANBarcode{#1}}
 }
\ExplSyntaxOff

\end{document}
1
  • Thank you, I suspected it was a type problem but I couldn't find any pointer on the web.
    – jaj
    Feb 12, 2016 at 21:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .