2

I'm generating a bulk letter using datatool. Therefore I import my data from an external csv-file using the following syntax:

\documentclass[11pt]{dinbrief}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{lmodern}
\usepackage[separator=;]{datatool}
\newrobustcmd{\companyrobust}{\parbox[b]{7.5cm}{\raggedright\company}}
\begin{document}
\inputencoding{latin1}
\DTLloadrawdb{addr}{list.csv} % open database
\inputencoding{utf8}
\DTLforeach{addr}{
  \company=company,
  \firstname=firstname,
  \surname=surname%
}{ % start bulk letter
\begin{letter}{\companyrobust\\\firstname\ \surname}
\subject{\textbf{test}}
\opening{Dear Mr. \surname,}
nothing
\closing{regards}
\end{letter}
}
\end{document}

the corresponding list.csv is the following:

company;firstname;surname
Microsoft Software;Bill;Gates

This was working for me for quite a while but now I have the problem that there is a company in my list which has a linebreak in its name. For example I want to put "Software" in a new line. I tried using \\, \linebreak and \newline but I it did not work and I could not figure out how to succeed. How can I realize a defined line break within a field of the csv-file?

  • Please provide a minimal working example (MWE) document showing how you're using the data in the document (for example, are you just using the standard letter class with the letter environment), and also a short sample csv file with an example entry that needs a line break. – Nicola Talbot Nov 2 '14 at 19:43
  • I extended my question with a complete MWE – bene Nov 3 '14 at 7:02
  • Is this list of company values created automatically? In your setup you could use Microsoft\DTLpar Software and avoid using a line-break in the actual CSV. – Werner Nov 3 '14 at 7:10
  • Yes, it is created automatically. But it wouldn't be a problem to insert the \DTLpar at the appropriate points in the csv file. However, if I insert it, latex gives me an error and does not compile. – bene Nov 3 '14 at 9:43
  • What error message do you get? – Nicola Talbot Nov 3 '14 at 10:08
4

If you want to include LaTeX commands in your csv file, you can't use \DTLloadrawdb. If you switch to \DTLloaddb instead, your example works fine with \DTLpar.

list.csv:

company;firstname;surname
Microsoft\DTLpar Software;Bill;Gates

Test file:

\documentclass[11pt]{dinbrief}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{lmodern}
\usepackage[separator=;]{datatool}
\newrobustcmd{\companyrobust}{\parbox[b]{7.5cm}{\raggedright\company}}
\begin{document}
\inputencoding{latin1}
\DTLloaddb{addr}{list.csv} % open database
\inputencoding{utf8}
\DTLforeach{addr}{
  \company=company,
  \firstname=firstname,
  \surname=surname%
}{ % start bulk letter
\begin{letter}{\companyrobust\\\firstname\ \surname}
\subject{\textbf{test}}
\opening{Dear Mr. \surname,}
nothing
\closing{regards}
\end{letter}
}
\end{document}

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.