mailmerge: repeat amount of text merging fields

Similar documents
The isodateo package

The nbaseprt package

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

The alphalph package

Three Ways to Use CSS:

The hypbmsec package

The EverySel package

The dashrule package

Discrete Structures Lecture 14

Documented Code for datatool v2.29

CREATING A WEBSITE USING CSS. Mrs. Procopio CTEC6 MYP1

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal

Setup Contacts Add Compose Letter Compose Letter

probsoln v3.0: creating problem sheets optionally with solutions

{cprotect.sty} \verbatim in \macro arguments

Documented Code for datatool v2.23

Object oriented programming C++

SFU CMPT Topic: Control Statements

Arrays. Theoretical Part. Contents. Keywords. Programming with Java module 3

Syntax errors are produced when verifying an EasyLanguage statement that is not

<body bgcolor=" " fgcolor=" " link=" " vlink=" " alink=" "> These body attributes have now been deprecated, and should not be used in XHTML.

parrun User Guide Massimiliano Dominici 2004/02/06

Review Question 1. Which tag is used to create a link to another page? 1. <p> 2. <li> 3. <a> 4. <em>

The multicap L A TEX2ε package

COP 2000 Note Framework Chapter 5 - Repetition Page 1

The stdclsdv package

L A TEX: Online module 2

Problem Solving With Loops

Appendix D CSS Properties and Values

Quality Assurance & Accessibility

Compiler principles, PS1

Appendix B: Test Scripting Language 1

recall: a Web page is a text document that contains additional formatting information in the HyperText Markup Language (HTML)

The Arraysort Package

Web Publishing Basics I

The optparams package

Information technology Document description and processing languages Office Open XML File Formats Part 3: Markup Compatibility and Extensibility

The svn-prov package

Table of Contents. Appendix C: Index. Part A. Technical Settings. General. Main Text. Equation. Figure. Table. Part B. Content Settings.

$%&#!#$!!!#'((#!)*+"!!,!#*+- ) %() (. %( ) //. 0 1 ) (2.

Directions for posting on the UC Weed Science blog

Documentation of the UJAC print module's XML tag set.

Version List of tables Tbl. 5.1 Additional fonts... 5 Tbl Types of index entries... 10

CSC 121 Computers and Scientific Thinking

The count1to package

Logging Mechanism. Cisco Logging Mechanism

Python - Variable Types. John R. Woodward

Reading 2.2 Cascading Style Sheets

v2.1, dated 2014/03/04.

252 TUGboat, Volume 39 (2018), No. 3

Introduction to Multimedia. MMP100 Spring 2016 thiserichagan.com/mmp100

Microsoft Excel 2007 Level 1

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5-1

Wanted! Introduction. Step 1: Styling your poster. Activity Checklist. In this project, you ll learn how to make your own poster.

Perl Regular Expressions. Perl Patterns. Character Class Shortcuts. Examples of Perl Patterns

Termcal.sty printing a class calendar

A Balanced Introduction to Computer Science, 3/E

The ifplatform package

pgfopts LaTeX package options with pgfkeys

This is a paragraph. It's quite short.

Arrays Structured data Arrays What is an array?

COMPUTER APPLICATIONS IN BUSINESS FYBMS SEM II

The EverySel package

CSE au Final Exam Sample Solution

C Programming Language. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

Autonumbering in FrameMaker. Presented by:

Introduction. C provides two styles of flow control:

L L G E N. Generator of syntax analyzier (parser)

Information technology Document description and processing languages Office Open XML File Formats Part 2: Open Packaging Conventions

Lesson 5: Introduction to Content Matchers

DINO. Language Reference Manual. Author: Manu Jain

CSS Selectors. element selectors. .class selectors. #id selectors

Documented Source Code for flowfram.sty v1.17

The mathstyle package

Lesson B Objectives IF/THEN. Chapter 4B: More Advanced PL/SQL Programming

Unit 3 Fill Series, Functions, Sorting

Unit 3 Functions Review, Fill Series, Sorting, Merge & Center

HCA Tech Note 103. Expressions. Example: Conversion

From The Edge: Using the Rich Text Control for Mail Merge

All copyrights reserved - KV NAD, Aluva. Dinesh Kumar Ram PGT(CS) KV NAD Aluva

Personal Computing EN1301 Word Processing Applications (12 hrs.) Part All rights reserved by UCSC

DAY 4. Coding External Style Sheets

The ExSol package. your original text that only contains the exercises, and

CdmCL Language - Syntax

