I am writing a form letter in latex. The addresses come from an external data source. The problem is that empty fields occur (quite frequently, actually) in the data source (see below). Therefore, because of \def\chopline#1,#2,#3,#4,#5,#6,#7,#8 \\ the line \expandafter\chopline\zeile\\ somehow expects at least one character behind a comma and consumes it. If there is no data in one field, it will just "eat" the comma and include the next data field, leading to a complete mess. Any advice on how to migitate the problem would be helpful.

Besides, I copied this example some time ago and don't understand all commands and their implications. I have the impression the structure I use is rather old and might not be the safest way to implement the behaviour I desire. What more advanced tools that LuaLaTeX offers could I use to improve the code that implements the form letter?

This is the code:



\setmainfont{Linux Libertine O}
\setsansfont{Linux Biolinum O}
\setmonofont{Linux Libertine Mono O}

\def\chopline#1,#2,#3,#4,#5,#6,#7,#8 \\{

\newif\ifmore \moretrue




\read\quelle to \zeile

    \read\quelle to \zeile
        \begin{letter}{\firstname\ \lastname \\
        \postcode\ \town}

        \opening{Sehr geehrte Familie \lastname,}


        \closing{Best regards}




Here comes the data source (containing some dummies):

Barnes,Helen,,Apartment 3,Potsdamer Platz 10,Neukölln,99823,Görlitz,3714 2487824,8797 9717692,[email protected]
Thomas,Brandon,,,Dorfstraße 34d,,20903,Aachen,9214 3252403,,[email protected]
Kelley,Juan,,,Hauptstraße 11,,00495,Hamburg,6265 9683011,6263 6235169,[email protected]
Fisher,Anne,,,Berliner Straße 99,,39856,Oldenburg,0666 6226586,7917 5816244,
Sanchez,Martha,Miller,,Mittelweg 23,,11932,Leverkusen,3728 6123496,,[email protected]
Morrison,Daniel,,,Schulstraße 8,,11943,Neustadt,9589 2520624,
Brown,David,Clark,Room 42,Bahnhofstraße 12,Amorbach,12821,Neckarsulm,9304 3674329,,[email protected]
Graham,Frank,,,Lindenallee 19,,32956,Neustadt,,,[email protected]
Price,Douglas,,,Mühlweg 5e,,04923,Neustadt,7934 4700638,7689 9255281,[email protected]
  • 1
    With \def\foo#1,#2,#3 \\ the input \foo X,,Z \\ will assign #1<-X, #2<- (empty) and #3<-Z. None of the first seven commas in your code will be used as argument. Your problem seems to be that you have more than eight fields. Probably datatool is better for such a project, because it can handle any number of fields.
    – egreg
    Sep 30, 2014 at 21:33

1 Answer 1


Here's a solution using datatool (assuming the data is in test.csv, change as appropriate):



\setmainfont{Liberation Sans}% (I don't have the fonts from the original MWE)




    \begin{letter}{\FirstName\ \LastName\\%

    \opening{Sehr geehrt Familie \LastName,}


    \closing{Best regards}


You must log in to answer this question.

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