3

This really refers to the following posting:

How do I insert names into birthday invitations automatically?

I've tried to used the suggested LaTeX coding in LyX and don't quite seem to get it to work.

Does anyone know if this is actually achievable in LyX or would I need to go back to native LaTeX code?

Here's an example - I would need to exchange the full name several times:

enter image description here

2 Answers 2

3

My approach (in LyX) is based on the LaTeX package "datatool".

For the name list, create a simple text file "studentlist.csv" with one name per line. The first line contains a heading!

Student Name
Peter M.
Tom J.

For the LyX document, add following to the "LaTeX Preamble":

\usepackage{datatool}
% load database 'studentlist' from file '/home/tux/studentlist.csv';
% in LyX the absolute path to the file is *necessary*!
\DTLloaddb{studentlist}{/home/tux/studentlist.csv}

Then write the main document starting with the following TeX code/ERT:

\DTLforeach{studentlist}
{\name=Student Name}
{

Write the main part of the document (Would a sans serif font look better?) and replace the names with TeX code/ERT \name. (The package "datatool" can do much more complex stuff, e.g., adding more fields or creating conditional texts - see this example or datatool user documentation.) Probably you would also like to set "Page Layout > Headings style: empty".

Finally, insert a "Clear Page" and put as TeX code/ERT }. This will looks like:

picture of lyx document

1
  • Brilliant. Thank you very much! I was nearby there, but my CSV file didn't have a header and I also missed out the "clear page"! Commented Apr 18, 2013 at 18:53
1

What I did when faced with something similar (mail the requests for a program committee to review papers) was to write a skeleton file using markers for the data to be replaced (reviever name, email, papers to review, ...) and use a Perl script to take the values from a simple file (fields separated by ';', essentially) to write a specific message for each member.

With LaTeX I'd probably create a skeleton that \includes a file defining macros, and switch those around.

5
  • The Perl solution sounds interesting. Does this mean that you end up with multiple files that you then need to compile separately? Commented Apr 18, 2013 at 18:59
  • @JoanneDemmler, that was what I did, yes. Or more precisely, I wrote a script that created a message to email from the template and the line with values on the fly and sent it out. Here I'd use the template to create a .tex, pdflatex it to PDF, rename/move to the final destination and go for the next entry in the control file. Here it is simpler, perhaps create files for each recipient, which \includes the template after defining commands for name and such?
    – vonbrand
    Commented Apr 18, 2013 at 19:05
  • I've played around with the macro and \include version for a while, but LyX bombarded me with unhelpful error messages (something about too may #'s). Another time... Commented Apr 18, 2013 at 19:15
  • @JoanneDemmler, dump LyX. Use a honest text editor and command line, as Knuth intendeth.
    – vonbrand
    Commented Apr 18, 2013 at 19:26
  • 1
    I probably just got something wrong in the preamble. I don't mind plain LaTeX for shortish documents, but I get badly lost in my code in very long documents. Commented Apr 18, 2013 at 19:30

You must log in to answer this question.

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