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}
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}
  • Thank you, I suspected it was a type problem but I couldn't find any pointer on the web. – jaj Feb 12 '16 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.