%Mögliche Aufrufe: 
%pdflatex "\def\settings{mode=label, labelsetup={labelsetup.conf}}\input{LaTeXtutiX_3_etiketten}"
%Element innerhalb von \input ist der Dateiname
%lualatex/xelatex analog verwendbar
%ggf. + zusätzlich die Option -jobname=, falls mehrere Modi aus derselben Quelle erstellt werden sollen, ohne, dass überschrieben wird:
%pdflatex -jobname=document_labelmode "\def\settings{mode=label, labelsetup={labelsetup.conf}}\input{LaTeXtutiX_3_etiketten}"
\documentclass{scrartcl}
\usepackage{xparse}%lädt expl3 automatisch

%Fehlermeldung, falls \settings nicht gesetzt wurde
\ExplSyntaxOn
\cs_if_exist:NF \settings {
	\msg_new:nnn {LaTeXtut} {settingsundefined}
		{\protect\settings-macro~ ist~ undefined.~Please~provide~ a~ mode-setup~ to~ receive~ output.}
	\msg_fatal:nn {LaTeXtut} {settingsundefined}
}

%%%%%
%Anfang Listing 1: Einlesen und Aufbereiten der Daten
\ior_new:N \LaTeXtut_content_ior
\int_new:N \g_LaTeXtut_items_int
\seq_new:N \l_LaTeXtut_dataLine_seq
\NewDocumentCommand\CSVtoProp{m}{
	\ior_open:Nn \LaTeXtut_content_ior {#1}
	\tl_new:N \l_LaTeXtut_dataHeader_tl
	\ior_str_get:NN \LaTeXtut_content_ior \l_LaTeXtut_dataHeader_tl
	\seq_new:N \l_LaTeXtut_dataHeader_seq
	\seq_set_split:NnV \l_LaTeXtut_dataHeader_seq {;}
	\l_LaTeXtut_dataHeader_tl
	\int_zero:N \l_tmpa_int
	\seq_map_inline:Nn \l_LaTeXtut_dataHeader_seq
	{
		\int_incr:N \l_tmpa_int
		\cs_new:cx {LaTeXtut_##1_ColID:} {
			\int_use:N \l_tmpa_int
		}
	}
	\ior_map_inline:Nn \LaTeXtut_content_ior {
		\int_gincr:N \g_LaTeXtut_items_int
		\prop_new:c {g_LaTeXtut_data_\int_use:N \g_LaTeXtut_items_int _prop}
		\seq_set_split:Nnn \l_LaTeXtut_dataLine_seq {;} {##1}
		\seq_map_inline:Nn \l_LaTeXtut_dataHeader_seq
		{
			\prop_gput:cnx {g_LaTeXtut_data_\int_use:N \g_LaTeXtut_items_int _prop} {####1}
			{\seq_item:Nn \l_LaTeXtut_dataLine_seq {\use:c {LaTeXtut_####1_ColID:}}}
		}
	}
}
\ExplSyntaxOff
%Einlesevorgang zum Erhalten von Leerzeichen in Standard-LaTeX-Syntax
\CSVtoProp{inventar.csv}
%Ende Listing 1
%%%%%
%Anfang Listing 2: Datenausgabe
\ExplSyntaxOn
\tl_new:N \g_LaTeXtut_mode_tl
\keys_define:nn {LaTeXtut} {
	mode .choices:nn = {label, list} {
		\tl_gset:Nn \g_LaTeXtut_mode_tl {#1}
	}
}
%Setupdatei laden
\ior_new:N \LaTeXtut_setup_ior
\cs_new:Nn \LaTeXtut_load_setupFile:n {
	\ior_open:Nn \LaTeXtut_setup_ior {
		\tl_use:c {g_LaTeXtut_#1setup_tl} }
	\ior_map_inline:Nn \LaTeXtut_setup_ior {
		\keys_set:nn {LaTeXtut} {##1}
	}
	\ior_close:N \LaTeXtut_setup_ior
}
% Keys für den Modus Label
\keys_define:nn {LaTeXtut} {
	labelsetup .tl_gset:N = \g_LaTeXtut_labelsetup_tl,
	labelwidth .dim_gset:N = \g_LaTeXtut_labelwidth_dim,
	labelheight .dim_gset:N = \g_LaTeXtut_labelheight_dim,
	labelmargin .dim_gset:N = \g_LaTeXtut_labelmargin_dim,
}
\cs_new:Nn \LaTeXtut_activate_label_mode: {
	\LaTeXtut_load_setupFile:n {label}
	\usepackage{geometry}
	\geometry{
		paperwidth=\g_LaTeXtut_labelwidth_dim,
		paperheight=\g_LaTeXtut_labelheight_dim,
		margin=\g_LaTeXtut_labelmargin_dim
	}
	\let\TypesetElements\LaTeXtut_typeset_labels:
	\setlength{\parindent}{0pt}
}
\usepackage{qrcode}
\cs_new:Nn \LaTeXtut_typeset_label:n {
	\parbox{\dim_eval:n {\linewidth-1,5cm}}{
		\prop_item:cn {g_LaTeXtut_data_#1_prop} {ID}\par
		\prop_item:cn {g_LaTeXtut_data_#1_prop}
		{Name}~(\prop_item:cn {g_LaTeXtut_data_#1_prop} {Typ})\par
		\prop_item:cn {g_LaTeXtut_data_#1_prop} {IP}
	}
	\qrcode[height=1.5cm]{
		\prop_item:cn {g_LaTeXtut_data_#1_prop} {Netzwerkadresse}}
	\par
	\vfill
	Position:~
	\prop_item:cn {g_LaTeXtut_data_#1_prop} {Position}\par
	Kontakt:~
	\prop_item:cn {g_LaTeXtut_data_#1_prop} {Ansprechpartner}
}
\cs_new:Nn \LaTeXtut_typeset_labels: {
	\setlength{\parindent}{0pt}
	\int_step_inline:nnnn {1}{1}{\g_LaTeXtut_items_int} {
		\LaTeXtut_typeset_label:n {##1}
		\clearpage
	}
}
\usepackage{scrlayer}
\usepackage{graphicx}
\usepackage{tikz}

\definecolor{peitex}{cmyk}{0,.56,.94,0}

\DeclareNewLayer[
page,
background,
contents={\resizebox{\layerwidth}{\layerheight}{
		\begin{tikzpicture}
		\clip(0,0)rectangle(21,-15);
		\filldraw[peitex](-.1,.1)rectangle (1.2,-3.2)(.25,-3.2)rectangle(-.1,-29.8);
		\filldraw[peitex](0,0.1)rectangle(14,-.4);
		\end{tikzpicture}
}}
]{background}
\DeclareNewLayer[
textarea,
foreground,
contents={
	\begin{tikzpicture}
	\useasboundingbox(0,0)rectangle(\textwidth,-\textheight);
	\node[rectangle,draw,anchor=south~ east] at 
	(\textwidth,-\textheight){\includegraphics[width=1cm]{PeiTeX_logo}};
	\end{tikzpicture}
}
]{logo}
\DeclarePageStyleByLayers{label}{background,logo}
\cs_if_exist:NTF \settings{
	\exp_args:Nnx \keys_set:nn {LaTeXtut} {\settings}
	\use:c {LaTeXtut_activate_\tl_use:N \g_LaTeXtut_mode_tl _mode:}
} {\let\TypesetElements\relax}
\ExplSyntaxOff
\pagestyle{label}
%Dokumenteninhalt
\begin{document}
	\TypesetElements
\end{document}
%Ende Listing 2