TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 3 down vote accepted

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":

% load database 'studentlist' from file '/home/tux/studentlist.csv';
% in LyX the absolute path to the file is *necessary*!

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

{\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

share|improve this answer
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"! – Joanne Demmler Apr 18 '13 at 18:53

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.

share|improve this answer
The Perl solution sounds interesting. Does this mean that you end up with multiple files that you then need to compile separately? – Joanne Demmler Apr 18 '13 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 Apr 18 '13 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... – Joanne Demmler Apr 18 '13 at 19:15
@JoanneDemmler, dump LyX. Use a honest text editor and command line, as Knuth intendeth. – vonbrand Apr 18 '13 at 19:26
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. – Joanne Demmler Apr 18 '13 at 19:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.