INFORMATICA GENERALE 2014/2015 LINGUAGGI DI MARKUP CSS

Jonathan Zachhuber Michael Fü erer Version v., / /


MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

mnotes annotate documents with margin comments

SRJC DRUPAL SITES Siteimprove Reports & Administration

Outbreak Maps: Visual Discovery in Your Data. Jeff Phillips, Data Visualization R&D

8. Control statements

Documented Code For glossaries v3.02

from The Elements of Typographic Style by Robert Bringhurst, page 171

Mobile App:IT. Methods & Classes

Chapter 2: Functions and Control Structures

Longware, Inc INTERNAL STYLE GUIDE

JavaScript Functions, Objects and Array

The newunicodechar package

Preparing FP7 Proposals in L A TEX with eurpoposal.cls

Transcription:

mailmerge: repeat amount of text merging fields Miguel Vinícius Santini Frasson 2009 09 23 version 1.0 Contents 1 Introduction 1 2 Usage 1 3 Example 2 4 Idea of implementation 3 5 Code 4 5.1 (Re)initialization............................ 4 5.2 Saving the repetition in a command................. 4 5.3 Restoring data from aux file...................... 4 5.4 Saving field names........................... 5 5.5 Repeating within an entry....................... 5 1 Introduction The package mailmerge provides an interface to mail merge or other such documents, where a body (or amount of text) is to be repeated, with some tags replaced by respective values in each repetition. 2 Usage In short, one needs to: 1. declare field names, 2. define the repetition and 3. provide entries, each one being a set of values for the fields. It is important to define the repetition with \mailrepeat before provide any entry. We present the usage in more detail now. 1

