Richard, Thank you so much. The other suggestions I received are very helpful for sending several letters at once, which I may do someday, but, as I am mostly in need of replacing names throughout long "stand-alone" documents, documents which contain standard content, your suggestions are exactly what I need.
John On Friday, March 31, 2017 6:13:49 PM PDT Richard Heck wrote: > On 03/31/2017 04:05 PM, John White wrote: > > I use lyx and am using it more and more in what I call "mailmerge" > > mode, similar to how I once used mailmerge in Wordstar. Once I have a > > good form document (say a will or a contract) I replace the names > > with, say "@name1" and then I replace all @name1 with the new data, > > e.g. "Judy Jones". > > > > > > > > This works fine, but on longer documents (say a 40 page document) > > with, say @name1 through @name12, it can get a bit confusing. I put > > all the replacement data in a separate lyx file and go back and forth > > to that file until I have made all replacements. > > > > > > > > I use article class. > > > > > > > > Is there perhaps a better layout or class or perhaps something else > > lyx that I should be using? > > The easiest way to do this would be to use some LaTeX in your LyX > document. Where you now have "@name1" put, say: > \nameone > in ERT. Now in the preamble, say, put: > \def\nameone{Judy Jones} > This is a LaTeX variable, or "macro". > > You could also do something like: > \def\nameonef{Judy} > \def\nameonel{Jones} > \def\nameone{\nameonef \nameonel} > and now you have access to first, last, and full names. > > You can also put all of that in some separate LyX file, if you like, but > as ERT, and include it at the beginning of the file. > > Caveats: > > LaTeX does not allow numbers in variable names, only letters (well, > close enough). Hence "one". > > You'll have to be careful to avoid naming conflicts with what LaTeX > already predefines. One way to do this is to use names like, e.g., > \MERGEnameone. > > You may run into problems with spaces after such macros. This is because > LaTeX sees the space after the macro as just separating it from what > follows, not as an actual space. You can handle this in a couple ways. > First, in the LyX file, you can do: > \nameone{} > in ERT. Now the braces terminate the macro, and LaTeX will treat a > following space as an actual space. The other option is to use the > xspace package. So the macro gets defined as: > \def\nameone{Judy Jones\xspace} > and you put > \usepackage{xspace} > into the preamble. The \xspace macro adds a space, but only if what > follows isn't punctuation, etc. It isn't perfect, but it usually works. > > This is a very simple approach. Try searching "latex mail merge" for > more sophisticated ones. > > Richard