3

Original Text below

Edit: I solved it with endless googleing and help from here. Here is my theory: the typos caused expandafter to fail, which caused a dismatch between the chopline command and the rest of the chopped line of the previous loop. Another error was the ifeof. Latex tried to read one line after eof. This caused "read to" to fail

Working code:

The format of the csv must be

academicTitle(might be empty);surname;prename;Street+Number;ZIP-code;city;addressExtension;postbox(0 or certainValue)\n

File begins here:

\documentclass[12pt,a4paper,landscape]{article}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage{graphicx}
\usepackage[verbose]{placeins}


%What do we do? Delete all the margins!!! How do we do it? By force!!!
\setlength{\leftmargin}{0pt}
\setlength{\rightmargin}{0pt}
\setlength{\topmargin}{0pt}
\setlength{\textheight}{845pt}
\setlength{\hoffset}{-3.3in}
\setlength{\voffset}{-1.5in}
\setlength{\textheight}{845pt}
\setlength{\textwidth}{597pt}


%Personal chopline command from https://de.wikibooks.org/wiki/LaTeX-W%C3%B6rterbuch:_Serienbrief_mit_externen_Daten
\def\chopline#1;#2;#3;#4;#5;#6;#7;#8 \\{
\def\Titel{#1}
\def\Name{#2}
\def\Vorname{#3}
\def\Strasse{#4}
\def\PLZ{#5}
\def\Ort{#6}
\def\Adresszusatz{#7}
\def\Postfach{#8}
}

\newif\ifmore \moretrue



\begin{document}
\pagenumbering{gobble}

\newread\quelle
\openin\quelle=Adressen.csv %Here we get the addresses from

\loop

\read\quelle to\zeile
\ifeof\quelle
\global\morefalse
\else{

%write you stuff here

\newpage %gets ignored on first page


\expandafter\chopline\zeile\\
\vspace*{-0.02\paperwidth} %due to my Brief.pdf
\hspace*{0.0\paperheight}  %same here
\includegraphics[width=\paperwidth]{./Brief.pdf}

\FloatBarrier
\vspace*{-0.23\paperheight} %shift the box where desired
\hspace*{0.65\paperwidth}   %same here
\parbox{0.4\textwidth}{
\Titel \ \Vorname \ \Name \ \\
\ifx\Adresszusatz\empty %if it isn't empty, it is printed
\else
\Adresszusatz \\
\fi
\ifnum\Postfach=0 %if the value is 0 in the .csv, it isn't printed
\else
Postfach \ \Postfach
\fi
\Strasse \ \\
\PLZ \ \Ort
}

%stop with you writing here

}
\fi

\ifmore\repeat

\closein\quelle


\end{document}

Original Question:

This is my first question. I googled a lot, but I still haven't succeeded.

I have made an automatic generator for letter envelopes. This reads from a csv-file. I stick to the instruction given in de.wikibooks Serienbrief. But unfortunately it won't work.

I use Texmaker and MikTex on Windows 7, but I could change to Manjaro, if necessary.

This is my code:

Former code

It crashes after "read to". This seems to be the problem, but I ca'nt figure out why. Furthermore, the loop doesn't work in ANY way. No matter what kind of loop (loop, whiledo, for) I set up, it only loops once. Even if I set a for-loop to 30 repetitions. Actually it should produce 30 frames.

Don't judge me on using beamer for the envelopes. I would give more tags, but I'm not allowed to.

3
  • The first thing I spotted is \Straße, which will not work. You have to use \Strasse. Mar 23 '16 at 9:02
  • Also \NamensTitel should be \Titel and \Nachname is \Name
    – user31729
    Mar 23 '16 at 9:04
  • And value{Postfach} should be \Postfach.
    – cfr
    Mar 23 '16 at 18:00
3

Perhaps not the best way, but somewhat 'failsafe' is using the expl3 features and \ior_map_inline command that reads the file line by line and processes the input line.

I've used a sequence to split the line into the several relevant parts.

Please note, that white space must be entered with foo\ some other stuff!

\documentclass[12pt,a4paper]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
%\usepackage{amsmath}
%\usepackage{amsfonts}
%\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{forloop}

\usepackage{xparse}

\begin{document}



\ExplSyntaxOn
\int_const:Nn \c_maestro_titel_int {1}
\int_const:Nn \c_maestro_vorname_int {2}
\int_const:Nn \c_maestro_name_int {3}
\int_const:Nn \c_maestro_strasse_int {4}
\int_const:Nn \c_maestro_plz_int {5}
\int_const:Nn \c_maestro_ort_int {6}
\int_const:Nn \c_maestro_zusatz_int {7}
\int_const:Nn \c_maestro_postfach_int {8}


\ior_new:N \l_maestro_quelle_stream

\ior_open:Nn  \l_maestro_quelle_stream  {Adressen.csv}

\ior_map_inline:Nn \l_maestro_quelle_stream {%
  \seq_set_split:Nnn \l_tmpa_seq {;} {#1}% Split the sequence
  \begin{frame}
    \includegraphics[scale=0.2]{beeduck.jpg}\par

%    \vspace{0.6\paperheight}
%    \hspace{0.6\paperheight}????
    \seq_item:Nn \l_tmpa_seq {\c_maestro_titel_int}~\seq_item:Nn \l_tmpa_seq {\c_maestro_vorname_int}~\seq_item:Nn \l_tmpa_seq {\c_maestro_name_int}\par
    \tl_set:Nx \l_tmpa_tl {\seq_item:Nn \l_tmpa_seq {\c_maestro_zusatz_int}}
    \tl_if_empty:NF \l_tmpa_tl {%
      \tl_use:N \l_tmpa_tl\par
    }
    \tl_set:Nx \l_tmpa_tl {\seq_item:Nn \l_tmpa_seq {\c_maestro_postfach_int}}
    \tl_if_empty:NF \l_tmpa_tl {%
      Postfach~\tl_use:N \l_tmpa_tl\par
    }
    \seq_item:Nn \l_tmpa_seq {\c_maestro_strasse_int}\par
    \seq_item:Nn \l_tmpa_seq {\c_maestro_plz_int}~\seq_item:Nn \l_tmpa_seq {\c_maestro_ort_int}
  \end{frame}
}
\ExplSyntaxOff


\end{document}

And Adressen.csv is here:

;Gandalf;Stormcrow;Shireroad;10000;Shire;bei\ Schmidt;11111
;Baggins;Bilbo;Shireroad;10000;Shire;bei\ Müller;22222
Dwarf-King;Thorin;Oak-Shield;Erebor\ Road;Middle\ Earth;Arkenstone;at\ Smaug's\ cave;33333

enter image description here

1
  • Since this is a solutions, I mark this as solution, though I solved it myself. Mar 26 '16 at 11:10

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.