\mailfields \mailrepeat \field \numberoffields \numberofentries \entrynumber \mailentry 1. Declare the names of the fields, with the command \mailfields{name1,name2,...} The order declared here is the order in which the values must be provided in the parameter of \mailentry (see below.) 2. The block of text to be repeated is given as the parameter of macro \mailrepeat as in \mailrepeat{... text to be repeated...} Inside the text to be repeated, which can be several paragraphs long, each instance of \field{name } is replaced by the respective value, this for each entry. The command \numberoffields is replaced by the number of fields and \numberofentries is replaced by the number of entries, but it is necessary two runs to update the value. The command \entrynumber is replaced by the current entry number. This can be used, for example, in determining if current entry has an odd or even number. For conditional text, depending on field value, one can compare value s contents, for example, with the \ifthenelse command provided by the ifthen package. 3. For each entry, provide a command \mailentry{value1,value2,...} where value1 is the value of field named name1, value2 is the value of field named name2, and so on. The values can be several paragraphs long. If the value has a comma with it, better enclose the value between curly brackets, like in \mailfields{name,friends,drives} \mailentry{john,{bart,robert},yes} \mailentry{michael,{jean,phillip,maria},no} \mailnewdata 4. In case of intention of use of several databases in the same file, use the command \mailnewdata, which resets entries. New uses of \mailfields overhide previous field names. 3 Example \usepackage{ifthen,mailmerge} % \ifequal{a}{b}{what if A=B}{what if A<>B} \newcommand{\ifequal}[2]{\ifthenelse{\equal{#1}{#2}}} \mailfields{name,friends,drives} \mailrepeat{\section*{\field{name} s profile} 2

\field{name} has \ifequal{\field{friends}}{} {no friends} {\field{friends} as friends}. \ifequal{\field{drives}}{yes}{drives.}{doesn t drive.} (entry \entrynumber\ of \numberofentries) % \newpage optional } \mailentry{john,{bart and Robert},yes} \mailentry{sara,{jean, Phillip and Maria},no} \mailentry{edward,,yes} what produces the following output: John s profile John has Bart and Robert as friends. Drives. (entry 1 of 3) Sara s profile Sara has Jean, Phillip and Maria as friends. Doesn t drive. (entry 2 of 3) Edward s profile Edward has no friends. Drives. (entry 3 of 3) 4 Idea of implementation Each new data initialization (call od \mailnewdata) defines a tag command with values a, aa, aaa, and so on, saved in command \MAILMcurrtag. A \mailfields saves field names to commands \MAILMfieldI, \MAILMfieldII, \MAILMfieldIII, etc (ending with upcase roman numbers), and at the end, saves in the.aux file the number of fields in a command determined by the data tag. The \mailrepeat command just saves its parameter to a command. 3

Each \field{name } is expanded to a command \MAILMthefieldname. \numberoffields expands to a command whose name is composed by MAILMnumberfields plus tag. The same for \numberofentries. Each \mailentry defines the comands \MAILMthefieldnameN to expand to valuen, using \MAILMfieldN-in-roman to compose the name of the command and expand an entry of the repetition command. Now, when the \field, \numberoffields and \numberofentries are expanded, they have ppropriated values. 5 Code Identidication of the package and use of the package ifthen. 1 \NeedsTeXFormat{LaTeX2e} 2 \ProvidesPackage{mailmerge}[2009/09/23 v1.0 repeat amount of text merging fields] 3 \RequirePackage{ifthen} 5.1 (Re)initialization Reset counters and update tag command \MAILMcurrtag. Inicialize once. 4 \def\mailmcurrtag{} 5 \newtoks\mailmtok 6 \newcounter{mailmcount}% aux counter 7 \newcounter{mailmentry}% 8 \newcommand{\mailnewdata}{% 9 \setcounter{mailmentry}{0}% 10 \xdef\mailmcurrtag{a\mailmcurrtag}} 11 \mailnewdata 5.2 Saving the repetition in a command \mailrepeat \MAILMsetnumfields \MAILMsetnumentries \numberoffields \numberofentries 12 \newcommand{\mailrepeat}[1]{\gdef\mailmrepetition{#1}} 5.3 Restoring data from aux file Commands that extract info from aux file (saved by \mailfields and \mailentry) and commands that use this information when repeting. 13 \newcommand{\mailmsetnumfields}[2] 14 {\expandafter\xdef\csname MAILMnumberoffields#1\endcsname{#2}} 15 \newcommand{\mailmsetnumentries}[2] 16 {\expandafter\xdef\csname MAILMnumberofentries#1\endcsname{#2}} 17 \newcommand{\numberoffields} 18 {\csname MAILMnumberoffields\MAILMcurrtag\endcsname} 19 \newcommand{\numberofentries} 20 {\csname MAILMnumberofentries\MAILMcurrtag\endcsname} 4

\field \mailentry 5.4 Saving field names 21 \newcommand{\mailfields}[1]{% 22 \setcounter{mailmcount}{0}% Initiate a loop, where for each entry, the command \MAILMaux is set to entry name. 23 \@for\mailmaux:=#1\do{% The next line is to extract white space after comma. 24 \edef\mailmaux{\expandafter\@firstofone\mailmaux\@empty}% Define command \MAILMfieldRoman-number. 25 \stepcounter{mailmcount}% 26 \expandafter\edef\csname MAILMfield\Roman{MAILMcount}\endcsname 27 {\MAILMaux}% 28 \edef\numberoffields{\arabic{mailmcount}}% 29 }% Write to aux \MAILMsetnumfields{tag}{num} 30 \immediate\write\@mainaux{\string\mailmsetnumfields 31 {\MAILMcurrtag}{\theMAILMcount}}% 32 } 5.5 Repeating within an entry Defining \field, that expands to \MAILMthefieldname. 33 \newcommand{\field}[1]{\csname MAILMthefield#1\endcsname} Each entry increments counter (reset in initialization), saves entry number to aux, saves each value to the command expanded by \field and expand the repetition, stored in \MAILMrepetition. The implementation is similar to \mailfields. 34 \newcommand{\mailentry}[1]{% 35 \stepcounter{mailmentry}% 36 \edef\entrynumber{\themailmentry}% 37 \immediate\write\@mainaux{\string\mailmsetnumentries 38 {\MAILMcurrtag}{\theMAILMentry}}% 39 \setcounter{mailmcount}{0}% 40 \@for\mailmentryfield:=#1\do{% 41 \MAILMtok=\expandafter{\MAILMentryfield}% 42 \stepcounter{mailmcount}% 43 \expandafter\long\expandafter\edef 44 \csname MAILMthefield% 45 \csname MAILMfield\Roman{MAILMcount}\endcsname 46 \endcsname {\the\mailmtok}% 47 }% 48 \MAILMrepetition 49 } 5

Index Numbers written in italic refer to the page where the corresponding entry is described; numbers underlined refer to the code line of the definition; numbers in roman refer to the code lines where the entry is used. E \entrynumber....... 2 F \field.......... 2, 5 M \mailentry...... 2, 5 \mailfields........ 2 \MAILMsetnumentries. 4 \MAILMsetnumfields.. 4 \mailnewdata....... 2 \mailrepeat...... 2, 4 N \numberofentries. 2, 4 \numberoffields.. 2, 4 6