# Generate barcodes with a for loop

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}{
\EANBarcode{\arabic{loop}}
}
}
\end{document}

• 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 at 14:34

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}{%
\expandafter\EANBarcode\expandafter{\the\value{loop}}%
}%
}

\end{document}


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 }
{