Home

datatool: Databases and data manipulation

image

Contents

1. 95 A pie chart using segment colours and outline 97 Anannotated ple Cat cuis orbe E ES 98 54 oq D ee 103 A EE e eg eh en Roe E peo gea 104 A scatter plot multiple datasets 106 A scatter plot witha legend coo e lt 106 A scatter plot using the end plot hook to annotate the plot 108 Adding toa pl t stream icono dee o x RA 112 Time to growth data plotting from the same database using diferent keys echte rero Con e AE EE i a 114 A basic bar CHAR o ioo o ee m o o x 118 A bar chart labelled 4 2 284 585 ee 9 REFUS 122 Profits for 2000 2003 a horizontal bar chart 124 Student marks a multi bar chart 126 Student marks annotating a bar chart 128 vii List of Tables NI M 5 3 5 4 5 5 5 6 5 7 5 8 2 9 5 10 5 11 S12 5 13 5 14 5 15 5 16 aly 5 18 5 19 5 20 bul 522 5 23 5 24 5 25 Special character mappings used by DTLloadrawdb Time to Growth Data 2 084 99 32 2422 20 2 404 Balance Sheet Jos s nenn ROE SE we a ee oR ae Student scores displaying a database in a table Student scores labelling rows eso e RR e Top student scores filtering rows using NDTLisgt Student scores B filtering rows using BTLisopenbetween o o tooo First Three ROWS es crad Bis nn xe a A stripy table illustrating the use of DTLifoddrow Two database rows per tabular row illustrating the
2. 140 DTLbibfieldexists 134 DTLendpt dorada 119 DTLbibfieldiseq 134 DTLenvforeach environment DTLbibfieldisge P35 2 ck dee eee A DR heeds S 49 49 DTLbibfieldisgt 135 DTLenvforeach environment DTLbibfieldisle te METTI PP 49 49 DTLbibfieldislt 135 DTLeverybarhook 119 DTLbibliography 134 dtlexpandnewvalue 37 DTLbibliographystyle 138 NdElforcoLu mi sox ersa sewwi 80 DTLbibrow counter 144 dtlforcolumnindex 80 DTLbibrow counter 136 DTLforeach 48 50 53 60 66 delbreak Mala alle 51 69 72 82 86 95 96 99 112 116 DTLeite i 9n a ees 145 DTLforeach 48 NDTLoleatdb se REF ke 79 WNDTLforeachblb ssi 143 NDILCIXD xaecueeewedenm ey READER 31 DTLforeachbib 143 DTLcolumncount 36 dtlforeachkey 79 dtlcolumnindex 81 DTLforeachkeyinrow 51 DTLcomputebounds 72 DTLformatabbrvforenames 139 DTLcomputewidestbibentry 144 DTLformatauthor 138 DTLconverttodecimal 22 68 112 DTLformatbibentry 144 Ndtlcurrencyalign 45 DTLformateditor 138 dtlcurrencyformat 46 DTLformatforenames 139 DTLcurrencytype 9 NDTLformat r ven 139 DTLcurrentindex 50 155 DTLformatlegend 111 dtlcurrentrow 83 DTLformatsurname 139 dtldbname sn 64 DTLformatvon
3. 139 DTLdecimaltocurrency 23 68 DTLgabs 26 DTLdecimaltolocale 22 68 DILgadd 24 69 dtldefaultkey 99 NpTLgaddall sie ge RR 24 DTLdeletedb 79 NDTLhgOlip gt si 31 dtldisplayafterhead 46 NDILGQIY e au za 26 DTLdisplaydb 42 DTLgetcolumnindex 80 dtldisplayendtab 46 DTLgetdatatype 79 DTLdisplayinnerlabel 93 dtlgetentryfromcurrentrow DTLdisplaylongdb 4d 0 ee ee eee 85 DTLdisplaylowerbarlabel 120 DTLgetkeydata 81 DTLdisplaylowermultibarlabel DTLgetkeyforcolumn 80 BEE 120 DTLgetlocation 81 DTLdisplayouterlabel 93 Ndblgetrow 2 422288 bene sets 83 dtldisplaystartrow 47 MXDILgetvalue 81 dtldisplaystarttab 46 DTLgetvalueforkey 81 DTLdisplayupperbarlabel 121 NDTLgmax 28 DTLdisplayuppermultibarlabel DTLgmaxall 28 u a EE ETE EE 121 DTLgmeanall sees 29 163 P D BO GO AO E ME AO RN sO A EO EO EP IR RO EO NE E OP RES ES BO Om ARE MP ANO P A GEE GO EO AE EE RY A NO MO P DTLgmin 2492232 be ee eee SE A DTLgminall 28 DICMU 42g 82a re 23 DTLgn q we RR 26 X D Ehgftou nd oed re 30 DTLgsdforall SU X DILOSATE 49 99 ERA ZEN DTEgSEUb asus 25 N DTLSELUNG esas ass 30 DTLgvarianceforall ZU
4. 45 This indicates how to format a column header where the header is given by header This defaults to null hfil textb header hfil null dtlstringformat dtlstringformat text This specifies how to format each entry in the columns that contain strings This defaults to just displaying text dtlintformat dtlintformat text This specifies how to format each entry in the columns that contain only integers This defaults to just displaying text dtlrealformat dtlrealformat text This specifies how to format each entry in the columns that contain only real numbers or a mixture of real numbers and integers This defaults to just displaying text dtlcurrencyformat dt lcurrencyformat text defaults to just displaying text dtldisplaystarttab dtldisplaystarttab This is a hook to add something at the beginning of the tabular environment This defaults to nothing dtldisplayendtab dtldisplayendtab This is a hook to add something at the end of the tabular environment This defaults to nothing dtldisplayafterhead dtldisplayafterhead o This is a hook to add something after the header row before the first row of data This defaults to nothing dtldisplaystartrow dtldisplaystartrow This is a hook to add something at the start of each row but not including the header row or the first row of data This defaults to nothing If you want to use the bookta
5. true part false part If string1 is alphabetically less than string2 then do true part otherwise do false part The starred version ignores the case the unstarred version is case sensitive For example DTLifstringlt aardvark zebra less not less produces less Note that both string1 and string2 are considered to be strings so for example DTLifstringlt 2 10 less not less produces not less since the string 2 comes after the string 10 when arranged alphabetically The case sensitive unstarred version considers uppercase characters to be less than lowercase characters so DTLifstringlt B a less not less produces less whereas DTLifstringlt B a less not less 10 produces not less DTLiflt DTLiflt argl arg2 true part false part ADTLifltx DTLifltx argl arg2 true part false part If arg1 and arg2 are both numerical then this is equivalent to DTLifnum1t otherwise it is equivalent to DTLstringlt when using NDTLiflt or DTLstringlt when using ADTLif1t DTLifnumgt DTLifnumgt numl num2 true part false part If num1 is greater than num2 then do true part otherwise do false part Note that both num1 and num2 must be numerical either integers real numbers or currency DTLifstringgt DTLifstringgt string string2 true part false part DTLifstri
6. DTLpiepercent This command is set to the percentage value of DTLpievariable The percentage value is rounded to n digits where n is the value of the DTLpieroundvar BIEX counter DTLpieroundvar Example 21 Changing the Inner and Outer Labels This example uses the database defined in example 19 The inner label is now set to the percentage value rather than the actual value and the outer label is set to the name with the actual value in parentheses begin figure htbp centering DTLpiechart variable quantity innerlabel DTLpiepercent outerlabel name DTLpievariable fruit name Name quantity Quantity caption A pie chart changing the labels end figure This produces Figure 6 7 6 2 Pie Chart Label Formatting DTLdisplayinnerlabel DTLdisplayinnerlabel text This governs how the inner label is formatted where text is the text of the inner label The default is to just do text DTLdisplayouterlabel Pears 25 Apples 30 Lemons Limes 40 5 Cherries 20 Peaches 34 5 Figure 6 7 A pie chart changing the labels DTLdisplayouterlabel text This governs how the outer label is formatted where text is the text of the outer label The default is to just do text Example 22 Changing the Inner and Outer Label Format This example extends example 21 The inner and outer labels are now both typeset in a sans serif font be
7. caption Time to end figure growth data This produces Figure 7 7 Notes e I redefined DTLplotatbegintikz in order to add the new plot to the legend since DTLplotatendtikz is used after the legend 113 is plotted The x and y unit vectors are set before DTLplotatbegintikz so I don t need to worry about the co ordinates I set the counter DTLplotroundXvar to zero otherwise the x axis would have looked too cluttered Ihave used DTLminforkeys and DTLmaxforkeys to determine the bounds since DTLplot won t take the data for Experiment 1 into account when computing the bounds 4 90 r x 441 x Experiment 1 o Experiment 2 3 92 3 43 o Log Count 2 94 245 1 96 1 47 0 08 j 0 6 12 18 24 30 36 42 48 54 60 0 49 Time Figure 7 7 Time to growth data 114 DTLbarchart DTLmultibarchart 8 Bar Charts databar package The databar package provides commands for creating bar charts It is not loaded by the datatool package so if you want to use it you will need to load it explicitly using usepackage databar You must also have the pgf package installed Bar charts can either be vertical or horizontal the default is vertical In this section the x axis refers to the horizontal axis when plotting a vertical bar chart and to the vertical axis when plotting a horizontal bar chart The x axis units are in increments of one bar The y axis refers to the v
8. Lforeach fruit name Name DTLiffirstrow TLdocurrentpiesegmentcolor rule 1l0pt 10pt name end tabular caption A pie chart using segment colours and outline end figure ZA A AO RX XA AX ZA ZA ZH This produces Figure 6 9 The format of the outer label has been changed to use Short stack to prevent the outer labels from taking up so much horizontal space The outerlabel setting has also been modified to use V after the name to move the percentage value onto the next row 96 Lemons Limes 40 5 Pears 25 Apples 30 Cherries 20 Apples Pears Lemons Limes Peaches Cherries Figure 6 9 A pie chart using segment colours and outline 6 4 Adding Extra Commands Before and After the Pie Chart The pie charts created using DTLpiechart are placed inside a tikzpicture environment defined by the tikz package DTLpieatbegintikz DTLpieatbegintikz The macro DTLpieatbegintikz is called at the start of the tikzpicture environment allowing you to change the tikzpicture settings By default DTLpieatbegintikz does nothing but you can redefine it to say scale the pie chart but be careful not to distort the chart DTLpieatendtikz The macro DTLpieatendtikz is called at the end of the tikzpicture environment allowing you add additional graphics to the pie chart This DTLpieatendtikz does nothing by default Example 24 Adding Information to the
9. NDTLloaddb growth growth csv However I d like to plot both results on the same graph Since they are contained in the same database I can t use the method I used in example 26 Instead I can use a combination of NDTLplot and DTLplotstream begin figure tbhp centering o computer bounds DTLminforkeys growth Time minX DTLminforkeys growth Experiment 1 Experiment 2 minY DTLmaxforkeys growth Time maxX DTLmaxforkeys growth Experiment 1 Experiment 2 maxY 9 o o set plot mark round x tick 1 setcounter DTLpl abels otroundXvar 0 redefine DTLplotatbegintikz to plot the data for Experiment 1 renewcommands D1 Lplotatbegintikz pgfplothandlermark color green pgfuseplotmark x add data from start plot stream pgfplotstreamstart Experiment 1 to plot stream DTLplotstream growth Time Experiment 1 end plot stream pgfplotstreamend stroke path pgfusepath stroke o add information to legend no line is require so use relax DTLaddtoplotlegend color green pgfuseplotmark x relax Experiment 1 now plot the data for Experiment 2 DTLplot growth x Time y Experiment 2 legend width 3in height 3in bounds minX minY maxX maxY xlabel Time ylabel Log Count legendlabels Experiment 2
10. produces not an integer The number group character may be changed For example DTLsetnumberchars DTLifint 2 536 integer not an integer this now produces not an integer since 2 536 is now a real number Note that nothing else can be appended or prepended to the number For example DTLsetnumberchars DTLifint 2 536m integer not an integer produces not an integer DTLifreal text true part false part If text is a real number then do true part otherwise do false part For example DTLifreal 1000 0 real not real produces real Note that an integer is not considered a real number DTLifreal 1 000 real not real DTLifcurrency produces not real Whereas DTLifreal 1 000 0 real not real produces real However DTLsetnumberchars DTLifreal 1 000 real not real produces real since the comma is now the decimal character Currency is not considered to be real DTLsetnumberchars DTLifreal 1 00 real not real produces not real DTLifcurrency text true part false part If text is currency then do true part otherwise do false part For example DTLifcurrency 5 99 currency not currency produces currency Similarly DTLifcurrency pounds5 99 currency not currency produces currency Note however that DTLifcurrency US 5 99 currency not currency produces not curre
11. secure 84 DTLandlast isa ees 140 DTLandnotlast 140 dtlappendentrytocurrentrow Se EE Wr 85 DTLappendtorow 66 DITASSTON dear nee ee ees 82 DTLbaratbegintikz 119 DTLbaratendtikz 119 bDThbarchaft sse ces 115 DTLbarchart options O au dens er EC 116 barlabel 116 length i Ee 116 MAX deta cese me e Re 116 124 maxdepth 116 124 upperbarlabel 116 variable 116 verticalbars 117 120 Ylabel ass see 112 yli6gap em ER ERES 117 yticlabelS 117 yticpointS 117 DTLbarchartlength 117 DTLbarchartwidth 124 127 DTLbardisplayYticklabel 120 DTLbargroupwidth 127 DTLbarlabeloffset 118 DIEDALMAX diners ee ias 124 DTLbaroutlinecolor 119 DTLbaroutlinewidth 119 TLbarroundvar counter 118 DTLhbarwidth 4 94 118 DTLbarXlabelalign 120 DTLbarYticklabelalign 120 dtlbeforecols 0m 45 dtlbeforerow 84 DILdiV oso 6 44 9 9 eee ne 26 dtlbetweencols 45 DTLdobarcolor 119 DTLbetweeninitials 34 DTLdocurrentpiesegmentcolor DTLBIBdbname TES sa i Kote a lal eu s 95 ADTLDIDELELO ann aaa 143 DTLdopiesegmentcolor 95 DTLbibfieldcontains 134 DTLendbibitem
12. key This removes the entry for key from the current row DTLremovecurrentrow DTLremovecurrentrow This removes the current row from the database 3Only the unstarred version of DTLforeach the starred version is read only 66 Example 13 Editing Database Rows In this example I have a CSV file called marks csv that contains student marks for three assignments Surname FirstName StudentNo Assignment 1 Assignment 2 Assignment 3 Smith Jr John 102689 68 57 72 Brown Jane 102647 75 84 80 Brown Andy 103569 42 52 54 Adams Z oe 105987 52 48 57 Brady Roger 106872 58 60 62 Verdon Clare 104356 45 50 48 First load this into a database called marks DTLloaddb marks marks csv Suppose now I want to compute the average mark for each student and append this to the database I can do this as follows DTLforeach marks assignI Assignment 1 assignII Assignment 2 assignIII Assignment 3 DTLmeanforall theMean assignI assignII assignIII DTLappendtorow Average theMean For each row in the marks database I now have an extra key called Average that contains the average mark over all three assignments for a given student I can now put this data into a table begin table htbp caption Student marks centering begin tabular llcccc bfseries Surname amp bfseries First Name amp bfseries Assign 1 amp bfseries Assign
13. assignI assignII assignIII barlabel firstname surname marks surname Surname firstname FirstName assignI Assignment 1 assignII Assignment 2 assignIII Assignment 3 caption Student marks end figure This produces Figure 8 4 Notes 1 I used variables assignI assignII assignIII to set the variable to use for each bar within a group This means that there will be three bars in each group 2 Ihave set the bar width to 10pt otherwise the chart will be too wide 3 I used uppermultibarlabels assignI assignII assignIIIl to set the upper labels for each bar within a group This will print the assignment mark above the relevant bar 4 Iused barlabel firstname surname to place the student s name below the group corresponding to that student Recall that example 13 computed the average score over for each student and saved it with the key Average This information can be added to the bar chart It might also be useful to compute the average over all students and add this information to the chart This is done as follows begin figure htbp centering compute the overall mean DTLmeanforkeys marks Average overallmean round it to 2 decimal places DTLround overallmean overallmean 2 draw a grey dotted line indicating the overall mean covering the entire width of the bar chart renewcommands DTLbaratendtikz draw lightgray loosely dotted 0
14. average sets average to the mean of all the scores in the database called scores DTLmeanforcolumn DTLmeanforcolumn db key cmd This is a faster version of DTLmeanforkeys that only computes the mean for a single column specified by key for a single database specified by db and doesn t provide any filtering The result is stored in cmd which must be a control sequence DTLvarianceforkeys DTLvarianceforkeys condition assign list db list y key list cmd This command computes the variance of all the entries over all the databases listed in db list for all keys in key list where the condition 70 given by condition is true The second optional argument assign list is the same as the assignment list used by DTLforeach so that you can use the information in condition The result is stored in cmd which must be a control sequence DTLvarianceforcolumn DTLsdforkeys DTLsdforcolumn DTLminforkeys DTLvarianceforcolumn db key cmd This is a faster version of DTLvarianceforkeys that only computes the variance for a single column specified by key for a single database specified by db and doesn t provide any filtering The result is stored in cmd which must be a control sequence DTLsdforkeys condition assign list db list t key list cmd This command computes the standard deviation of all the e
15. begin tabular llc bfseries First Name amp bfseries Surname amp bfseries Score DTLforeachs scores firstname FirstName surname Surname score Score DTLifoddrow rowcolor blue rowcolor green 55 9 5 firstname amp surname amp score end tabular end table This produces Table 5 9 Table 5 9 A stripy table First Name Surname Score Example 8 Two Database Rows per Tabular Row In order to save space you may want two database rows per tabular row when displaying a database in a tabular environment This can be accomplished using DTLifoddrow For example begin table htbp caption Two database rows per tabular row centering begin tabular llcllc bfseries First Name amp bfseries Surname amp bfseries Score amp bfseries First Name amp bfseries Surname amp bfseries Score DTLforeachx scores firstname FirstName surname Surname score Score DTLifoddrow amp firstname amp surname amp score end tabular end table produces Table 5 10 To order column wise instead of row wise see example 18 56 Table 5 10 Two database rows per tabular row First Name Surname Score First Name Surname Score John Smith Jr 68 Jane Brown 75 Andy Brown 42 Zoe Adams 52 Roger Brady 58 Clare Verdon 45 Example 9 Iterating Through Keys in a Row Suppose you have lots of columns in you
16. caption A line plot end figure This produces Figure 7 2 103 60 90 59 35 57 80 56 25 54 70 53 15 51 60 50 05 48 50 7 46 95 45 40 154 155 1 56 1 56 1 57 158 1 59 1 60 1 60 1 61 1 62 Figure 7 2 A line plot 104 Example 26 Plotting Multiple Data Sets In this example I shall use the database called groupa defined in example 25 and another database called groupb which is loaded from the file groupb csv which contains the following Height Weight 1 54 48 4 1 54 42 0 1 55 64 1 56 58 1 56 49 1 57 40 1 58 51 1 985 034 1 59 74 1 59 59 3 First load this into a database called groupb VO k D wo MN CH DTLloaddb groupb groupb csv I can now plot both groups in the same graph but I want a smaller graph than Figure 7 1 and Figure 7 2 so I am going to set the plot width and height to 3in begin figure htbp centering DTLplot groupa groupb x Height y Weight width 3in height 3in caption A scatter plot end figure This produces Figure 7 3 Now let s add a legend using the legend setting with the legend labels Group Aand Group B and set the x tick intervals using xticpoints setting Iam also going to set the x axis label to Height m and the y axis label to Weight kg and place a box around the plot begin figure htbp centering DTLplot groupa groupb x Height y Weight widt
17. false paty If num1 is equal to num2 then do true part otherwise to false part where num1 and num2 are plain numbers using a full stop as the decimal point and no number group separator For currency or locale dependent numbers use ADTLi fnumeg XDTLifnumeg DTLifnumeq numl num2 true part false part If num1 is equal to num2 then do true part otherwise do false part Note that both num1 and num2 must be numerical either integers real numbers or currency The currency symbol is ignored when determining equality For example DTLifnumeg pounds10 50 10 5 true false produces true since they are considered to be numerically equivalent Likewise DTLifnumeg pounds10 50 10 50 true false produces true DTLifstringeg DTLifstringeq DTLifeq DTLifeq DTLifstringed string1 string2 true part false part DTLifstringeqs string1 string2 true part false part If string1 and string2 are the same then do true part otherwise do false part The starred version ignores the case the unstarred version is case sensitive Both string1 and string2 are considered to be strings so for example DTLifstringeq 10 50 10 5 true false produces false Note that DTLifstringeq Text text true false produces false whereas DTLifstringeq Text text true false produces true however it sh
18. index csv iterate through index database DTLforeach index theFile File theTemp Temperature theNaCl NaCl thepH pH load results file into database of the same name DTLloaddb theFile theFile Create a table begin table htbp caption Temperature theTemp NaCl theNaCl pH thepH label tab theFile centering begin tabular rl bfseries Time amp bfseries Log Count DTLforeach theFile theTime Time theLogCount Log Count theTime amp theLogCount end tabular end table This creates Table 5 14 to Table 5 16 Note that each table is given a label that is based on the database name to ensure that it is unique Table 5 14 Temperature 25 NaCl 4 7 pH 0 5 Time Log Count 0 3 75 23 3 9 45 4 0 Table 5 15 Temperature 25 NaCl 4 8 pH 1 5 Time Log Count 0 3 6 60 3 8 120 4 0 Table 5 16 Temperature 30 NaCl 5 12 pH 4 5 Time Log Count 0 3 73 23 3 67 60 4 9 61 Example 11 Dynamically Allocating Field Name This example was suggested by Bill Hobbs Suppose you have a directory containing members of multiple clubs The CSV file say clubs csv may look something like First Name Surname Rockin Single John Smith Jr member Jane Brown friend Andy Brown friend member ZN oe Adams member member Roger Brady friend friend Clare Verdon member Blank entries indicate that the person is no
19. num min and max are all in standard fixed point notation i e no number group separator no currency symbols and a full stop as a decimal point en DTLifFPopenbetween num min max true part false part If min num max then do true part otherwise do false part where num min and max are all in standard fixed point notation i e no number group separator no currency symbols and a full stop as a decimal point e DTLifAllUpperCase string true part false part Tests if string is all upper case For example DTLifAllUpperCase WORD all upper not all upper produces all upper whereas DTLifAllUpperCase Word all upper not all upper produces not all upper Note also that DTLifAllUpperCase MakeUppercase word all upper not all upper 14 also produces all upper MakeText Uppercase defined in David Carlisle s textcase package and uppercase are also detected otherwise if a command is encountered the case of the command is considered For example DTLifAllUpperCase MAN OE UVRE all upper not all upper produces all upper DTLifAllLowerCase DTLifSubString DTLifAllLowerCase string true part false part Tests if string is all lower case For example DTLifAllLowerCase word all lower not all lower produces all lower whereas DTLifAllLowerCase Word all lower not all lower produce
20. to the negative of num DLTneg sets cmd locally while DTLgneg sets cmd globally Example DTLneg result pounds2 50 result produces 2 50 DTLsqrt cmd num y NDTLgsqrt cmd num This sets cmd to the sqrt root of num DLTsqrt sets cmd locally while DTLgsqrt sets cmd globally Example DTLsqrt result 2 result produces 1 414213562373095042 DTLmin cmd y num1 num2 DTLgmin cmd num1 y num2 This sets the control sequence cmd to the minimum of num1 and num2 DLTmin sets cmd locally while DTLgmin sets cmd globally For example DTLmin result 256 32 result produces 32 Again num1 and num2 may be currency For example DTLmin result 256 pounds32 result produces 32 whereas DTLmin result pounds256 32 result produces 32 As mentioned above datatool doesn t know about exchange rates so be careful about mixing currencies For example DTLmin result pounds5 6 result produces 5 which may not necessarily be true DTLminall DTLminal1 cmd number list DTLgminall DTLgminal1 cmd number list This sets the control sequence cmd to the minimum of all the numbers in number list DLTminall sets cmd locally while DTLgminall sets cmd globally Example DTLminall theMin 25 1 45 2 35 6 theMin produces 25 1 Note that if any of the numbers in number li
21. widest DTLforeachbibentry equal DBIBentrytype article mybib bibitem J theDTLbibrow DBIBcitekey DTLformatbibentry end thebibliography Nrenewcommand refname Conference Papers DTLcomputewidestbibentry equal DBIBentrytype inproceedings mybib C theDTLbibrow widest begin thebibliography widest DTLforeachbibentry equal DBIBentrytype inproceedings mybib bibitem C theDTLbibrow DBIBcitekey DTLformatbibentry end thebibliography end document 9 6 Multiple Bibliographies It is possible to have more than one bibliography in a document but it then becomes necessary to have a separate auxiliary file for each bibliography and each auxiliary file must then be passed to BIBTEX In order to do this you need to use DTLmult ibibs name list where name list is a comma separated list of names name For each name this command creates an auxiliary file called name aux note that this command may only be used in the preamble When you want to cite an entry for a given bibliography named in DTLmultibibs you must use DTLcite text mbib cite key list This is analogous to cite text cite key list but writes the 145 citation command to mbib aux instead of to the document s main auxiliary file It also ensures that the cross referencing labels are based on mbib to allow you to have the same reference in more than one bibli
22. 158 graphics package 123 graphicx package 123 I ifallfemale 157 ifallmale 157 ifdefempty 63 ifDTLverticalbars 120 kKiELlemale sea eee dE ses 197 iffemalelabel 157 Kiltbmale san ee SES 157 ifmalelabel 157 ifpersonexists 156 ifthen package 16 48 136 L longtable environment 42 43 longtable package 42 43 M malelabels 149 155 malename 158 158 nldeule anna 47 N newperson 149 155 n t exe a een nee 136 P package options color databat Ad ENKEN ees 115 datapie 86 delimiter 2 gray databar 115 datapie 86 horizontal databar 115 120 Math 22e RR y 2 3 VEER 24 pgfmath 2 norotateinner datapie 86 88 norotateouter datapie 86 88 rotateinner datapie 86 88 rotateouter datapie 86 88 separator 2 style databib 137 138 verbose 2 3 129 TUG ae aan SE vertical G databar 115 120 Peoplechild 154 peoplechild 154 peoplefullname 153 peoplename 0 4 153 Peopleobjpronoun 153 peopleobjpronoun 153 Peopleparent 154 peopleparent 154
23. 2 amp bfseries Assign 3 amp bfseries Average Mark DTLforeach marks surname Surname firstname FirstName average Average assignI Assignment 1 assignII Assignment 2 assignIII Assignment 3 surname amp firstname amp assignI amp assignII amp assignIII amp DTLround average average 2 DTLclip average average relax end tabular end table This produces Table 5 18 67 Note that if I only wanted the averages for the table and nothing else I could simply have computed the average in each row of the table and displayed it without adding the information to the database however I am going to reuse this information in example 33 so adding it to the database means that I don t need to recompute the mean Table 5 18 Student marks Surname First Name Assign1 Assign2 Assign3 Average Mark Smith Jr John 68 57 72 Brown Jane 75 84 80 Brown Andy 42 52 54 Adams Z e 52 48 57 Brady Roger 58 60 62 Verdon Clare 45 50 48 5 7 Arithmetical Computations on Database Entries The commands used in chapter 3 can be used on database entries You can of course directly use the commands provided by the fp package if you know that the values are in the correct format i e no currency symbols no number group separators and a full stop as the decimal point but if this is not the case then you should use the commands described in chapter 3 If you want to use acommand provided by the fp packa
24. 87 innerratio 87 outerlabel 88 96 outeroffset 87 88 outerratio 87 radius 2 240 420 87 ler u a 87 rotateinner 88 rotateouter o 88 SLabl oae eite eoe RR o 86 variable 86 87 93 DTLpieoutlinecolor 95 DTLpieoutlinewidth 96 DTLpiepercent 93 DTLpieroundvar counter 93 DTLpievariable 23 DTLplot 99 108 110 113 114 NDTLplot options VO su ew qq ee at 100 bounds 99 101 bOX cease ers ee a Re ae 100 COlOIS lr x gs 99 grid aue nee Eus 102 height ies ee 100 legend 102 105 legendlabels 102 linecolors 99 lines vy t dS 100 markcolos 99 MAKS uu ee oe RES PES 99 MAXX 4 93 e oed on 101 Maxy ar ii qe 101 MINE rara 101 MINDY es 101 Slyle une 100 103 ticdi rer Ren 101 width ooo 100 165 99 label o su see 102 xminortics 101 Xxticdi cad sees 101 xliGgap used eec ee det 101 xticlabels 102 xticpoints 101 105 EE 100 Y 2ee Rae ee eee doe ees 99 ylabel 2 2 24s RE 102 yminortics 101 ylicdir iu usce Ren 101 yticgap 101 102 yticlabels 102 yticpoints 101
25. DTLinitialhyphen 34 DRI a eb ei el dardos 33 dtlintalign E E e 45 dtlintforma t aie ca 46 DETAINEE Y DE ae weet ay RR ee do 79 DTLisclosedbetween 19 DTLiscurr noy seeen esias 17 DTLiscurrencyunit 17 DILZSeq i elsceas wm 19 DTLisFPclosedbetween 21 DILisEPeq wee dE hee mas 21 DTLISFPOL 242 4 oia 20 DTLisFPgteq 20 DTLhisERLE nissan 20 DILIsSEPIteq serena a aa 20 DTLisFPopenbetween 21 DTLLSGE 2 18 53 DTLisiclosedbetween 19 DILiSledg vais skies ee a x 19 DTEISIGE osa nas Ve eda d 19 Se CHE 18 D EIGS TIS Sy ice as ene 18 DTLisiopenbetween 20 DCS o P othe a Be 18 DTLisnumerical 17 DTLisopenbetween 20 DThEisPfeflX eee 21 DILisr dl hi dense 4 ms 18 DILisString cepas atea 16 DILisSubString rera nee dos 21 DTLlegendxoffset 109 DTLlegendyoffset 109 DILloadbDl zer 133 DTLloaddb 38 40 155 DTLloaddb options headers o o 39 59 keys sies n 9k beeen awe 38 P NT Ae E ZZ E d EI tJ tJ EI Ei PAGO E EE GO EE EE AE E E Men I OSA eg E 7 i D O G G DD DD QUU UU UU UU UU DD UU UU CU 3 ud Eu ud a J r r noheader ls 38 noheaders 43 omitlines 39 TLloadmbbl 146 TLlo dtawdb i e ms 40 TLmajorgridstyle 111 TUMAR A 28 EE EES 28 Lmaxauthors counter 140 Lmaxeditors counter 14
26. Lieu p xo 4 ee a ee a 102 Plot ng Multiple Data Sets as 3 ese ao a era 105 Adding Information foa Plot oi es sx x NN aaa 107 Adding toa Plotshesm o o cde ee ee dex 112 Plotting Multiple Keys in the Same Database 112 A Basie Bar Chat eco Mu seu da e e xut e xS 117 A Labelled Bar Chart lt 2 4 83 2 8 8 85 2 BE a ed 121 Profit Loss Bar Chart 2 2 2 ae nee 121 A Multi Bar Chart nme ee 124 Creating a list of publications since a given year 136 Creating a list of my 10 most recent publications 137 Compact bibliography lt Ad cres m neg Ro 141 Highlighting a given author 2 6 6 eR Rm 141 38 39 40 41 42 Separate List of Journals and Conference Papers 144 Multiple Bibliographies 656 t RR x 146 Order of Service Memorial 152 Order a Service Baptist lt s 22 cab ss whe x GEG e Ye s 154 Mail Merging Using Appropriate Gender 155 vi List of Figures 6 1 6 2 6 3 6 4 6 5 6 6 67 6 8 6 9 6 10 Zl Zu 7 9 7 4 pA 7 6 Ja 8 1 8 2 8 3 8 4 8 5 PCC ea repa ii TET 89 A pie chart outer labels sel o cr v9 oor RR s 89 A pie chart rotation enabled s 646228522825 wus 90 A pie chart with cutaway segments 666420405 04 91 A pie chart with cutaway segments cutaway 1 2 92 A pie chart with cutaway segments cutaway 1 2 92 A pie chart changing the labels e t 94 A pie chart changing the label format
27. Smith Jr John 68 Verdon Clare 45 de la Mere Jos 58 van der Mere Henk 71 76 Table 5 23 Student scores case ignored when sorting Surname First Name Score Adams Z e 52 Brady Roger 58 Brown Andy 42 Brown Jane 75 de la Mere Jos 58 Smith Jr John 68 vander Mere Henk 71 Verdon Clare 45 Example 17 Influencing the sort order Consider the data displayed in Table 5 23 suppose that you want the names van der Mere and de la Mere sorted according to the actual surname Mere rather than by the von part There are two ways you can do this firstly you could store the von part in a separate field and then sort by surname then von part then first name or you could define a command called say switchargs as follows Xnewcommandx 1switchargs 2 4241 then store the data as FirstName Surname StudentNo Score John Smith Jr 102689 68 Jane Brown 102647 75 Andy Brown 103569 42 ZN oe Adams 105987 52 Roger Brady 106872 58 Clare Verdon 104356 45 Henk switchargs Mere van der 106789 71 Jos switchargs Mere de la 104256 58 Now sort the data and put it in table this is the same code as in the previous example begin table htbp caption Student scores influencing the sort order centering DTLsort Surname FirstName scores begin tabular llr bfseries Surname amp bfseries First Name amp bfseries Score DTLforeach scores firstname FirstN
28. UE 100 DTLplotatbegintikz 107 113 114 DTLplotatendtikz v 107 115 DTLpLotheight seu 108 DTLplotlinecolors 110 DTLplotlines nes 110 DTLplotmarkcolors 110 DTLplotmarks 110 DTLplotroundXvar counter 109 DTLplotroundXvar counter 102 114 DTLplotroundYvar counter 109 DTLplotroundYvar counter 102 DTLplotstream 121 113 DTLplotwidth 108 DTLrawmap sicarios ieu 41 dtlrealalign 45 dtlrealformat 46 XDILreattype sss othe v4 x a 79 dtlrecombine 84 dtlrecombineomitcurrent 84 DTLremovecurrentrow 66 DTLremoveentryfromrow 66 dtlremoveentryincurrentrow EE 85 DTLremoverow 66 DTLreplaceentryforrow 66 dt lreplaceentryincurrentrow DEE 85 NDELYOUNG 2288er 30 69 DTLLOwWeo nt criar 36 DTLrowi counter 50 DTLrowi counter 54 55 DTLrowii counter 50 DTLrowiii counter 50 166 dtlrownum 84 DTLsavedb o o 78 DTLsavelastrowcount 51 69 DTLsavetexdb 78 DELSIFOFANN extras 29 DTLsdforcolumn 71 DTLsdforkeys A DTLsetbarcolor 118 DTLsetdefaultcurrency 23 DTLsetdelimiter 39 78 DTLsetheader 38 DTLsetnumberchars 4 DTLsetpiesegmentcolor 95 DTLsetseparator 39 78 DTLsettabseparator 39 78 ADTUSOT E u
29. X dtlheaderformat 45 DTLifAllLowerCase 15 N DTLifAllUpperCase 14 DTLifbibanyfieldexists 144 DTLifbibfieldexists 143 DTLifcasedatatype 8 N DTLifclosedbetween 13 X DTLifclosedbetween 13 A DTELECUEDENOS xe wx 6 N DTLifcurrencyunit 7 N DTLifdbempty 33 A DTLifdbexists 80 DIhifeq 24 ete ea eee pee S EN DTLifeqk waded noche de eta nh ed Si 3 DIHiffifsSbrOW sepia 51 DTLifFPclosedbetween 14 DTLifFPopenbetween 14 DTLILgGE meridia acts argos ees 12 DEL fgEX aaa 12 N DTLifhaskey 80 DIEifinl st xi ex 9s 82 N DILifint are 5 N KE EE IF N DILITIES es russ JI X DTLifnull ici n 63 DTLifnumclosedbetween 12 N DTLifnumeq B X dtlrfnumeq sse 8 N DTLifnumerical WX DTLifn mgt si 9 HN DILT NUMIE sive x 6n 10 dil Ifnumbb 3 2026 na xv 10 DTLifnumopenbetween BON DTLifoddrow 51 56 DTLifopenbetween 14 DTLifopenbetween 14 DIEIFrEAl e ema B X DThifStartsWith 2i 16 DTLifstring iiie 3 cR 8 164 DTLifstringclosedbetween 12 DTLifstringclosedbetween Tm 12 DTLifstringeq 9 DTLi3fstringeq decanos pid g DTbifstrihnggt i s 11 DTLifstringgt ee 11 DILifstreinglt ce 10 DThifstringlt ee 10 DTLifstringopenbetween 13 DTLifstringopenbetweenx 13 DTLhifSubString i 15
30. body Y This iterates through the column given by key in the database given by db and applies body In each iteration cs which must be a control sequence is set to the current element in the column and may be used in body Alternatively if you want to identify the column by its index rather than its key use dtlforcolumnindex dtlforcolumnindex cs db col index body DTLifdbexists DTLifdbexists db name true part false part Determines if the database given by db name exists DTLifhaskey DTLifhaskey db name key true part false part This determines if the database given by db name has any entries with the key given by key If so it does true part otherwise it does false part Each key has an associated column index This can be obtained using DTLgetcolumnindex DTLgetcolumnindex cs db key where cs is a command name db is the database label and key is the key The column index is stored in cs You can also do the reverse and find the key associated with a given column index DTLgetkeyforcolumn 80 dtlcolumnindex DTLgetkeydata DTLgetvalue DTLgetlocation DTLgetkeyforcolumn key cs db column index The key is stored in key cs which must be acommand name There is also a full expandable way of obtaining the column index but note that no check is performed to
31. c z mystr produces abzdze DTLsplitstring DTLsplitstringt string split text before cmd after cmd This splits string at the first occurrence of split text and stores the before part in the command before cmd and the after part in the command after cmd For example DTLsplitstring abcdce c beforepart afterpart Before part beforepart After part afterpart produces Before part ab After part dce Note that for DTLsplitstring string is not expanded so def mystr abcdce DTLsplitstring mystr c beforepart afterpart Before part beforepart After part afterpart produces Before part abcdce After part If you want the string expanded you will need to use expandafter def mystr abcdce expandafter DTLsplitstring expandafter mystr c beforepart afterpart Before part beforepart After part afterpart which produces Before part ab After part dce DTLinitials DTLinitials string This converts string typically a name into initials For example DTLinitials Mary Ann produces M A including the final full stop Note that DTLinitials Mary Ann produces M A including the final full stop Be careful if the initial letter has an accent The accented letter needs to be placed in a group if you want the initial to also
32. cs gender cs and label cs are set to the current person s name full name gender and label respectively These arguments must all be command names Note that the gender is malename set to the definition of malename or femalenane as appropriate femalename Once these commands are set body is applied If you only want to iterate through a subset of defined people you can use foreachperson name cs full name cs gender cs label cs Mint list do t body where list is a comma separated list of labels 10 3 3 Accessing Individual Information getpersongender getpersongender cs label Gets the gender of the person identified by label and stores in cs which must be a command name This sets cs to the definition of malename or femalename as appropriate getpersonname getpersonname cs label Gets the name of the person identified by label and stores in cs which must be a command name 1Predefined names provided by the person package are described in the documented code datatool pdf 158 getpersonfullname getpersonfullname cs label Gets the full name of the person identified by label and stores in cs which must be a command name 159 Bibliography 1 Michel Goossens Frank Mittelbach and Alexander Samarin The Dick Companion Addison Wesley 1994 160 Acknowledgements Many thanks to Morten He
33. currency last encountered So for example DTLifcurrency texteuro45 00 DTLdecimaltocurrency 267 5 price price will produce 267 50 This is because the last currency symbol to be encountered was texteuro You can reset the currency symbol using the command DTLsetdefaultcurrency DTLadd DTLsetdefaultcurrency symbol For example DTLsetdefaultcurrency textyen DTLdecimaltocurrency 267 5 price price will produce 267 50 The datatool base package provides convenience commands which use DTLconverttodecimal and then use the basic macros provided by the fp pgfmath package The resulting value is then converted back into the locale format using DTLdecimaltolocale or DTLdecimaltocurrency Note that since these commands use DTLconverttodecimal the caveat above regarding expansion also applies to all the commands DTLadd cmd num1 num2 DTLgadd DTLgadd cmd num1 y num2 This sets the control sequence cmd to num1 num2 DLTadd sets cmd locally while DTLgadd sets cmd globally For example DTLadd result 3 562 65 412 2 result will produce 3 974 85 Since DTLconverttodecimal can convert currency to a real number you can also add prices For example DTLadd result pounds3 562 65 pounds452 2 result produces 4 014 85 Note that datatool isn t aware of exchange rates If you use different currency symbols the la
34. emaill emph Missing emaill amp iifnull NemailII Nemph Missing NemailII amp DTLifnull regnum emph Missing regnum end tabular e D D D 64 This produces the following First Name Surname Email1 Email 2 Reg Num Mary Jones mj my uni ac uk mj somewhere com Missing Adam Smith as my uni ac uk Missing 12345 If you want to do this you may find it easier to define a convenience command that will display some appropriate text if an entry is missing for example newcommands checkmissing 1 DTLifnull 1 1 Then instead of typing say DTLifnull regnum regnum you can instead type checkmissing regnum Now suppose that instead of defining the database using DTLnewdb DTLnewrow and DTLnewdbentry you have a file with the contents Surname FirstName RegNum Emaill Email2 Jones Mary mj my uni ac uk mj somewhere com Smith Adam 12345 as my uni ac uk and you load the data from this file using DTLloaddb defined in section 5 2 Now the database has no null values but has an empty value for the key RegNum on the first row of the database and an empty value for the key Email2 on the second row of the database Now the following code begin tabular 11111 bfseries First Name amp bfseries Surname amp bfseries Email 1 amp bfseries Email 2 amp bfseries Reg Number DTLforeach email
35. entry over all entries satisfying conditions in the database db name where the label is given by bib label and the result is stored in cmd which may then be used in the argument of the thebibliography environment The counter DTLbibrowkeeps track of the current bibliography entry This is reset at the start of each DTLforeachbib and is incremented if conditions is met Within the optional argument condition you may use any of the commands that may be used within the optional argument of DTLbibliography described in section 9 3 Example 38 Separate List of Journals and Conference Papers Suppose now my boss has decided that Ineed to produce a list of allmy publications but they need to be separated so that all the journal papers appear in one section and all the conference papers appear in another section The journal papers need to be labelled J1 J2 and so on while the conference papers need to be labelled C1 C2 and so on My boss isn t interested in any of my other publications Again all my publications are stored in the BIBTpX database nlct bib The following creates the required document documentclass article usepackage databib 144 DTLmultibibs DTLcite begin document Xnocite x DTLloadbbl mybib nlct renewcommand refname Journal Papers DTLcomputewidestbibentry equal DBIBentrytype article mybib J theDTLbibrow widest begin thebibliography
36. following ways 1 First names von part Surname Jr part The von part is optional and is identified by the name s starting with lowercase letters The final comma followed by Jr part is also optional Examples author Henry James de Vere In the above the first names are Henry James the von part is de and the surname is Vere There is no junior part author Mary Jane Brown Jr In the above the first name is Mary Jane there is no von part the surname is Brown and the junior part is Jr author Peter Murphy Allen In the above the first name is Peter and the surname is Murphy Allen Note that in this case the surname must be grouped otherwise Murphy would be considered part of the forename author Maria Eliza uppercase d e La Cruz In the above the first name is Maria Eliza the von part is De La and the surname is Cruz In this case the von part starts with an uppercase letter but specifying author Maria Eliza De La Cruz would make BIBIEX incorrectly classify Maria Eliza De La as the first names and the von part would be empty Since BIBTEX doesn t understand TEX commands using uppercase d e La will trick BIBIEX into thinking that it starts with a lower case letter 131 2 von part Surname Forenames Again the von part is optional and is determined by the case of the first letter For example author de Vere Henry James
37. have an accent otherwise the accent command will be ignored For example DTLinitials E lise Adams produces E A whereas DTLinitials Elise Adams produces E A In fact any command which appears at the start of the name that is not enclosed in a group will be ignored For example DTLinitials MakeUppercase m ary ann produces m a whereas DTLinitials MakeUppercase m ary ann produces M a but note that DTLinitials MakeUppercase mary ann produces mary ann DTLstoreinitials DTLstoreinitials string cmd This converts string into initials and stores the result in cmd which must be a command name The remarks about DTLinitials also relate to DTLstoreinitials For example DTLstoreinitials Marie E lise del Rosario thelnitials thelnitials 33 produces M E d R Both the above commands rely on the following to format the initials DTLafterinitials DTrLlarterinitials This indicates what to do at the end of the initials This simply does a full stop by default DTLbetweeninitials DTLbetweeninitials This indicates what to do between initials This does a full stop by DTLinitialhyphen DTLinitialhyphen Q m 9 c This indicates what to do at a hyphen This simply does a hyphen by default but can be redefined to do nothing to prevent the hyphen appearing in the initials DTLafterinitialbeforehyph
38. is used Note that there is no starred version of this command instead use DTLisiopenbetween n DTLisiopenbetween arg min max This checks if arg lies between min and max end points excluded As with ADTLifopenbetweenx if the arguments are numerical a numerical comparison is used otherwise a case insensitive alphabetical comparison is used DTLisFPlt numl num2 This checks if num1 is less than num2 where both numbers are in standard fixed point format i e no number group separators no currency and a full stop as a decimal point DTLisFPlteq num1 num2 This checks if num1 is less than or equal to num2 where both numbers are in standard fixed point format i e no number group separators no currency and a full stop as a decimal point DTLisFPgt num1 num2 This checks if num1 is greater than num2 where both numbers are in standard fixed point format i e no number group separators no currency and a full stop as a decimal point DTLisFPgteq numl num2 20 DTLisFPeq This checks if num1 is greater than or equal to num2 where both numbers are in standard fixed point format i e no number group separators no currency and a full stop as a decimal point DTLisFPeq num num2 This checks if num1 is equal to num2 where both numbers are in standard fixed point format i e no number group separators no currency a
39. keys to omit foot The longtable s foot lastfoot The foot for the last page of the longtable For example suppose I have a database called iris then I can display the contents in a longtable using DTLdisplaylongdb caption Iris Data label tab iris contcaption Iris Data continued foot em Continued overleaf lastfoot iris Ican then reference the table using ref tab iris See the longtable documentation for details on how to change the longtable settings such as how to change the table so that it is left aligned instead of centred on the page Note that if you want more control over the way the data is displayed for example you want to filter rows or columns you will need to use DTLforeach described in section 5 4 Example 1 Displaying the Contents of a Database Suppose I have a file called t2g csv that contains the following 40 120 40 40 90 60 35 180 20 55 190 40 This represents time to growth data where the first column is the incubation temperature the second column is the incubation time and the third column is the time to growth This file has no header row so when it is loaded the noheaders option is required Note that DTLdisplaydb only puts the data in a tabular environment so DTLdisplaydb needs to be put in a table environment with a caption to make it a float First load the data base setting the keys and headers DTLloaddb noheader keys Temper
40. label and personnanel label peoplepronoun peoplepronoun Peoplepronoun Peoplepronoun peopleobjpronoun peopleobjpronoun Peopleobjpronoun Peopleobjpronoun peoplepossadj peoplepossadj Peoplepossadj e 3 gt E Li S E gt oO o A o 5 o Peoplepossadj peopleposspronoun 153 peopleposspronoun Peopleposspronoun peoplechild Peoplechild peopleparent Peopleparent peoplesibling Peoplesibling Peopleposspronoun lt me gt t 4 oO Du 3 o P o 2 oO oO Ko o 3 E Di n n c b 3 Q m B oO a O D O Si o En gt oO Ka b Re y commands is equivalent to person label or Person label If more than one person has been defined these commands will display they them their theirs or They Them Their Theirs as appropriate Likewise for relationship commands peoplechild Peoplechild peopleparent Peopleparent peoplesibling Peoplesibling newperson john John Joseph John male newperson jane Jane Mary Jane female begin document 154 begin center Large Baptism of peoplefullname end center Today we welcome peoplename into God s family may He guide and protect peopleobjpronoun end document This is produces the following text Baptism of John Joseph and Jane Mary Today we welcome John and Jane into God s family m
41. listed If this macro is set to empty the current colour will be used instead The default is the same as DTLplotmarkcolors DTLXAxisStyle 110 This governs the style of the x axis It is passed as the optional argument to the TikZ draw command By default it is just which is a solid line style with no start or end arrows The x axis line starts from the bottom left corner of the plot and extends to the bottom right corner of the plot So if you want the x axis to have an arrow head at the right end you can 0 a renewcommands DTLXAxisStyle gt DTLYAxisStyle DTLYAxisStyle This governs the style of the y axis It is analogous to DTLXAxisStyle described above DTLmajorgridstyle DTLmajorgridstyle This specifies the format of the major grid lines It may be set to any TikZ setting that you can pass to the optional argument of draw The default value is color gray which indicates a grey solid line DTLminorgridstyle DTLformatlegend DTLplotstream DTLminorgridstyle This specifies the format of the minor grid lines It may be set to any TikZ setting that you can pass to the optional argument of draw The default value is color gray loosely dotted which indicates a grey dotted line DTLformat legend legend This formats the entire legend which is passed as the argument The default is to set the legend with a white background a black frame 7 3 Adding to a Plot Stream DTLplot
42. marks 57 52 5224 N ea oo NO Clare Verdon Average 47 67 Roger Brady Average 60 Z e Adams Average 52 33 Andy Brown Average 49 33 Jane Brown Average 79 67 John Smith Jr Average 65 67 128 9 Converting a BIBTEX database into a datatool database databib package The databib package provides the means of converting a BIBIEX database into a datatool database The database can then be sorted using DTLsort described in section 5 8 For example you may want to sort the bibliography in reverse chronological order Once you have sorted the bibliography you can display it using DTLbibliography described in section 9 3 or you can iterate through the database using XDTLforeachbib described in section 9 5 Note that the databib package is not automatically loaded by datatool so if you want to use it you must load it using usepackage databib The purpose of this package is to provide a means for authors to for mat their own bibliography style where there is no bibliography style file available that produces the desired results The ADTLsort macro uses a much less efficient sorting algorithm than BIBTEX and loading the bibliography as a datatool database is much slower than loading a standard bb1 file If you have a large database and you are worried that TEX may have become stuck try using the verbose option to data tool or use the command dtlverbosetrue This will print
43. number of authors etalname is used the definition of which is given in section 5 4 The default value of DTLmaxauthors is 10 DTLmaxeditors The DTLmaxeditors counter is analogous to the DTLmaxauthors counter It is used to determine the maximum number of editor names to display The default value of DTLmaxeditors is 10 Within a list of author or editor names DTLandlast is used between the last two names otherwise DTLandnot last is used between names However if there are only two author or editor names DTLtwoand is used instead of DTLandlast The command DTLendbibitem is a hook provided to add additional information at the end of each bibliography item This does nothing by default but if you want to display the additional fields provided by the databib bst style file you can redefine DTLendbibitem so that it displays a particular field if it is defined Within this command you may use the commands DTLbibfield DTLifbibfieldexist and DTLifanybibfieldexist which are described in section 9 5 For example if you have used the abst ract field in any of your entries you can display the abstract as follows renewcommand DTLendbibitem 5again it also checks jr part to determine if it ends with a full stop 140 DTLifbibfieldexists Abstract DTLpar textbf Abstract begin quote DTLbibfield Abstract end quote Note that DTLpar needs to be used instead of par Example 36 Compact biblio
44. on the value of theProfit 123 DTLbarchartwidth DTLnegextent DTLbarmax Both DTLbarchart and DTLmultibarchart set the following macros which may be used in DTLbaratbegintikz and DTLbaratendtikz DrTEbarceharewideh This is the overall width of the bar chart In the case of DTLbarchart this is just the number of bars In the case of DTLmultibarchart itis computed as mxn m 1 xg where m is the number of bar groups i e the number of rows of data n is the number of bars within a group i e the number of commands listed in the variables setting and g is the group gap as specified by the groupgap setting DTLnegextent This is set to the negative extent of the bar chart This value may either be zero or negative and corresponds to the maxdepth setting DTLbarmax This is set to the maximum extent of the bar chart This value corresponds to the max setting 2003 2002 2001 2000 Profit Loss Figure 8 3 Profits for 2000 2003 Example 33 A Multi Bar Chart This example uses the marks database described in example 13 Recall that this database stores student marks for three assignments The keys for the assignment marks are Assignment 1 Assignment 2and Assignment 3 respectively I can convert this data into a bar chart using the following 124 begin figure htbp centering DTLmultibarchart variables assignI assignII assignIIL barwidth 10pt uppermultibarlabels
45. order is either ascending or descending If the order is omitted ascending is assumed The database keeps track of the data type for a given key and uses this to determine whether an alphabetical or numerical sort is required String comparisons are made using the command dtlcompare or dtlicompare described in subsection 1 6 1 The optional argument replacement key list is a list of keys to use if the current key given in sort criteria is null for a given entry Null keys are unlikely to occur if you have loaded the database from an external ASCII file but may occur if the database is created using DTLnewdb DTLnewrow and DTLnewdbent ry For example DTLsort Editor Organization Author mydata will sort according to the Author key but if that key is missing for a given row of the database the Editor key will be used and if the Editor key is missing it will use the Organization key Note that this is not the same as DTLsort Author Editor Organization mydata which will first compare the Author keys but if the author names are the same it will then compare the Editor keys and if the editor names are also the same it will then compare the Organization keys The unstarred version uses a case sensitive comparison for strings whereas the starred version ignores the case when comparing strings Note that the case sensitive comparison orders uppercase characters before lowercase characters so the letter B i
46. part false part If the current row is the first row then do true part otherwise do false part DTLifoddrow DTLifoddrow true part false part If the current row number is an odd number then do true part otherwise do false part DTLsavelastrowcount DTLsavelastrowcount cmd This command will store the value of the row counter used in the last occurrence of DTLforeach in the control sequence cmd DTLforeachkeyinrow DTLforeachkeyinrow cmd y text This iterates through each key in the current row globally assigns cmd to the value of that key and does text cmd must be a control sequence and may be used in text This command may only be used in the body of DTLforeach At each iteration DTLforeachkeyinrow sets dtlkey to the current key 1dt1co1 to the current column index dtltype to the data type for the current column and dt lheader to the header for the current column Note that dt 1t ype corresponds to the column type but if the entries in the column have mixed types it may not correspond to the type of the current entry ct ct dtlbreak dtlbreak You can break out of most of the loops provided by datatool using dt lbreak Note however that it doesn t break the loop until the end of the current iteration There is no provision for a next or continue style command Additional loop commands provided by datatool are described in the documen
47. result will produce 1 137 9 Again num1 or num2 may be currency but unlike DTLadd and DTLsub currency overrides integer real For example DTLmul result pounds568 95 2 result will produce 1 137 90 Likewise DTLmul result 2 pounds568 95 result will produce 1 137 90 Although it doesn t make sense to multiply two currencies datatool will allow DTLmul result 2 pounds568 95 result DTLdiv DTLgdiv DTLabs DTLgabs DTLneg DTLgneg which will produce 1 137 90 DTLdiv cmd num1 num2 DTLgdiv cmd num1 num2 This sets the control sequence cmd to num1 num2 NDLTdiv sets cmd locally while DTLgdiv sets cmd globally For example DTLdiv result 501 2 result will produce 250 5 Again num1 or num2 may be currency but the resulting type will be not be a currency if both num1 and num2 use the same currency symbol For example DTLdiv result 501 2 result will produce 250 5 Whereas DTLdiv result 501 2 result will produce 250 50 DTLabs cmd num DTLgabs cmd num This sets cmd to the absolute value of num DLTabs sets cmd locally while DTLgabs sets cmd globally Example DTLabs result pounds2 50 result produces 2 50 DTLneg cmd num DTLgneg cmd num 26 DTLsqrt DTLgsqrt DTLmin DTLgmin This sets cmd
48. t rue is assumed Example 30 A Basic Bar Chart Recall example 19 defined a database called fruit This example will be using that database to plot a bar chart The following plots a basic vertical bar chart begin figure htbp centering DTLbarchart variable theQuantity fruit theQuantity Quantity caption A basic bar chart end figure This produces Figure 8 1 8 1 Changing the Appearance of a Bar Chart DTLbarchartlength DTLbarchartlength 117 DTLbarwidth Figure 8 1 A basic bar chart This specifies the total length of the y axis You must use set length to change this value The default value is 3in DTLbarwidth This specifies the width of each bar You must use set length to change this value The default value is 1cm DTLbarlabeloffset DTLbarroundvar DTLsetbarcolor Derbarlabelorrsee This specifies the distance from the x axis to the lower bar label You must use setlength to change this value The default value is 10pt DTLbarroundvar The y tick labels are rounded to n digits after the decimal point where n is given by the value of the counter DTLbarroundvar You must use setcounter to change this value 118 DTLsetbarcolor n color This sets the 1 th bar colour to color Only the first eight bars have a colour defined by default If you need more than eight bars you will need to define more bar colours It is recommended that y
49. tabular colalign egintabular F doamp gdef doamp amp foreachkey theKey theCol theType theHead in scores do Lifeq theKey StudentNo doamp bfseries theHead foreach scores def doamp gdef doamp amp foreachkeyinrow thisValue TLifeg dtlkey StudentNo doamp thisValue tabular table The result is shown in Table 5 13 59 Table 5 13 Student Scores Filtering Out a Column FirstName Surname Score John Smith Jr 68 Jane Brown 75 Andy Brown 42 Zoe Adams 52 Roger Brady 58 Clare Verdon 45 Example 10 Nested DTLforeach In this example I have a CSV file called index csv which contains File Temperature NaCl pH exp25a csv 25 4 7 0 5 exp25b csv 25 4 8 1 5 exp30a csv 30 5 12 4 5 The first column of this file contains the name of another CSV file which has the results of a time to growth experiment performed at the given incubation temperature salt concentration and pH The file exp25a csv contains the following Time Log Count 0 3 75 2354959 45 4 0 The file exp25b csv contains the following Time Log Count 0 3 6 60 3 8 120 4 0 The file exp30a csv contains the following Time Log Count 0 32 78 23 3 67 60 4 9 Suppose I now want to iterate through index csv load the given file and create a table for that data I can do this using nested DTLforeach as follows 60 load index data file DTLloaddb index
50. that substring must occur at the start of string This command performs a case sensitive match For example DTLifStartsWith An apple app prefix not a prefix produces not a prefix All the above remarks for DTLifSubString also applies to DTLifStartsWith For example DTLifStartsWith uppercase a n apple an prefix not a prefix produces prefix since uppercase is ignored and is considered to be the same as a space whereas DTLifStartsWith An apple an prefix not a prefix produces not a prefix 2 2 ifthen conditionals The commands described in the previous section can not be used as the conditional part of the i ft henelse or whiledo commands provided by the ifthen package This section describes analogous commands which may only be used in the conditional argument of Ni fthenelse and whiledo These may be used with the boolean operations not and and or provided by the ifthen package See the ifthen documentation for further details DTLisstring text Tests if text is a string For example ifthenelse DTLisstring some text string not a string 16 DTLisnumerical DTLiscurrency produces string DTLisnumerical text Tests if text is numerical i e not a string For example ifthenelse DTLisnumerical 10 95 numerical not numerical produces numerical Note however that DTLisnumerical requires more care than DTLifnumerical when used with some
51. the scores are integers however as it s possible that an entry may feasibly have a decimal score I have used DTLisgt instead Table 5 6 Top student scores First Name Surname Score John Smith Jr 68 Jane Brown 75 2 students scored above 60 Suppose now I only want to display the scores for students whose surname begins with P I can do this as follows 53 begin table htbp caption Student scores B centering begin tabular llr bfseries First Name amp bfseries Surname amp bfseries Score DTLforeach DTLisopenbetween surname B C scores firstname FirstName surname Surname score Score 1 firstname amp surname amp score end tabular end table This produces Table 5 7 Table 5 7 Student scores B First Name Surname Score Jane Brown 75 Andy Brown 42 Roger Brady 58 Example 6 Breaking Out of a Loop Suppose I only want to display the first three rows of a database I could doc DTLforeachx value DTLrowi lt 3 scores firstname FirstName surname Surname score Score firstname amp surname score However this isn t very efficient as it still has to iterate through the entire database checking if the condition is met If the database has over 100 entries this will slow the time taken to create the table It would therefore be much more efficient to break out of the loop when row count exceeds 3 beg
52. to r right aligned dtlrealalign dtlrealalign The alignment for real numbers defaults to r right aligned dtlcurrencyalign dtlcurrencyalign The currency alignment defaults to r right aligned You can redefine these to change the column alignments For example if you want columns containing strings to have the alignment p 2in then you can redefine dtlstringalign as follows renewcommand dtlstringalign p 2in You can t use siunitx s S column alignment with either DTLdisplaydb or DTLdisplaylongdb Instead you will need to use DTLforeach The siunitx documentation provides an example In addition to the Nat 1 type align commands above you can also modify the tabular column styles by redefining dt lbeforecols dt lbetweencols and dtlaftercols For example to place a vertical line before the start of the first column and after the last column do u dtlbeforecol dtlbetweencol dtlaftercol u u renewcommand dtlbeforecols renewcommand dtlaftercols If you additionally want vertical lines between columns do renewcommand dtlbetweencols Limited modifications can be made to the way the data is displayed with DTLdisplaydband DTLdisplaylongdk The commands controlling the formatting are described below If amore complicated layout is required you will need to use DTLforeach described in section 5 4 dt lheaderformat dtlheaderformat header
53. use of OELSE usse dede RS ERE ERG e E a Student Scores Iterating Through Keys Student Scores Using dtlforeachkey and BTLEGPSaChheyinrewW gt ed RE Student Scores Filtering Out a Column Temperature 25 NaCl 4 7 pH 0 5 illustrating nested DILforeach ociosas eS ESOS boa EES Temperature 25 NaCl 4 8 pH 1 5 illustrating nested KE ue ok og EE Sees ee Temperature 30 NaCl 5 12 pH 4 5 illustrating nested NEE een Hy Eer RO Sm Bo en Chab Membership lt eas d Oe bk u Se EN eR RA Student marks with averages 6 6 4u2 o nes Student scores using arithmetic computations Student scores sorted by score i c mw Student scores sorted by name Student scores case sensitive sort Student scores case ignored when sorting Student scores influencing the sort order Two database rows per tabular row column wise 1 Introduction The datatool bundle consists of the following packages datatool which loads datatool base and either datatool fp or datatool pgfmath datapie dataplot databar and databib The datatool package can be used to e Create or load databases e Sort rows of a database either numerically or alphabetically ascending or descending Perform repetitive operations on each row of a database e g mail merging Conditions may be imposed to exclude rows Package Options ve
54. ut f8 inputenc This creates a new database called db name and fills it with the entries given in the file filename The filename may have a header row at the start of the file which provides the key when creating a new database entry using DTLnewdbent ry The optional argument options is a key value list of options Available options are noheader This is a boolean value and indicates if the file does not contain a header If no value is supplied true is assumed i e the file doesn t contain a header row If this option is omitted it is assumed that the file contains a header row keys This is a comma separated list of keys to use where the keys are listed in the same order as the columns If the file has a header 38 these keys will override the values given in the header row If the file has no header row and no keys are supplied in options then the keys will be given by dtldefaultkey n where n is the dtldefaultkey column number and dtldefaultkey defaults to Column Note that the list of keys must be delimited by braces since they contain commas For example DTLloaddb noheader keys Temperature Time T2G data data csv headers This is a comma separated list of headers If not supplied the header will be the same as that given in the header row or the key if there is no header row Note that the list of headers must be delimited by braces since they contain commas For example DTLl
55. yo oO H Ko o 3 2 Di n o oO D 3 Q o E c a cr D oO lt j Q o 3 B 2 oO oO 3 o 4 c a E d 3 Re removeallpeopl o 3 lt lt o E 4 oO 3 o 4 oO f wn E o Dm oO u E d 3 a removepeople list where list is a comma separated list of labels 10 2 Displaying Information 9 fo e o H o o 3 2 D Dn oc D 5 Q HEN 5 D a lt o fe o e 3 e Dn ach amp lt R4 2 P 3 D z E 2 3 ga y personfullname label where label is the unique label used in the optional argument to newperson The person s familiar name is displayed using 150 personname personpronoun personobjpronoun personpossadj personname label The person s pronoun he or she is displayed using personpronoun label The objective pronoun him or her is displayed using personob pronoun label The possessive adjective his or her is displayed using personpossadj label The possessive pronoun his or hers is displayed using personposspronoun personchild personparent personsibling personposspronoun label The person s relationship to their parent son or daughter is displayed using personchild label The person s relationship to their child mother or father is displayed using personparent
56. 0 TLmaxforcolumn 72 TLmaxforkeys 72 114 Lmbibliography 146 TLmeanforall 29 TLmeanforcolumn 70 TLmeanforkeys 70 72 Lmidpt rie 119 DLmin sess 49 9e ERA of DLmnindll ts ras 28 TLminforcolumn 72 PLminforkeyS 71 114 Lminorgridstyle 111 Lminorticklength 109 Lmintickgap 101 109 mu asien 25 TLmultibarchart 115 Lmult ibarchart options ANOS es acted Dei Gyn gg 116 barlabel 116 groupgap 117 124 El 116 MaX ia e 116 124 maxdepth 116 124 multibarlabels 116 uppermultibarlabels 117 variables 116 124 verticalbars 117 ylabel sy ds 117 yliGgap s eee ee ae ect 117 yticlabels 117 yticpoints 117 TEMultibibs 2 9s 145 TINGE zur arten 26 TLnegextent 124 TLnewcurrencysymbol 4 7 TLnewdb 35 78 148 TLnewdbentry 36 38 78 TLNEWLOW croatas das 36 78 L ocite i 3 x 146 Ndtlnoexpandnewvalue 37 DTLnumbernull 63 DTLnumitemsinlist 82 NDTLDaE sesi ese yes 37 42 DTLpieatbegintikz 97 DTLpieatendtikz oF ADTLpieCchaft eetis ieten 86 97 DTLpiechart options cutaway 87 90 cutawayoffset 87 cutawayratio 87 innerlabel 87 93 inneroffset
57. DB firstname FirstName surname Surname emaill Emaill emailII Email2 regnum RegNum DTLifnull firstname emph Missing firstname amp DTLifnull surname emph Missing surname DTLifnull emaill emph Missing emaill amp DTLifnull emailII emph Missing emaillI amp DTLifnull regnum emph Missing regnum end tabular 65 DTLremoverow DTLappendtorow produces First Name Surname Emaill Email 2 Reg Number Mary Jones mj my uni ac uk mj somewhere com Adam Smith as my uni ac uk 12345 5 6 Editing Database Rows A row can be removed from a data base using DTLremoverow db name row index where row index is the index of the unwanted row For example DTLremoverow scores 2 will delete the second row in the database labelled scores There is also a starred version that doesn t check for the existence of the database The following commands may be used in the body of the DTLforeach loop to edit the current row of the loop See also subsection 5 11 1 DTLappendt orow key value This appends a new entry with the given key and value to the current row value is expanded DTLreplaceentryforrow DTLreplaceentryforrow key value This replaces the entry for key with value value is expanded DTLremoveentryfromrow DTLremoveent ryfromrow
58. Lconverttodecimal num cmd The decimal number will be stored in cmd which must be a control sequence For example DTLconverttodecimal 1 563 54 mynum will define mynum to be 1563 54 The command mynum can then be used in any of the arithmetic macros provided by the fp or pgfmath packages The arguments to DTLconverttodecimal don t get fully expanded so for example def myval 1 23 DTLconverttodecimal myval mynum will work but the following won t work def myval 1 23 def myotherval myval DTLconverttodecimal myotherval mynum Nor will the following work def myval 9 DTLconverttodecimal myval 9 mynum There are two commands provided to perform the reverse DTLdecimaltolocale DTLdecimaltolocale number cmd 22 This converts a plain decimal number number that uses a full stop as the decimal character and has no number group characters into a locale dependent format The resulting number is stored in cmd which must be a control sequence For example DTLdecimaltolocale 6795 3 mynum will define mynum to be 6 795 3 DTLdecimaltocurrency DTLdecimaltocurrency number cmd This will convert a plain decimal number number into a locale dependent currency format For example DTLdecimaltocurrency 267 5 price price will produce 267 50 The currency symbol used by DTLdecimaltocurrency is initially but it will use the
59. Multiple authors or editors should be separated by the key word and for example author Michel Goossens and Frank Mittlebach and Alexander Samarin Below is an example of a book entry book latexcomp titl The LaTeX Companion author Michel Goossens and Frank Mittlebach and Alexander Samarin publisher Addison Wesley year 1994 Note that numbers may be entered without delimiters as in year 1994 There are also some predefined strings including those for the month names You should always use these strings instead of the actual month name as the way the month name is displayed depends on the bibliography style For example article Cawley2007b author Gavin C Cawley and Nicola L C Talbot title Preventing over fitting in model selection via B ayesian regularisation of the hyper parameters journal Journal of Machine Learning Research volume 8 pages 841 861 month APR year 2007 You can concatenate strings using the character for example month JUL 4 31 AUG lt 4 Depending on the bibliography style this may be displayed as July 31 August 4 or it may be displayed as Jul 31 Aug 4 For further information see 1 132 DTLloadbbl 9 2 Loading a databib database The databib package always requires the databib bst bibliography style file which is supplied with this bundle You need to use cit
60. Peoplepossadj 153 peoplepossadj 153 Peopleposspronoun 154 peopleposspronoun 153 Peoplepronoun 153 peoplepronoun 153 Peoplesibling 154 peoplesibling 154 person package i 149 155 156 158 Personchild 152 personchild 151 personfullname 150 167 personname 00 T51 Personobjpronoun 152 personobjpronoun 151 Personparent 152 personparent 151 Personpossadj 152 personpossadj 151 Personposspronoun 152 personposspronoun 151 Personpronoun 152 personpronoun 151 Personsibling 152 personsibling 151 pgf package 3 86 99 100 110 112 115 127 pgfmath package i il 2 22 20 R Xremoveallpeople 150 removepeople 150 removeperson 150 S siunitx package 45 substr package 32 T table environment 43 tabular environment 42 43 45 46 48 56 59 64 69 80 textcase package 15 textcomp package 6 thebibliography environment TE 144 thepeople 00 150 tikz package 86 97 tikzpicture environment cadera r 97 99 107 topr ule iil 99 raed 47 V verbatim environment 49 168
61. Pie Chart This example modifies example 19 It redefines DTLpieatendtikz to add an annotated arrow begin figure htbp centering Nrenewcommand DTLpieatendtikz Xdraw lt 45 1 5cm 40 2 5cm node right Apples DTLpiechart variable quantity fruit name Name quantity Quantity caption An annotated pie chart end figure This produces Figure 6 10 Note that the centre of the pie chart is the origin of the TikZ picture Apples Figure 6 10 An annotated pie chart 98 DTLplot 7 Scatter and Line Plots dataplot package The dataplot package provides commands for creating scatter or line plots from databases It uses the pgf TikZ plot handler library to create the plots See the pgf manual for more detail on pgf streams and plot handles The dataplot package is not loaded by datatool so if you want to use it you need to load it explicitly using usepackage dataplot DTLplot condition db list settings This command creates a plot inside a tikzpicture environment of all the data given in the databases listed in db list which should be a comma separated list of database names The optional argument condition is the same as that for DTLforeach The settings argument is a comma separated list of setting value pairs There are two settings that must be specified x and y The other settings are optional Note that any value that contains a comma must be enc
62. Roger Brady 58 Clare Verdon 45 Average Score 56 67 This command sums all the entries over all the databases listed in the comma separated list of database names db list for each key in key list where the condition given by condition is true The second optional 69 argument assign list is the same as the assignment list used by DTLforeach so that you can use the information in condition The result is stored in cmd which must be a control sequence For example DTLsumforkeys scores Score total sets total to the sum of all the scores in the database called scores DTLsumcolumn DTLsumcolumn db key cmd This is a faster version of DTLsumforkeys that only sums the entries in a single column specified by key for a single database specified by db and doesn t provide any filtering The result is stored in cmd which must be a control sequence DTLmeanforkeys DTLmeanforkeys condition assign list db list y key list cmd This command computes the arithmetic mean of all the entries over all the databases listed in db list for all keys in key list where the condition given by condition is true The second optional argument assign list is the same as the assignment list used by DTLforeach so that you can use the information in condition The result is stored in cmd which must be a control sequence For example DTLmeanforkeys scores Score
63. Table 5 1 So using the file products csv as described above DTLloadrawdb mydata products csv is equivalent to DTLnewdb mydata DTLnewrow mydata DTLnewdbentry mydata Product Fruit amp Veg DTLnewdbentry mydata Cost 1 25 DTLnewrow mydata DTLnewdbentry mydata Product Stationary DTLnewdbentry mydata Cost 0 80 EEE NZ Table 5 1 Special character mappings used by DTLloadrawdb note that the backslash retains its active state Character Mapping NS N amp textasciitilde textasciicircum oe Hom ur 1 e 4 gt It may be that there are other characters that require mapping For example the file products csv may instead look like Product Cost Fruit amp Veg 1 25 Stationary 0 80 The pound character is not an internationally standard keyboard character and does not generally achieve the desired effect when used in a I4TEX document It may therefore be necessary to convert this symbol to an appropriate control sequence This can be done using the command DTLrawmap string replacement For example 41 DTLrawmap pounds will replace all occurrences of with pounds Naturally the mappings must be set prior to loading the data with DTLloadrawdb Note that the warning in the previous section about no paragraph breaks in an entry also applies to entries loaded from a database If you do need a paragraph
64. User Manual for datatool bundle version 2 10 Nicola L C Talbot School of Computing Sciences University of East Anglia Norwich Norfolk NR4 7TJ United Kingdom http theoval cmp uea aciuk nlet 2012 07 18 The datatool bundle comes with the following documentation datatool user pdf This document is the main user guide for the datatool bundle datatool pdf Advanced users wishing to know more about the inner workings of all the packages provided in the datatool bundle should read Documented Code for datatool v2 10 INSTALL Installation instructions CHANGES Change log README Package summary The datatool bundle is provided to help perform repetitive commands such as mail merging but since TEX is designed as a typesetting lan guage don t expect this bundle to perform as efficiently as custom database systems or a dedicated mathematical or scripting language This bundle consists of the following packages datatool Main package providing database support Automatically loads datatool base datatool base Provides the main library code for numerical and string functions Automatically loads datatool fp or datatool pgfmath depending on package options databar Package for drawing bar charts Automatically loads datatool datapie Package for drawing pie charts Automatically loads datatool dataplot Package for drawing simple line graphs Automatically loads datatool databib Package for loading a biblio
65. ame surname Surname score Score 77 DTLsavedb DTLsavetexdb surname amp firstname amp score end tabular end table This produces Table 5 24 Table 5 24 Student scores influencing the sort order Surname First Name Score Adams Zoe 52 Brady Roger 58 Brown Andy 42 Brown Jane 75 de la Mere Jos 58 van der Mere Henk 71 Smith Jr John 68 Verdon Clare 45 5 9 Saving a Database to an External File DTLsavedb db name y filename This writes the database called db name to a file called filename The separator and delimiter characters used are as given by DTLsetseparator or DTLsettabseparator and DTLsetdelimiter For example DTLsettabdelimiter DTLsavedb scores scores txt will create a file called scores txt and will save the data in a tab separated format The delimiters will only be used if a given entry contains the separator character DTLsavetexdb db name filename This writes the database called db name to a BIEX file called filename where the database is stored as a combination of DTLnewdb DTLnewrow and DTLnewdbentry commands 5 10 Deleting or Clearing a Database A database can be cleared or deleted when its contents are no longer required DTLcleardb DTLcleardb db name Clears the database given by db name The database is emptied but remains defined DTLdeletedb DTLdeletedb db name Dele
66. an create the required document as follows documentclass article usepackage databib begin document 2as long as I haven t put anything before the month name in the bibliography file e g month 2 apr will sort by 2 03 instead of 03 137 nocite x DTLloadbbl mybib nlct DTLsort Year descending Month descending mybib DTLbibliography value DTLbibrow lt 10 mybib end document 9 4 Changing the bibliography style The style of the bibliography produced using DTLbibliography depends on the style databib package option or can be set using DTLbibliographystyle DTLformatauthor DTLformateditor DTLbibliographystyle style Note that this is not the same as bibliographystyle as the databib package uses its custom databib bst bibliography style file Example usepackage style plain databib This sets the plain bibliography style This is in fact the default style so it need not be specified Available styles are plain abbrv and alpha These are similar to the standard BIBIpX styles of the same name but are by no means identical The most notable difference is that these styles do not sort the bibliography It is up to you to sort the bibliography using DTLsort described in section 5 8 9 4 1 Modifying an existing style This section describes some of the commands which are used to format the bibliography You can choose whichever predefined style best fits you
67. atabase exists or if the row index is valid You will probably get a Missing inserted error if you misspell the database name and a Runaway argument error if you specify a row index that is out of range You can use the commands below to access or edit dtlcurrentrow but they won t change the database Instead once you ve finished editing dtlcurrentrow you need to reconstruct the database token by recombining dtlbeforerow dtlcurrentrowand dtlafterrow using dtlrecombine Alternatively to recombine omitting the current row dtlrecombineomitcurrent delreeonbimeomrzreurrene This removes the current row from the database shifting the row indices in dtlafterrow Note that these recombining commands assume that you haven t altered dtlrownum dtldbname dtlbeforerowand dtlafterrow 84 dt lcurrent row stores the row information using datatool s internal row syntax described in the documented code datatool pdf Don t explicitly modify dtlcurrentrow unless you have a good under standing of the syntax dtlgetentryfromcurrentrow dtlgetentryfromcurrentrow cs col idx Gets the value from dt lcurrent row for the column given by col idx an integer and stores in cs which must be a control sequence dtlreplaceentryincurrentrow dtlreplaceentryincurrentrow new value col idx Replaces the value in dt 1current row for the column given by col idx an i
68. ation to the chart The databar package see chapter 8 can be used to convert a database into a bar chart Colour grey scale options Predefined bar colours can be changed Hooks provided to add extra information to the chart The datapie and databar packages do not support the creation of 3D charts and I have no plans to implement them at any later date The use of 3D charts should be discouraged They may look pretty but the purpose of a chart is to be informative Three dimensional graphics cause distortion which can result in misleading impressions The pgf manual provides a more in depth discussion on the matter The dataplot package see chapter 7 can be used to convert a database into a two dimensional plot using markers and or lines Three dimensional plots are currently not supported The databib package see chapter 9 can be used to convert a BIBIEX database into a datatool database 2 Data Types The datatool base package recognises four data types integers real numbers currency and strings Integers An integer is a sequence of digits optionally groups of three digits may be separated by the number group character The default number group character is a comma but may be changed using DTLsetnumberchars see below Real Numbers A real number is an integer followed by the decimal character followed by one or more digits The decimal character is a full stop by default The number group and decimal cha
69. atool package can be converted into a pie chart using DTLpiechart condition settings list db name values where db name is the name of the database and condition has the same form as the optional argument to DTLforeach described in section 5 4 If condition is false that information is omitted from the construction of the pie chart The argument values is a comma separated list of cmd key pairs the same as that required by the penultimate argument of DTLforeach The settings list is a comma separated list of setting value pairs where setting can be any of the following variable This specifies the control sequence to use that contains the value used to construct the pie chart The control sequence must be one of the control sequences to appear in the assignment list values This setting is required start This is the starting angle of the first segment The value is 0 by default 86 radius This is the radius of the pie chart The default value is 2cm innerratio The distance from the centre of the pie chart to the point where the inner labels are placed is given by this value multiplied by the ratio The default value is 0 5 outerratio The distance from the centre of the pie chart to the point where the outer labels are placed is given by this value multiplied by the ratio The default value is 1 25 cutawayratio The distance from the centre of the pie chart to the point of
70. ature Time T2G headers shortstack Incubation Temperature shortstack Incubation Time shortstack Time to Growth t2g t2g csv 43 dtlstringalign Now display the data in a table begin table htbp caption Time to Growth Data centering DTLdisplaydb t2g end table The result is shown in Table 5 2 Table 5 2 Time to Growth Data Incubation Incubation Time to Temperature Time Growth 40 120 40 40 90 60 35 180 20 55 190 40 Each column in the database has an associated data type which indicates what type of data is in that column This may be one of string integer real number or currency If a column contains more than one type the data type is determined as follows e If the column contains at least one string then the column data type is string e If the column doesn t contain a string but contains at least one currency then the column data type is currency e If the column contains only real numbers and integers the column data type is real number The column data type is integer if the column only contains integers The column data type is updated whenever a new entry is added to the database Note that the column data type is not adjusted when an entry is removed from the database The column alignments used by DTLdisplaydb are given by dtlstringalign The string alignment defaults to 1 left aligned dtlintalign dtlintalign The integer alignment defaults
71. ax 58 edef colalign colalign 1 column contains strings else edef colalign colalign c column contains numerical values E To ensure colalign gets correct expanded when passed to the tabular environment I temporarily define dobegintabular to the code required to start the tabular environment edef dobegintabular noexpand begin tabular colalign This sets dobegintabular to begin tabular 1111 After defining dobegintabular I then need to use it As before I use doamp to put the ampersands between columns Recall that I can set the headers using DTLset header or using the headers key when loading the data from an external file For example DTLsetheaders scores FirstName First Name DTLsetheaders scores Score Score Recall that DTLforeachkeyinrow sets dt 1key to the current key This can be used to filter out columns Alternatively if you know the column index you can test dt1col instead The following code modifies the above example so that it filters out the column whose key is StudentNo begin table htbp cap cen def dtl DT ede dob gde dtl DT DTL g DTL D end end tion Student Scores Filtering Out a Column tering colalign foreachkey theKey theCol theType theHead in scores do Lifeq theKey StudentNo edef colalign colalign 1 f dobegintabular noexpand begin
72. ay He guide and protect them Example 42 Mail Merging Using Appropriate Gender In this example I have a CSV file called students csv containing the following FirstName Surname Gender Parent Address John Smith Jr M Mr and Mrs Smith 1 The Street Newtown Jane Brown F Ms Brown 2 The Avenue Oldtown Andy Brown male Mr Brown and Miss Sepia 3 The Road Newtown ZN oe Adams f Mr and Mrs Adams 5 The Street Newtown Roger Brady m Mrs Brady 6 The Avenue Oldtowm Clare Vernon female Mr Vernon 7 The Close Anytown Suppose I have to write to each student s parents regarding their child I can load the information using DTLloaddb described in section 5 2 I can then iterate through the database and define the student as a person and use the commands defined in the person package to display the correct gender related text I could give each person a unique label based on the row count DTLcurrentindex but since I don t need to reuse the information I can use the default anon label and undefine the person when no longer required Note that in the CSV file the gender label isn t consistent For some students the gender is identified by a single letter m or f and for others the gender is identified by a complete word male or female There s also no regard for case This doesn t matter to newperson as all the identifiers used are listed in nalelabels and femalelabels The following is an example
73. ay be accessed using DTLbibfield DTLbibfield field label where field label may be one of Address Author BookTitle Chapter Edition Editor HowPublished Institution Journal Key Month Note Number Organization Pages Publisher School Series Title Type Volume Year ISBN DOI PubMed Abstract or Url You can determine if a field exists for a given entry using DTLifbibfieldexists DTLifbibfieldexists field label true part false part If the field given by field label exists for the current bibliography entry it does true part otherwise it does false part 143 DTLifbibanyfieldexists DTLifanybibfieldexists field label list true part false part This is similar to DTLifbibfieldexists except that the first argument is a list of field names If one or more of the fields given in field label list exists for the current bibliography item this does true part otherwise it does false part DTLformatbibentry DTLformatbibentry This formats the bibliography entry for the current row It checks for the existence of the command DTLformat entry type where entry type is given by DBIBentrytype These commands are defined by the bibliography style DTLcomputewidestbibentry DTLbibrow DTLcomputewidestbibentry conditions db name bib label cmd This computes the widest bibliography
74. b name assign list text DTLforeach DTL oreachs condition db name assign list text This will iterate through each row of the database called db name applying text to each row of the database where condition is met The argument assign list is a comma separated list of cmd key pairs At the start of each row each command cmd in assign list will be set to the value of the entry given by key These commands may then be used in text Note that this assignment is done globally to ensure that DLTforeach works correctly in a tabular environment Since you may want to use the same set of commands in a later DTLforeach the commands are not checked to determine if they already exist It is therefore important that you check you are not using an existing command whose value should not be changed The optional argument condition is a condition in the form allowed by ifthenelse This includes the commands provided by the ifthen package such as not and or as well as the commands described in section 2 2 The default value of condition is ooolean true The starred version ADTLforeachx is a read only version If you want to modify the database using any of the commands described in section 5 6 you must use the unstarred version The starred version is faster 48 DTLenvforeach DTLenvforeachx As is generally the case with command arguments verbatim for ex a
75. be numerical either integers real numbers or currency The currency symbol is ignored when determining equality For example DTLifnumclosedbetween 5 4 5 7 inside outside produces inside Note that the closed range includes end points DTLifnumclosedbetween 5 5 7 inside outside produces inside DTLifstringclosedbetween DTLifstringclosedbetween string min max true part false part DTLifstringclosedbetween DTLifstringclosedbetweens string min max true part false part This determines if string is between min and max in the alphabetical sense or is equal to either min or max The starred version ignores the case the unstarred version is case sensitive 12 DTLifclosedbetween DTLifclosedbetween arg min max true part false part NDTLifclosedbetweenx DTLifclosedbetweens arg min max true part y false part If arg min and max are numerical then this is equivalent to DTLifnumclosedbetween otherwise it is equivalent to DTLifstringclosedbetween when using DTLifclosedbetween or NDTLifstringclosedbetweenx when using NDTLifclosedbetween DTLifnumopenbetween DTLifnumopenbetween num min max true part false part If min num max then do true part otherwise do false part Note t
76. break use DTLpar instead of par but re member that each row of data in an external data file must not have a line break 5 3 Displaying the Contents of a Database Once you have created a database either loading it from an external file as described in section 5 2 or using the commands described in section 5 1 you can display the entire database in a tabular or longtable environment DTLdisplaydb DTLdisplaydb omit list db This displays the database given by db in a tabular environment The first row displays the headers for the database in bold the subsequent rows display the values for each key in each row of the database The optional argument omit list is a comma separated list of column keys to omit All columns displayed by default DTLdisplaylongdb DTLdisplaylongdb options db This is like DTLdisplaydb except that it uses the longtable environment instead of the tabular environment Note that if you use this command you must load the longtable package as it is not loaded by datatool The optional argument options is a comma separated list of key value pairs The following keys are available caption The caption for the longtable contcaption The continuation caption shortcaption The caption to be used in the list of figures when it is loaded into the IATpX database it does not modify the data file label The label for this table omit Comma separated list of column
77. bs package you can redefine the above three commands to use toprule midrule and bottomrule renewcommand dtldisplaystarttab toprule renewcommand dtldisplayafterhead midrule renewcommand dtldisplayendtab bottomrule Example 2 Balance Sheet Suppose you have a file called balance csv that contains the following Description In Out Balance Travel expenses 230 230 Conference fees 400 630 Grant 700 70 Train fare 70 0 The data can be loaded using DTLloaddb headers Description In pounds Out pounds Balance pounds balance balance csv Suppose I want negative numbers to be displayed in red I can do this by redefining dtlrealformat to check if the entry is negative For example begin table htbp caption Balance Sheet renewcommands Ndtlrealformat 1 DTLif1lt 1 0 color red 1 centering DTLdisplaydb balance end table This produces Table 5 3 47 Table 5 3 Balance Sheet Description In Out Balance Travel expenses 230 00 230 00 Conference fees 400 00 630 00 Grant 700 00 70 00 Train Fare 70 00 0 00 5 4 Iterating Through a Database Once you have created a database either loading it from an external file as described in section 5 2 or using the commands described in section 5 1 you can then iterate through each row of the database and access elements in that row DTLforeach DTLforeach condition d
78. ch I keep in the directory SHOME texmf bibtex bib I could look through this file work out the labels for all the publications whose year field is greater or equal to 2000 and create a file with a nocite command containing all those labels in a comma separated list in reverse chronological order but I really can t be bothered to do that Instead I can create the following document documentclass article usepackage databib begin document nocite DTLloadbbl mybib nlct DTLsort Year descending Month descending mybib DTLbibliography DTLbibfieldisge Year 2000 mybib end document Suppose I save this file as mypubs tex then I need to do latex mypubs bibtex mypubs latex mypubs Notes 1 nocite x is used to add all the citations in the bibliography file nlct bib in this case to the databib database 2 NDTLloadbbl mybib n1ct does the following a writes the line bibstyle databib to the auxiliary file This tells BIBIEX to use databib bst which is supplied with this package You therefore shouldn t use bibliographystyle b writes the line bibdata nlct 136 to the auxiliary file This tells BIBTEX that the bibliography data is stored in the file nlct bib Since I have placed this file in TEX s search path BIBTEX will be able to find it C creates a datatool database called mybib d if the bb1 file mypubs bb1 in this example exists it loads this file whi
79. ch adds the bibliography data to the database otherwise it does nothing further In my BIBIgX database nlct bib in this example I have remembered to use the BIBIEX month macros jan feb etc This means that the months are stored in the database in the form DTLmonthname nn where nn is a two digit number from 01 to 12 DTLsort ignores command names when it compares strings which means I can not only sort by year but also by month Once Ihave loaded and sorted my database I can then display it using DTLbibliography This uses the style given by the databib style databib package option or the DTLbibliographystyle command both of which are described in section 9 4 have filtered the bibliography using the optional argument DTLbibfieldisge Year 2000 which checks if the year field of the current entry is greater than or equal to 2000 Note that if an entry has no year field the condition evaluates to false and the entry will be omitted from the bibliography If the bibliography database is large sorting and creating the bibliography may take a while Using databib is much slower than using a standard BIBTEX style file Example 35 Creating a list of my 10 most recent publications Suppose now my boss has asked me to produce a list of my ten most recent publications in reverse chronological order As in the previous example I have a file called n1ct bib which contains all my publications I c
80. ct However these fields are ignored by the three predefined databib styles plain abbrv and alpha If you want these fields to be displayed in the bibliography you will need to modify the bibliography style see subsection 9 4 1 133 DTLbibliography 9 3 Displaying a databib database A databib database which has been loaded using DTLloadbb1 described in section 9 2 can be displayed using DTLbibliography conditions 1 db name where db name is the name of the database Within the optional argument condition you may use any of the commands that may be used within the optional argument of DTLforeach In addition you may use the following commands DTLbibfieldexists DTLbibfieldiseq DTLbibfieldexists field label This tests whether the field with the given label exists for the current entry The field label may be one of Address Author BookTitle Chapter Edition Editor HowPublished Institution Journal Key Month Note Number Organization Pages Publisher School Series Title Type Volume Year ISBN DOI PubMed Abstract Url or Eprints For example suppose you have loaded a databib database called mybib using DTLloadbb1 described in section 9 2 then the following bibliography will only include those entries which have a Year field DTLbibliography DTLbibfieldexists Year mybib DTLbibfieldiseq1 field label value y This tests whether the val
81. cutaway segments is given by this value multiplied by the ratio The default value is 0 2 inneroffset This is the absolute distance from the centre of the pie chart to the point where the inner labels are placed You should use only one or other of innerratio and inneroffset not both If you also want to specify the radius you must use ratio before inneroffset If omitted the inner offset is obtained from the ratio multiplied by the innerratio value outeroffset This is the absolute distance from the centre of the pie chart to the point where the outer labels are placed You should use only one or other of outerratio and outeroffset not both If you also want to specify the radius you must use ratio before outeroffset If omitted the outer offset is obtained from the ratio multiplied by the outerratio value cutawayoffset This is the absolute distance from the centre of the pie chart to the point of the cutaway segments You should use only one or other of cutawayratio and cutawayoffset not both If you also want to specify the radius you must use ratio before cutawayoffset If omitted the cutaway offset is obtained from the ratio multiplied by the cutawayratio value cutaway This is a list of cutaway segments This should be a comma separated list of individual numbers or number ranges separated by a dash For example cutaway 1 3 will separate the first and third segments from the rest of the pie chart offset by the value of t
82. d to be empty DTLifdbempty mydata empty not empty This now produces not empty The row count is given by DTLrowcount mydata which produces 1 The column count is given by DTLcolumncount mydata which produces 0 DTLnewdbent ry db name key value Y This creates a new entry with the identifier key whose value is value and adds it to the last row of the database called db name For example DT DT Lnewdbentry mydata Surname Smith Lnewdbentry mydata FirstName John Adds an entry with identifier Surname and value Smith to the last row of the database named mydata and then adds an entry with identifier FirstName and value John Note that the key should not contain any fragile commands It is generally best to only use non active characters in the key The value isn t expanded by default but you can change this using the declaration dtlexpandnewvalue dtlexpandnewvalue This can be localised by placing it in a group or you can switch back using dt lnoexpandnewvalue dt lnoexpandnewvalue DTLpar Note that database entries can t contain paragraph breaks as many of the macros used by datatool are short commands If you do need a paragraph break in an entry you can instead use the command DTLpar For example DTLnewdbentry mydata Description First paragraph DTLpar Second paragraph DTLaddentryforrow DTLaddentryforrow db assig
83. determine if the database exists or if it contains the given key dtlcolumnindex db name key DTLgetkeydata key db col cs type cs header cs Gets data for given key in database db the column index is stored in col cs as DTLgetcolumnindex the type is stored in type cs as DTLget datatype and the header is stored in header cs DTLget value cs t db r c This gets the value for row given by index r and column given by c for the database db and stores it in cs which must be a command name If you want to get the value by key rather than column index you can use dtlcolumnindex For example the following gets the value for row 3 with key Surname from the database data and stores in myval DTLgetvalue myval data 3 dtlcolumnindex data Surname DTLget Location row cs t column cs y database value Assigns row cs and column cs to the indices of the first entry in database that matches value DTLgetvalueforkey DTLgetvalueforkey cmd key db name ref key ref value This globally sets cmd a control sequence to the value of the key specified by key in the first row of the database called db name which contains the key ref key which has the value value 81 DTLassign DTLassign db name row idx assign list This globally assigns the list of commands i
84. e score Score surname amp firstname amp score end tabular end table This produces Table 5 21 Table 5 21 Student scores sorted by name Surname First Name Score Adams Z e 52 Brady Roger 58 Brown Andy 42 Brown Jane 75 Smith Jr John 68 Verdon Clare 45 75 Now suppose I add two new students to the database DTLnewrow scores DTLnewdbentry scores Surname van der Mere DTLnewdbentry scores FirstName Henk DTLnewdbentry scores Score 71 DTLnewrow scores DTLnewdbentry scores Surname de la Mere DTLnewdbentry scores FirstName Jos DTLnewdbentry scores Score 58 and again I try sorting the database and displaying the contents as a table begin table htbp caption Student scores case sensitive sort centering DTLsort Surname FirstName scores begin tabular llr bfseries Surname amp bfseries First Name amp bfseries Score DTLforeach scores firstname FirstName surname Surname score Score surname amp firstname amp score end tabular end table This produces Table 5 22 Notice that the surnames aren t correctly ordered This is because a case sensitive sort was used Changing DTLsort to DTLsort in the above code produces Table 5 23 Table 5 22 Student scores case sensitive sort Surname First Name Score Adams Zoe 52 Brady Roger 58 Brown Andy 42 Brown Jane 75
85. e 3 and uses DTLmeanforkeys to determine the average score A letter is then 72 DTLsort DTLsort created for each student to inform them of their score and the class average documentclass letter usepackage datatool begin document load database DTLloaddb scores studentscores csv compute arithmetic mean for key Score DTLmeanforkeys scores Score average Round the average to 2 decimal places DTLround average average 2 Save the highest score in maxscore DTLmaxforkeys scores Score maxscore DTLforeach scores firstname FirstName surname Surname score Score begin letter opening Dear firstname surname DTLifnumgt score 60 Congratulations you You achieved a score of score which was DTLifnumgt score average above below the average of average DTLifnumeg score maxscore You achieved the highest score The top score was maxscore closing Yours Sincerely end letter end document To determine a person s gender when mail merging see chapter 10 5 8 Sorting a Database DTLsort replacement key list sort criteria db name DTLsort x replacement key list sort criteria db name This will sort the database called db name according to the criteria given by sort criteria which must be a comma separated list of keys and 73 optionally order where
86. e are frequently simply copied and a search and replace edit is used to change the relevant text However this can lead to errors especially if the previous person s name was Mary With the person package you need only change the definition of the person by modifying the arguments of newperson 10 1 Defining and Undefining People A person is defined globally using the command newperson label t full name familiar name gender The optional argument is a unique label identifying this person in the event that there is more than one person If label is omitted anon is used This is also the case for subsequent commands that take an optional label The gender may be any of those given by malelabels femalelabels The default definition of malelabels ismale Male MALE M mand the default definition of femalelabels is female Female FEMALE E f You can add extra identifiers using 149 addmalelabel addfemalelabel thepeople removeperson removeallpeopl removepeople personfullname addmalelabel identifier o r addfemalelabel identifier addmalelabel boy addfemalelabel girl The total number of defined people is given by thepeople gt yo oO H D ei 5 Q 5 en D E 5 Q eg B c a c 2 2 ay removeperson label where the person is given by label y jura 3 o 3 oO 5 Di 3 o 5 oO
87. e data in the first place Thanks to Morten Hegholm for the suggestion Some advanced commands for accessing database information are described in section 5 11 but using TEX is nowhere near as efficient as say using a SOL database so don t expect too much from this package 5 1 Creating a New Database DTLnewdb db name This command creates a new empty database called db name You can test if a database is empty using DTLifdbempty db name true part false part If the database called db name is empty do true part otherwise do false part DTLrowcount DTLcolumncount DTLnewrow DTLnewdbentry DTLrowcount db name This command displays the number of rows in the database called db name DTLcolumncount db name This command displays the number of columns or keys in the database called db name DTLnewrow db name This command starts a new row in the database called db name This new row becomes the current row when adding new entries For example the following creates an empty database called mydata DTLnewdb mydata The following tests if the database is empty DTLifdbempty mydata empty not empty This produces empty The following adds an empty row to the database this is the first row of the database DTLnewrow mydata Note that even though the only row in the database is currently empty the database is no longer considere
88. e or nocite as usual If you want to add all entries in the bib file to the datatool database you can use nocite DTLloadbb1 bbl name db name y bib list This command performs several functions 1 it writes the following line in the auxiliary file bibstyle databib which tells BIBTEX to use the databib bst BIBIEX style file 2 it writes bibdata bib list to the auxiliary file which tells BIBTEX which bib files to use 3 it creates a datatool database called db name 4 it loads the file bbl name if it exists The value defaults to jobname bb1 which is the usual name for a bb1 file If the bb1 file doesn t exist the database db name will remain empty You then need to run your document through I4TEX or PDFETEX and then run BIBTEX on the auxiliary file as described in section 9 1 This will create a bb1 file which contains all the commands required to add the bibliography information to the datatool database called db name The next time you BIEX your document this file will be read and the information will be added to db name Note that DTLloadbbl doesn t generate any text Once you have loaded the data you can display the bibliography uses DTLbibliography described below or you can iterate through it using DTLforeachbibentry described in section 9 5 Note that the dat abib bst BIBIEX style file provides the following additional fields isbn doi pubmed url and abstra
89. en DTLafterinitialbeforehyphen This indicates what to do between an initial and a hyphen This simply does a full stop by default For example Nrenewcommand DTLafterinitialbeforehyphen DTLinitials Marie E lise del Rosario produces M E d R whereas renewcommands DTLafterinitialbeforehyphen renewcommand DTLafterinitials Nrenewcommand DTLbetweeninitials renewcommands DTLinitialhyphen DTLinitials Marie E lise del Rosario produces MEdR DTLnewdb DTLifdbempty 5 Databases The datatool package provides a means of creating and loading databases Once a database has been created or loaded it is possible to iterate through each row of data to make it easier to perform repetitive actions such as mail merging Whilst TEX is an excellent typesetting language it is not designed as a database management system and attempting to use it as such is like trying to fasten a screw with a knife instead of a screwdriver it can be done but requires great care and is more time consuming Version 2 0 of the datatool package uses a completely different method of storing the data to previous versions As a result the code is much more efficient however large databases and complex operations will still slow the time taken to process your document Therefore if you can it is better to do the complex operations using whatever system created th
90. ent DTLdocurrentpiesegmentcolor DTLdocurrentpiesegmentcolor This sets the current text colour to that of the current pie segment This command may only be used within a pie chart or within the body of DTLforeach DTLpieoutlinecolor DTLpiesutlinecoler al This sets the outline colour for the pie chart The default is black DTLpieoutlinewidth DTLpieout linewidth This is a length that governs the line width of the outline The default value is Opt but can be changed using set length The outline is only drawn if DTLpieoutlinewidth is greater than Opt Example 23 Pie Segment Colours This example extends example 22 It sets the outline thickness to 2pt and the outer label is now set in the same colour as the fill colour of the segment to which it belongs The third segment lemons and limes is set to yellow and the fourth segment peaches is set to pink In addition a legend is created using DTLforeach begin figure htbp centering setlength DTLpieout linewidth 2pt DTLsetpiesegmentcolor 3 yellow DTLsetpiesegmentcolor 4 pink renewcommands DTLdisplayinnerlabel l renewcommands DTLdisplayouterlabel DTLdocurrentpiesegmentcolor textsf shortstack 1 DTLpiechart variable quantity nnerlabel DTLpiepercent uterlabel name DTLpievariable fruit name Name quantity Quantity begin tabular b 11 D D textsf 1
91. erlabel 1name cutaway 1 3 fruit 90 name Name quantity Quantity caption A pie chart with cutaway segments end figure This produces Figure 6 4 Pears g 2 Apples Lemons Limes Cherries Peaches Figure 6 4 A pie chart with cutaway segments Alternatively I can specify a range of segments The following separates the first two segments begin figure htbp centering DTLpiechart variable quantity outerlabel name cutaway 1 2 fruit name Name quantity Quantity caption A pie chart with cutaway segments texttt cutaway 1 2 end figure This produces Figure 6 5 Notice the difference between Figure 6 5 and Figure 6 6 which was produced using begin figure htbp centering DTLpiechart variable quantity outerlabel name cutaway 1 2 fruit name Name quantity Quantity caption A pie chart with cutaway segments texttt cutaway 1 2 end figure 91 Pears Apples Lemons Limes Cherries Peaches Figure 6 5 A pie chart with cutaway segments cut away 1 2 Pears Apples Lemons Limes Cherries Peaches Figure 6 6 A pie chart with cutaway segments cutaway 1 2 6 1 Pie Chart Variables DTLpievariable DTLpievariable This command is set to the variable given by the variable setting in the settings list argument of DTLpiechart The innerlabel is set to DTLpievariable by default DTLpiepercent
92. ertical axis when plotting a vertical bar chart and to the horizontal axis when plotting a horizontal bar chart The y axis uses the same co ordinates as the data The bars may have an upper and lower label In a vertical bar chart the lower label is placed below the x axis and the upper label is placed above the top of the bar In a horizontal bar chart the lower label is placed to the left of the x axis and the upper label is placed to the right of the end of the bar This is actually a misnomer as it is possible for the upper label to be below the lower label if a bar has a negative value however the bars are considered to be anchored on the x axis and the other end of the bar is considered to be the upper end regardless of its direction The databar package options are as follows color databar Created coloured bar charts default gray databar Created grey scale bar charts vertical databar Created vertical bar charts default horizontal databar Created horizontal bar charts DTLbarchart condition db name settings values DTLmultibarchart condition db name settings values These commands both create a bar chart from the information in the database db name where condition is the same as the optional 115 argument for DTLforeach described in section 5 4 and values is the same as the penultimate argument of DTLforeach The settings argument is a settin
93. esn t provide any filtering The result is stored in cmd which must be a control sequence DTLmaxforkeys DTLmaxforkeys condition assign list db list key list cmd This command determines the maximum value over all entries for all keys in key list over all the databases listed in db list where condition is true The second optional argument assign list is the same as the assignment list used by DTLforeach so that you can use the information in condition The result is stored in cmd which must be a control sequence For example DTLminforkeys scores Score theMax sets theMax to the minimum score in the database DTLmaxforcolumn DTLmaxforcolumn db key cmd This is a faster version of DTLmaxforkeys that only computes the maximum for a single column specified by key for a single database specified by db and doesn t provide any filtering The result is stored in cmd which must be a control sequence DTLcomputebounds DTLcomputebounds db list x key t y key minX cmd minY cmd y maxX cmd maxY cmd Computes the maximum and minimum x and y values over all the databases listed in db list where the x value is given by x key and the y value is given by y key The results are stored in minX cmd minY cmd maxX cmd and maxY cmd Example 15 Mail Merging This example uses the database given in exampl
94. etting is set to both or y this value will automatically be set to t rue otherwise it will be set to false 100 xminortics This setting governs whether or not to display the x minor tick marks It is a boolean setting taking only the values t rue and false If no value is specified true is assumed This setting also sets the x major tick marks on if the value is true yminortics This setting governs whether or not to display the y minor tick marks It is a boolean setting taking only the values true and false If no value is specified t rue is assumed This setting also sets the y major tick marks on if the value is t rue xticdir This sets the x tick direction and may only take the values in or OUL yticdir This sets the y tick direction and may only take the values in or OLE ticdir This sets the x and y tick direction and may only take the values inorout bounds The value must be in the form min x min y max x max y This sets the graph bounds to the given values If omitted the bounds are computed from the maximum and minimum values of the data For example DTLplot datal data2 x Height y Weight bounds 0 0 10 20 Note that the bounds setting overrides the minx maxx miny and maxy settings minx The value is the minimum value of the x axis miny The value is the minimum value of the y axis maxx The value is the maximum value of the x axis maxy The value is the maximum value of the y axis xticp
95. ewrow mydata DTLnewdbentry mydata FirstName Z oe DTLnewdbentry mydata Score 52 DTLnewdbentry mydata Surname Adams e Sy at NE d AP ANC AID GE ai Ge EE aM cd Note that the entry Smith Jr had to be delimited in mydata csv using the double quote character since it contained a comma which is used as the separator The percent symbol can be used as a comment character within the file The file used in the above example contained a IATEX command namely V When using DTLloaddb all the special characters that appear in the command retain their IAIEX meaning when the file is loaded It is likely however that the data file may have been created by another application that is not TEX aware such as a spreadsheet application For example suppose you have a file called say products csv which looks like Product Cost Fruit amp Veg 1 25 Stationary 0 80 This file contains two of TEX s special characters namely amp and In this case if you try to load the file using DTLloaddb you will encounter errors Instead you can use DTLloadrawdb options db name filename This is the same as DTLloaddb except that it maps nine of the ten special characters onto commands which produce that symbol The only character that retains its active state is the backslash character so you will 40 DTLrawmap still need to check the file for backslash characters The mappings used are listed in
96. ex mydoc Now that the bb1 file exists the bibliography can be input into the document The internal cross referencing information for the bibliography can now be written to the auxiliary file 4 latex mydoc The cross referencing information can be read from the auxiliary file 9 1 1 BIBTEX database The bibliographic data required by BIBIEX must be stored in a file with the extension bib where each entry is stored in the form e entry type cite key field name value field name value Note that curly braces and may be used instead of and The entry type given by entry type above indicates the type of document This may be one of article book booklet inbook incollection i nproceedings manual mastersthesis misc phdthesis proceedings techreport or unpublished INote that conference isa synonym for inproceedings 130 The cite_key above is a unique label identifying this entry and is the label used in the argument of cite or nocite The available fields depends on the entry type for example the field journal is required for the article entry type but is ignored for the inproceedings entry type The standard fields are address author booktitle chapter edition editor howpublished institution journal key month note number organization pages publisher school series title type volume and year Author and editor names must be entered in one of the
97. g value list of settings The first command DLTbarchart will draw a bar chart for a given column of data in the database whereas the second command DTLmultibarchart will draw a bar chart that is divided into groups of bars where each bar within a group represents data from several columns of a given row in the database The variable setting is required for DTLbarchart and the variables the other settings are optional though some may only be used for one of DTLbarchart and DLTmultibarchart and are as follows variable This specifies the control sequence to use that contains the value used to construct the bar chart The control sequence must be one of the control sequences to appear in the assignment list values This setting is required for DTLbarchart and is unavailable for DTLmultibarchart variables This specifies a list of control sequences to use which contain the values used to construct the bar chart Each control sequence must be one of the control sequences to appear in the assignment list values This setting is required for DTLmultibarchart and is unavailable for DTLbarchart max This specifies the maximum value on the y axis This should be a standard decimal value length This specifies the overall length of the y axis and must be a dimension maxdepth This must be a zero or negative number It specifies the maximum depth of the y axis This should be a standard decimal value axes This setti
98. g Num DTLforeach emailDB firstname FirstName surname Surname emaill Emaill emailII Email2 regnum RegNum firstname amp surname amp emailI amp emailII regnum end tabular This produces the following First Name Surname Email 1 Email 2 Reg Num Mary Jones mj my uni ac uk mj somewhere com 0 Adam Smith as my uni ac uk NULL 12345 Note that on the first row of data the registration number appears as 0 while on the next row the second email address appears as NULL The datatool package has identified the key RegNum for this database as a numerical key since all elements in the database with that key are numerical whereas it has identified the key Email2 as a string since there is at least one element in this database with that key that is a string Null numerical values are set to DTLnumbernull 0 and null strings are set to DTLstringnull NULL The following code checks each value to determine whether it is null using DTLifnull If it is the text Missing is inserted otherwise the value itself is used begin tabular 11111 bfseries First Name amp bfseries Surname amp bfseries Email 1 amp bfseries Email 2 amp bfseries Reg Num DTLforeach emailDB firstname FirstName surname Surname mailI Emaill emailII Email2 regnum RegNum DTLifnull firstname emph Missing firstname amp ifnull surname emph Missing surname amp i fnull
99. ge that does not have a wrapper function in datatool then you will need to convert the value using DTLconverttodecimal and convert it back using either DTLdecimaltolocale or DTLdecimaltocurrency Example 14 Arithmetical Computations In this example I am going to produce a table similar to Table 5 4 except that I want to add an extra row at the end which contains the average score begin table htbp caption Student scores label tab mean centering def total 0 begin tabular llr bfseries First Name amp bfseries Surname amp 9 bfseries Score 68 DTLsumforkeys DTLforeach scores firstname FirstName surname Surname score Score firstname surname E DTLgadd total score total score IAN multicolumn 2 l bfseries Average Score amp DTLsavelastrowcount n DTLdiv average total n DTLround average average 2 average end tabular end table This produces Table 5 19 Notes e J had to use DTLgadd rather than DTLadd since it occurs within a tabular environment which puts each entry in a local scope e used DTLsavelastrowcount to store the number of rows produced by DTLforeach in the control sequence n e used DTLround to round the average score to 2 decimal places Table 5 19 Student scores First Name Surname Score John Smith Jr 68 Jane Brown 75 Andy Brown 42 Z e Adams 52
100. gholm for suggesting a much more efficient way of storing the information in databases which has significantly improved the time it takes to TEX documents containing large databases 161 Index A addfemalelabel 150 addmalelabel 150 B booktabs package 47 bottomrule oo 47 C colortbl package 55 counters DTLbarroundvar 118 DTEDIDEOW sitiado 144 DTLmaxauthors 140 DTLmaxeditors 140 DTLpieroundvar 25 DTLplotroundXvar 109 DTLplotroundYvar 109 DILSOWL 233 2 3 40 a 50 DIL OW l eane a berg 50 DIL OWLIl icu Rea 50 D databar package 12 3 115 databib package i 2 3 129 133 134 136 139 143 datapie package i 2 3 86 94 dataplot package 12 3 99 datatool package i 2 3 24 25 27 32 35 37 42 51 64 68 85 86 99 107 115 129 133 137 146 datatool base package i 2 4 5 22 23 datatool fp package 12 3 datatool pgfmath package i2 9 DBIBcitekey 143 DBIBentrytype 143 DTLabS ni Et 26 NDTLadd 2a sea 23 69 XDTLaddall 3522 x v5 24 DTLaddentryforrow 37 DTLaddtoplotlegend 107 D 162 dtlaftercols iix ao 45 DTLafterinitialbeforehyphen aU CP DOTT 34 DTLafterinitials 34 dtla fterrowW
101. gin figure htbp centering renewcommands DTLdisplayinnerlabel 1 textsf 1 renewcommands DTLdisplayouterlabel 1 textsf 1 DTLpiechart variable quantity innerlabel DTLpiepercent outerlabel name DTLpievariable fruit name Name quantity Quantity caption A pie chart changing the label format end figure This produces Figure 6 8 6 3 Pie Chart Colours The datapie package predefines colours for the first eight segments of the pie chart If you require more than eight segments or if you want to change the default colours you will need to use 94 Pears 25 Apples 30 Lemons Limes 40 5 Cherries 20 Peaches 34 5 Figure 6 8 A pie chart changing the label format DTLsetpiesegmentcolor DTLsetpiesegmentcolor n t color The first argument n is the segment index starting from 1 and the second argument color is a colour specifier as used in commands such as color It is a good idea to set the colours so that each segment colour is somehow relevant to whatever the segment represents For example in the previous examples of pie charts depicting fruit some of default colours were inappropriate Whilst red is appropriate for apples and green is appropriate for pears blue doesn t really correspond to lemons or limes DTLdopiesegmentcolor DTLdopiesegmentcolor n This sets the current text colour to that of the n th segm
102. graphy Suppose I don t have much space in my document and I need to produce a compact bibliography Firstly I can use the bibliography style abbrv either through the package option usepackage style abbrv databib or using DTLbibliographystyle abbrv Once I have set the style I can further modify it thus renewcommands Nandname N amp Nrenewcommand editorname ed renewcommand editorsname eds Nrenewcommand pagesname pp renewcommand pagename p Nrenewcommand volumename vol renewcommands numbername no renewcommands editionname ed Nrenewcommand techreportname T R renewcommands mscthesisname MSc thesis Now I can load and display the bibliography create a database called mybib from the information given in mybibl bib and mybib2 bib DTLloadbbl mybib mybibl mybib2 display the bibliography DTLbibliography mybib Example 37 Highlighting a given author Suppose my boss wants me to produce a list of allmy publications which I have stored in the file n1ct bib as in example 34 Most of my publications have multiple co authors but suppose my boss would like me to highlight my name so that when he skims through the document he can easily see my name in the list of co authors I can do this by 6T can load the bibliography earlier but obviously the bibliography should only be dis played after the bibliog
103. graphy into a database Automatically loads datatool person Package for referencing people by the appropriate gender pronouns Automatically loads datatool In addition there are two mutually exclusive packages datatool fp and datatool pgfmath that provide mathematical related commands that are just wrapper functions for fp or pgfmath commands These can be loaded individually without loading datatool For example the following documents produce the same results but the first uses the fp package and the second uses the pgfmath package 1 Using fp macros documentclass article usepackage datatool fp begin document 1 2 dtlifnumeg 1 2 true false end document 2 Using pgfmath macros documentclass article usepackage datatool pgfmath begin document 1 2 dtlifnumeg 1 2 true false end document ii Contents 1 Introduction Data Types 21 ele corzos Sod ei E Kane ea are Ar 22 ithenconditi nalS sesa sci uw o x9 un wee e s Fixed Point Arithmetic Strings Databases 51 Creating a New Database 1 xo EE E E EE 5 2 Loading a Database from an External ASCII File 5 3 Displaying the Contents of a Database 54 Iterating Through a Database 22 0644 seed ce es 5 9 ul Vales ue 4 00 RR nn CLERC Een a 56 Editing Database Rows 4 644 65 6 bance men 5 7 Arithmetical Computations on Database Entries 558 Sorting a Database 2 22999 3 rare 59 Saving a Database to a
104. h 3in height 3in legend legendlabels Group A Group B xlabel Height m ylabel Weight kg box xticpoints 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 caption A scatter plot end figure This produces Figure 7 4 105 74 90 71 44 67 98 64 52 61 06 57 60 54 14 50 68 47 22 43 76 40 30 sel 1 54 1 55 1 56 1 56 1 57 1 58 1 59 1 60 1 60 1 61 1 62 Figure 7 3 A scatter plot 74 90 t I T 7144 o Group A x Group B 67 98 64 52 IT x Weight kg 54 14 61 06 o 57 60 5 E O 50 68 o 47 22 43 76 40 30 RA 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 Height m Figure 7 4 A scatter plot 106 1 62 7 1 Adding Information to the Plot The datatool package provides two hooks used at the beginning and end of the tikzpicture environment DTLplotatbegintikz DTLplotatbegintikz and DTLplotatendtikz DTLplotatendtikz They are both defined to do nothing by default but can be redefined to add commands to the image The unit vectors are set prior to using these hooks so you can use the same co ordinates as those in the data sets DTLaddtoplotlegend DTLaddtoplot legend marker line style text This adds a new row to the plot legend where marker is code to produce the marker line style is code to set the line style and text is a textual label You can use relax to suppress the marker o
105. hapter 4 so if you want to change the way the initials are displayed e g put a space between them you will need to redefine the commands used by DTLstoreinitials such as DTLbetweeninitials DTLformatsurname surname This displays its argument by default DTL ormat von von part If the von part is empty this command does nothing otherwise it displays its argument followed by a non breakable space It also checks whether forenames ends with a full stop using DTLcheckendsperiod to prevent a sentence ending full stop from following an abbreviation full stop It also checks whether the surname ends with a full stop using DTLcheckendsperiod 139 DTLmaxauthors DTLmaxeditors D DTLandlast TLandnotlast DTLtwoand TLendbibitem DTLformat jr jr part If the jr part is empty this command displays nothing otherwise it displays a comma followed by its argument For example suppose you want the author s surname to appear first in small capitals followed by a comma and the forenames This can be achieved by redefining DTLformatauthor as follows Nrenewcommand DTLformatauthor 4 textsc DTLformatvon 1 DTLformatsurname 2 DTLformatjr 3 DTLformatforenames 4 DTLmaxauthors The counter DTLmaxauthors is used to determine the maximum number of authors to display for a given entry If the entry s author list contains more than that
106. hat num min and max must be numerical either integers real numbers or currency Again the currency symbol is ignored when determining equality For example DTLifnumopenbetween 5 4 5 7 inside outside produces inside Note that end points are not included For example DTLifnumopenbetween 5 5 7 inside outside produces outside DTLifstringopenbetween DTLifstringopenbetween string min max true part false part DTLifstringopenbetweenx DTLifstringopenbetween string min max y true part false part This determines if string is between min and max in the alphabetical sense The starred version ignores the case the unstarred version is case sensitive 13 DTLifopenbetween DTLifopenbetween DTLifFPclosedbet DTLifFPopenbetwe DTLifAllUpperCas DTLifopenbetween arg min max true part false part DTLifopenbetweens arg min max true part y false part If arg min and max are numerical then this is equivalent to DTLifnumopenbetween otherwise it is equivalent to DTLifstringopenbetween when using DTLifopenbetween or DTLifstringopenbet ween when using DTLifopenbetween ween DTLifFPclosedbetween num min max true part false part If min lt num lt max then do true part otherwise do false part where
107. he cutawayoffset setting whereas cut away 1 3 will separate the first three segments from the rest of the pie chart If omitted the pie chart will be whole innerlabel The value of this is positioned in the middle of each segment at a distance of inneroffset from the centre of the pie chart The default is the same as the value of variable 87 outerlabel The value of this is positioned at a distance of outeroffset from the centre of the pie chart The default is empty rotateinner This is a boolean setting so it can only take the values t rue and false If the value is omitted t rue is assumed If true the inner labels are rotated along the spokes of the pie chart otherwise the inner labels are not rotated There are analogous package options rotateinner datapie and norotateinner datapie rotateouter This is a boolean setting so it can only take the values t rue and false If the value is omitted t rue is assumed If true the outer labels are rotated along the spokes of the pie chart otherwise the outer labels are not rotated There are analogous package options rotateouter datapie and norotateouter datapie Example 19 A Pie Chart This example loads data from a file called fruit csv which contains the following Name Quantity Apples 30 Pears 25 Lemons Limes 40 5 Peaches 34 5 Cherries 20 First load the data DTLloaddb fruit fruit csv Now create a pie chart in a figure begin figure h
108. idth 1pt Round the y tick labels to integers setcounter DTLbarroundvar 0 Adjust the tick label offset setlength DTLticklabeloffset 20pt Change the y tick label alignment renewcommands DTLbarYticklabelalign left Rotate the y tick labels t ei E renewcommand DTLbardisplayYticklabel 1 rotatebox 45 1 Set the bar colours depending on the value of theProfit DTLforeach profits theProfit Profit ifthenelse DTLislt theProfit 0 DTLsetbarcolor DTLcurrentindex red DTLsetbarcolor DTLcurrentindex blue Do the bar chart DTLbarchart variable theProfit upperbarlabel theYear ylabel Profit Loss pounds verticalbars false maxdepth 2000 max 4000 profits theProfit Profit theYear Year caption Profits for 2000 2003 end figure This produces Figure 8 3 Notes 1 This example uses rotatebox so the graphics or graphicx package is required 2 The y tick labels are too wide to fit horizontally so they have been rotated to avoid overlapping with their neighbour 3 Rotating the y tick labels puts them too close to the y axis so DTLticklabeloffset is made larger to compensate 4 Remember not to use year as an assignment command as this command already exists 5 Before the bar chart is created I have iterated through the database setting the bar colour to red or blue depending
109. in table htbp caption First Three Rows centering begin tabular llr 2Recall that DTLrowi is incremented after the condition is tested so it will be out by 1 when the condition is tested which is why lt 3 is used instead of lt 4 54 bfseries First Name amp bfseries Surname amp bfseries Score DTLforeach scores firstname FirstName surname Surname score Score ifthenelse DTLcurrentindex 3 dtlbreak firstname amp surname amp score IS end tabular end table This produces Table 5 8 Note that the loop is not broken until the end of the current iteration so even though dt 1break occurs at the start of the third row the loop isn t finished until the third row is completed Recall that DTLcurrent index must be used before the first instance of or amp Alternatively you can use DTLrowi instead DTLforeach scores firstname FirstName surname Surname score Score firstname amp surname amp score ifthenelse value DTLrowi 3 dtlbreak Table 5 8 First Three Rows First Name Surname Score John Smith Jr 68 Jane Brown 75 Andy Brown 42 Example 7 Stripy Tables This example uses the same database as in the previous examples It requires the colortbl package which provides the command rowcolor The command DTLifoddrow is used to produce a striped table begin table htbp caption A stripy table label tab stripy centering
110. in the values argument will be set to a null value This value depends on the data type associated with the given key DTLstringnull This is the null value for a string Drinumbernull This is the null value for a number DTLifnull cmd true part false part This checks if cmd is null where cmd is a command name if it is then true part is done otherwise false part is done This macro is illustrated in example 12 below Example 12 Null Values Consider the following which creates a database called emai 1DB DTLnewdb emailDB DTLnewrow emailDB DTLnewdbentry emailDB Surname Jones DTLnewdbentry emailDB FirstName Mary DTLnewdbentry emailDB Emaill mj my uni ac uk DTLnewdbentry emailDB Email2 mj somewhere com D D D D D TLnewrow emailDB TLnewdbentry emailDB Surname Smith TLnewdbentry emailDB FirstName Adam TLnewdbentry emailDB Emaill as my uni ac uk TLnewdbentry emailDB RegNum 12345 E GE O A OE gee In the above example the first row of the database contains an entry with the key Email2 but the second row doesn t Whereas the second row contains an entry with the key RegNum but the first row doesn t The following code puts the information in a tabular environment begin tabular 11111 bfseries First Name amp bfseries Surname amp bfseries Email 1 amp bfseries Email 2 amp bfseries Re
111. informa tive messages to the console and transcript file to let you know what s going on 9 1 BIBTEX An Overview This document assumes that you have at least some passing familiarity with BIBTEX but here follows a brief refresher BIBTEX is an external application used in conjunction with KIEX When you run BIBTEX you need to specify the name of the document a auxiliary file without the aux extension BIBTEX then reads this file and looks for the commands bibstyle which indicates which bibliography style ost file to load pibdata which indicates which bibliography database bib files to load and citation produced by cite and nocite which indicates which entries should be included in the bibliography BIBIEX then creates a file with the extension bb1 which 129 contains the bibliography formatted according to the layout defined in the bibliography style file In general given a document called say mydoc tex you will have to perform the following steps to ensure that the bibliography and all citations are up to date 1 latex mydoc This writes the citation information to the auxiliary file The bibliography currently doesn t exists so it isn t displayed Citations will appear in the document as since the internal cross references don t exist yet 2 bibtex mydoc This reads the auxiliary file and creates a file with the extension bb1 which typically contains the typeset bibliography 3 lat
112. isint DTLisint text Tests if text is an integer For example ifthenelse DTLisint 153 integer not an integer produces integer DTLislt DTLislt arg1 arg2 This checks if arg1 is less than arg2 As with DTLif1t if arg1 and arg2 are numerical a numerical comparison is used otherwise a case sensitive alphabetical comparison is used Note that there is no starred version of this command but you can instead use DTLisilt to ignore the case DTLisilt DTLisilt arg1 arg2 This checks if arg1 is less than arg2 As with ADTLif1tx if argl and arg2 are numerical a numerical comparison is used otherwise a case insensitive alphabetical comparison is used DTLisgt DTLisgt arg1 arg2 18 This checks if arg1 is greater than arg2 As with DTLifgt if arg1 and arg2 are numerical a numerical comparison is used otherwise a case sensitive alphabetical comparison is used Note that there is no starred version of this command instead use DTLisigt to ignore the case DTLisigt DTLisigt arg1 arg2 This checks if arg1 is greater than arg2 As with DTLifgt x if arg1 and arg2 are numerical a numerical comparison is used otherwise a case insensitive alphabetical comparison is used DTLiseq DTLiseq arg arg2 This checks if arg1 is equal to arg2 As with DTLifeq if arg1 and arg2 are numerical a numerical comparis
113. label The person s relationship to their sibling brother or sister is displayed using personsibling label EN cr 2 oO o 3 aQ o Q CH E 4 wn o et 2 oO u pel t H ai o En o wn oO 5 oO 5 Qo D Set o E z 5 oO oO a o 5 oO o En 5 oO y 8g 265 A ds e 869 EJE 3 E 5 e 2 B y a Z 2 ie gt D O D un gt O D gt o lt O O X e O S 3 T gt O E un d o eg e 77 151 Personpronoun Personpronoun label XPersonobjpronoun Personobjpronoun label Personpossadj Personpossadj label Personposspronoun Personposspronoun label Personchild Personchild label Personparent Personparent label Personsibling documentclass article We are gathered here to remember our personsibling personname Personpronoun will be much missed and personpossadj 152 In Memory of Jane Doe We are gathered here to remember our sister Jane She will be much missed and her family are in our prayers If there is more than one person you will need to use the optional argument label to newperson to uniquely identify each person You can then list all of the people s full or familiar names using peoplefullname peoplefullname peoplename peoplename Note that if there is only one person defined these commands behave the same as personfullname
114. layuppermultibarlabel DTLdisplayuppermultibarlabel text This specifies how to display the upper bar label for DTLmultibarchart The argument is the label This command is ignored by DTLbarchart Example 31 A Labelled Bar Chart This example extends example 30 so that the chart is a bit more informative which is after all the whole point of a chart This chart now has a label below each bar as well as a label above the bar The lower label uses the value of the Name key and the upper label uses the quantity I have also set the outline width so each bar has a border begin figure htbp setlength DTLbarout linewidth lpt centering DTLbarchart variable theQuantity barlabel theName upperbarlabel theQuantity fruit theQuantity Quantity theName Name caption A bar chart end figure This produces Figure 8 2 Example 32 Profit Loss Bar Chart Suppose I have a file called profits csv that looks like Year Profit 2000 pounds2 535 2001 pounds3 752 2002 pounds1 520 2003 pounds1 270 121 40 5 Cherries Peaches Lemons Limes Pears Apples Figure 8 2 A bar chart 122 First I can load this file into a database called profits DTLloaddb profits profits csv Now I can plot the data as a bar chart begin figure htbp centering Set the width of each bar to 10pt setlength DTLbarwidth 10pt Set the outline width to lpt setlength DTLbaroutlinew
115. le of the bar ifDTLverticalbars IrDrIvertiealbars This conditional governs whether the chart uses vertical or horizontal bars DTLbarXlabelalign DTLbarXlabelalign This specifies the text alignment of the lower bar labels This defaults to left rotate 90 if you use the vertical databar package option or the verticalbars setting and defaults to right if you use the horizontal databar package option or the verticalbars false setting DTLbarYticklabelalign DTLbarYlabelalign This specifies the text alignment of the y axis labels This defaults to right for vertical bar charts and center for horizontal bar charts DTLbardisplayYticklabe DTLbardisplayYticklabel text This specifies how to display the y tick label The argument is the tick label DTLdisplaylowerbarlabel DTLdisplaylowerbarlabel text This specifies how to display the lower bar label for DTLbarchart and the lower bar group label for DTLmultibarchart The argument is the label DTLdisplaylowermultibarlabel DTLdisplaylowermultibarlabel text 120 This specifies how to display the lower bar label for DTLmultibarchart The argument is the label This command is ignored by DTLbarchart DTLdisplayupperbarlabel DTLdisplayupperbarlabel text This specifies how to display the upper bar label for DTLbarchart and the upper bar group label for DTLmultibarchart The argument is the label DTLdisp
116. letter sent to all parents documentclass letter 155 ifpersonexists usepackage person load student information from file students csv DTLloaddb students students csv begin document Iterate through the student database DTLforeach students FirstName FirstName Surname Surname Gender Gender Parent Parent Address Address Define anon newperson FirstName space Surname FirstName Gender Do the letter begin letter Parent Address opening Dear Parent Your personchild personname has been awarded a place We look forward to seeing personobjpronoun on personpossadj arrival closing Yours Sincerely end letter Undefine anon removeperson end document The body of the first letter appears as follows Your son John has been awarded a place We look forward to seeing him on his arrival Whereas the body of the second letter appears as follows Your daughter Jane has been awarded a place We look forward to seeing her on her arrival 10 3 Advanced Commands This section describes additional commands provided by the person package More detail can be found in the documented code datatool pdf 10 3 1 Conditionals ifpersonexists label true part false part 156 Tests if the person identified by label has been defined If true do true part otherwise do false part ifmale ifmale label true part fal
117. losed in braces For example colors red cyan blue Note where any setting requires a number or list of numbers such as bounds the number must be supplied in standard decimal notation i e no currency no number groups and a full stop as the decimal point Available settings are as follows x The database key that specifies the x co ordinates This setting is required y The database key that specifies the y co ordinates This setting is required markcolors A comma separated list of colour names for the markers An empty value will use the current colour linecolors A comma separated list of colour names for the plot lines An empty value will use the current colour colors A comma separated list of colour names for the lines and markers marks A comma separated list of code to generate plot marks This should typically be a list of pgfuseplotmark commands see the 99 pgf manual for further details You may use relax as an element of the list to suppress markers for the corresponding plot For example marks pgfuseplotmark o relax will use an open circle marker for the first database and no markers for the second database listed in db list lines A comma separated list of line style settings This should typically be a list of pgfsetdash commands see the pgf manual for further details on how to set the line style An empty value will use the current line style You may use relax as an element of the list t
118. lue is 4in DTLplotheight This length governs the length of the y axis Note that the plot height does not include any outer tick marks or labels The default value is 4in DTLticklength 108 This governs the length of the tick marks The default value is 5pt DTLminorticklength DTLminorticklength This governs the length of the minor tick marks The default value is 2pt DTLticklabeloffset ND Dine tek labelormisecic This governs the distance from the axis to the tick labels The default value is 8pt DTLmintickgap DTLmintickgap This is the minimum distance allowed between tick marks If the plot width or height is less than this distance there will only be tick marks at either end of the axis The default value is 20pt DTLlegendxoffset DTLlegendxoffset This is the horizontal distance from the border of the plot to the outer border of the legend The default value is 10pt DTLlegendyoffset DTLlegendyoffset This is the vertical distance from the border of the plot to the outer border of the legend The default value is 10pt 7 2 2 Counters These counters govern the appearance of plots created using DTLplot The value of the counters can be changed using set counter DTLplotroundXvar DTLplotroundXvar Unless you specify your own tick labels the x tick labels will be given by the tick points rounded to n digits after the decimal point where n is the value of the counter DTLplotr
119. mma you must group the number Example DTLmeanforall theMean 1 525 2 340 500 theMean produces 1 455 DTLvarianceforall DTLvarianceforall cmd number list DTLgvarianceforall DTLgvarianceforall cmd number list This sets the control sequence cmd to the variance of all the numbers in number list DLTvarianceforall sets cmd locally while DTLgvarianceforall sets cmd globally Example DTLvarianceforall theVar 25 1 45 2 35 6 theVar produces 67 38 Again note that if any of the numbers in number list contain a comma you must group the number DTLsdforall DTLsdforall cmd number list 29 DTLgsdforall DTLgsdforall cmd y number list This sets the control sequence cmd to the standard deviation of all the numbers in number list DLTsdforall sets cmd locally while DTLgsdforall sets cmd globally Example DTLsdforall theSD 25 1 45 2 35 6 theSD produces 8 208532146492453016 Note that if any of the numbers in number list contain acomma you must group the number Example DTLsdforall theSD 1 525 2 340 500 thesD produces 752 805862534735216539 DTLround DTLround cmd num num digits DTLground DTLground cmd num num digits This sets cmd to num rounded to num digits after the decimal character DLTround sets cmd locally while DTLground sets cmd globally Exam
120. mple using verb or the verbatim environment can t be used in any of the arguments of DTLforeach specifically verbatim can t be used in text There are also environment alternatives begin DTLenvforeach condition db name assign list begin DTLenvforeach x condition db name assign list However note that since these environments gather the contents of their body they also suffer from the above limitation Verbatim can t be used in the body of DTLenvforeach or DTLenvforeach Example 3 Student scores Suppose you have a data file called student scores csv that contains the following FirstName Surname StudentNo Score John Smith Jr 102689 68 Jane Brown 102647 75 Andy Brown 103569 42 Z oe Adams 105987 52 Roger Brady 106872 58 Clare Verdon 104356 45 and you load the data into a database called scores using DTLloaddb scores studentscores csv you can then display the database in a table as follows begin table htbp caption Student scores centering begin tabular llr bfseries First Name amp bfseries Surname amp bfseries Score DTLforeach scores firstname FirstName surname Surname score Score DTLrowi DTLrowii DTLrowiii XDTLcurrentindex firstname amp surname amp score end tabular end table This produces Table 5 4 Note that since I didn t need the student registration n
121. n auxiliary file So if my document is called researchwork tex then I need to do latex researchwork bibtex researchwork bibtex kernel bibtex food latex researchwork latex researchwork bibliography database As before DTLloadbbl and DTLbibliography are used to load and display the main bibliography 147 cite x is used to add all the entries in the bib file to the main Don t try to directly input the bb1 file using input or include instead of using DTLloadbbl or DTLloadmbb1 as these commands store the name of the required database and initialise the database be fore loading the bb1 file Similarly don t just copy the contents of the bb1 file into your document without first defining the database using DTLnewdb and setting DTLBIBdbname to the name of the database 148 newperson malelabels femalelabels 10 Referencing People person package Sometimes when mail merging it may be necessary to reference a person by their pronoun which can lead to the cumbersome and impersonal he she construct The person package allows you to define a person by their full name familiar name and gender You can then use the commands described in section 10 2 to produce the appropriate pronoun This can also be useful for other types of documents such as an order of service for a baptism or funeral Since the document is much the same from one person to the next documents of this natur
122. n assign list for row row idx in database db name where assign list has the same format as in DTLforeach Two rows can be swapped using DTLswaprows DTLswaprows db name row1 index row2 index where row1 index and row2 index are the indices of the rows to be swapped For example DTLswaprows scores 3 5 will swap the third and fifth rows DTLifinlist DTLifinlist element list true part false part If element is contained in the comma separated list given by list then do true part otherwise do false part Does a one level expansion on list but no expansion on element DTLnumitemsinlist DTLnumitemsinlist list cmd Counts the number of non empty elements in list and stores result in cmd which must be a control sequence Example 18 Two Database Rows Per Tabular Row Column Wise This example adapts example 8 so that the list is ordered vertically rather than horizontally begin table htbp caption Two database rows per tabular row column wise centering store half number of rows edef maxrows DTLrowcount scores DTLdiv halfrowidx maxrows 2 begin tabular llcllc bfseries First Name amp bfseries Surname amp dtlgetrow Ndtlcurrentrow 9 bfseries Score amp bfseries First Name amp bfseries Surname amp bfseries Score XDILforeachx value DTLrowi lt halfr
123. n list t condition key value This adds the entry with the key given by key and value given by value to the first row in the database db which satisfies the condition given by condition The assign list argument is the same as for DTLforeach described in section 5 4 and may be used to set the values which are to be tested in condition where again condition is the same as for DTLforeach For example DTLaddentryforrow mydata firstname FirstName surname Surname DTLiseq firstname John and DTLiseq surname Smith Score 75 Note that unlike DTLnewdbent ry the value is always expanded when adding an entry using ADTLaddentryforrow DTLsetheader DTLsetheader db key header This assigns a header for a given key in the database named db This is used by DTLdisplaydb and DTLdisplaylongdb in the header row see section 5 3 If you don t assign a header the header will be given by the key For example DTLsetheader mydata Price Price S 5 2 Loading a Database from an External ASCII File Instead of using the commands described in section 5 1 to create a new database you can load a database from an external ASCII file using DTLloaddb DTLloaddb options db name filename Make sure your document uses the same encoding as filename For example if filename is UTF 8 then include the following in your doc ument Nusepackage
124. n External Pe 66 eee os 5 10 Deleting or Clearing a Database wa c AN mo ma Ron 5 11 Advanced Database Commands 15 s ec Rm 11 1 Operating on Current ROW e cance x Rei Pie Charts datapie package Ll Pie Chart Variables 6 s es ca 8 hed eek 62 DPieChart Label Formatting e A x oom omm 6 3 Pie Chart Colours 0 0000 eee ee eee 6 4 Adding Extra Commands Before and After the Pie Chart Scatter and Line Plots dataplot package 7 1 Adding Information tothe Plot 2222 44 24 444 Az Glopal Plotseling lt lt cR oe ner Tad EBEN cT 22 COUMES uu ae ACE Wok oe A 743 9 E o ouo es A ou X RuE A aw Ros po Adding toa PELS xu ess X era RU ans 111 8 Bar Charts databar package 8 1 Changing the Appearance ofa Bar Chart 9 Converting a BIBTEX database into a datatool database databib package BI BEA EEN ceo A eee XA Bane ee box vea SII BIER database A gs d Ro 0 RE dede Sw Y 9 2 Loading a databib database o m s 9 3 Displaying a databib database 9 4 Changing the bibliography style 9 4 1 Modifying an existing style 9 5 Iterating through a databib database 9 6 Multiple Bibliographies zu e RR E 10 Referencing People person package 10 1 Defining and Undefining People lt lt lt 2 es 10 2 Displaying Information o or Sa eR 10 3 Advanced Commands 10 3 1 Conditionals 2 2 22 22 mn
125. ncy If you want this to be considered currency you will have to add the sequence US to the set of currency symbols DTLnewcurrencysymbol US DTLifcurrency US 5 99 currency not currency this now produces currency This document has used the textcomp package which defines texteuro so this is also considered to be currency For example DTLifcurrency texteuro5 99 currency not currency produces currency The preferred method is to display the euro symbol in a sans serif font but DTLifcurrency textsf texteuro 5 99 currency not currency will produce not currency It is better to define a new command for example XDeclareRobustCommandx euro textsf texteuro and add that command to the list of currency symbols In fact in this case if you define the command euro in the preamble it will automatically be added to the list of known currency symbols If however you define euro in the document you will have to add it using DTLnewcurrencysymbol For example Xnewcommand leuro textsf texteuro DTLnewcurrencysymbol euro DTLifcurrency euro5 99 currency not currency produces currency DTLifcurrencyunit DTLifnumerical DTLifcurrencyunit text symbol true part false part If text is currency and uses symbol as the unit of currency then do true part otherwise do false part For example DTLifcurrencyunit 6 99 S dollar
126. nd a full stop as a decimal point DTLisFPclosedbetween DTLisFPclosedbetween num min max This checks if num lies between min and max end points included All arguments must be numbers in standard fixed point format i e no number group separators no currency and a full stop as a decimal point DTLisFPopenbetween DTLisSubString DTLisPrefix DTLisFPopenbetween num min max This checks if num lies between min and max end points excluded All arguments must be numbers in standard fixed point format i e no number group separators no currency and a full stop as a decimal point DTLisSubStringt string substring This checks if substring is contained in string The remarks about DTLifSubString also apply to DTLisSubString This command performs a case sensitive match DTLisPrefix string t prefix This checks if string starts with prefix The remarks about DTLifStartsWith also apply to DTLisPrefix This command performs a case sensitive match 21 3 Fixed Point Arithmetic The datatool base package uses either the fp or the pgfmath package to perform fixed point arithmetic however all numbers must be converted from the locale dependent format into the format required by the fp or pgfmath packages A numerical value i e an integer a real or currency can be converted into a plain decimal number using DTLconverttodecimal DT
127. nds DTLformatauthor 4 ifthenelse DTLiseq 2 Talbot and DTLisPrefix 4 N bfseries DTLformat forenames 4 DTLformatvon 1 DTLformatsurname 2 DTLformatjr 3 3 I have used a group to localise the effect of bfseries 142 9 5 Iterating through a databib database DTLbibliography described in section 9 3 may still not meet your needs For example you may be required to list journal papers and conference proceedings in separate sections In which case you may find it easier to iterate through the bibliography using DTLforeachbib DTLforeachbib condition db name text DTLforeachbibx DTLforeachbib condition db name y text This iterates through the databib database called db name and does text if condition is met As with NDTL oreach the starred version is read only For each row of the database the following commands are set DBIBcitekey DBIBcitekey This is the unique label which identifies the current entry as used in the argument of cite and nocite DBIBentrytype e DBIBentrytype This is the current entry type and will be one of article book booklet inbook incollection inproceedings manual mastersthesis misc phdthesis proceedings techreport or unpublished Note that even if you used the entry type conference in your bib file its entry type will be set to inproceedings The remaining fields m
128. ng specifies which axes to display This may take one of the following values both x y or none barlabel This setting specifies the lower bar label When used with DTLmultibarchart it indicates the group label multibarlabels This setting should contain a comma separated list of labels for each bar within a group for DTLmultibarchart This setting is not available for DTLbarchart upperbarlabel This setting specifies the upper bar label This setting is not available for DTLmultibarchart 116 uppermultibarlabels This setting must be a comma separated list of upper bar labels for each bar within a group This setting is not available for DTLbarchart yticpoints This must be a comma separated list of tick locations for the y axis These should be standard decimal values This setting overrides yticgap yticgap This specifies the gap between the y tick marks This should be a standard decimal value yticlabels This must be a comma separated list of tick labels for the y axis ylabel This specifies the label for the y axis groupgap This specifies the gap between groups when using DTLmultibarchart This value is given as a multiple of the bar width The default value is 1 which indicates a gap of one bar width This setting is not available for DTLbarchart verticalbars This is a boolean setting so it can only take the values t rue do a vertical bar chart or false do a horizontal bar chart If the value is omitted
129. nggt DTLifstringgt stringl string2 t true part false part If string1 is alphabetically greater than string2 then do true part otherwise do false part The starred version ignores the case the unstarred version is case sensitive For example DTLifstringgt aardvark zebra greater not greater produces not greater Note that both string1 and string2 are considered to be strings so for example DTLifstringgt 2 10 greater not greater produces greater since the string 2 comes after the string 10 when arranged alphabetically As with DTLifstringlt uppercase characters are considered to be less than lower case characters when performing a case sensitive comparison so DTLifstringgt B a greater not greater 11 produces not greater whereas DTLifstringgt B a greater not greater produces greater DTLifgt DTLifgt arg1 arg2 true part false part DTLifgt DTLifgt x arg1 arg2 true part false part If arg1 and arg2 are both numerical then this is equivalent to DTLifnumgt otherwise it is equivalent to DTLstringgt when using DTLifgt or DTLstringgt when using DTLifgt DTLifnumclosedbetween DTLifnumclosedbet ween num min max y true part false part If min lt num lt max then do true part otherwise do false part Note that num min and max must
130. nme nee 10 3 2 Iterating Through Defined People 10 3 3 Accessing Individual Information Bibliography Acknowledgements Index iv 115 117 160 161 162 List of Examples WO CD JO D s WN r Hi al Ro WWWWWWWWNNNNNNNNNN k FA RP k RP eee ND WAP WNFOUOANDTHPWNFOUOAN DD TB WN Displaying the Contents of a Database 43 Balance Sheet ck Bee caa ee Ge es 47 Student scares oia oe moo an Sw a doe Bu 49 Student Scores Labelling 32d b kom HSE KAS 51 Lat OWS RC Cm 52 Breaking Outotd Loop x s sa a a w orc RR as 54 soc NIU MEM EC eR ROE Ew Eee es 55 Two Database Rows per Tabular Row 56 Iterating Through Keys in a Row 2 6 2 66 eee ses 57 Nested NDILforeaeh a bade eb a are Be 60 Dynamically Allocating Field Name 62 ING Valles o e ome er ne Rorate Re E ws 63 Editing Database Rows 4 lt 4 28 e or rA x a 67 Arithmetical Computations 22 9224 2456 Sr nu 68 Mail TE CT 72 Sorte o Database s o soe oe XR o OS PEE es 74 Influencing the sortorder 22 4 4 eevee RR x RS 77 Two Database Rows Per Tabular Row Column Wise 82 POPE CMA ee x BA doro ek dose ne we Cn oso s 88 Separating Segments from the Pie Chart 90 Changing the Inner and Outer Labels 93 Changing the Inner and Outer Label Format 94 Ple Segment Colours co reio a y ke ee des 96 Adding Information to the Pie Chart ossa 2 2 402 0 98 A Basic Gapi
131. nteger with new value The new value doesn t get expanded dtlremoveentryincurrentrow dt lremoveentryincurrentrow col idx Removes the value in dt 1current row for the column given by col idx dtlswapentriesincurrentrow dt lswapentriesincurrentrow coll idx col2 idx Swaps entries in columns coll idx and col2 idx in dt lcurrentrow where col1 idx and col2 idx are the column indices dtlappendentrytocurrentrow dtlappendentrytocurrentrow key value Appends value to the current row for column given by key Note this is the only command in this section to reference by key rather than by index 85 DTLpiechart 6 Pie Charts datapie package The datapie package is not loaded by the datatool package so you need to explicitly load datapie if you want to use any of the commands defined in this section You will also need to have the pgf tikz packages installed The datapie package may be given the following options color datapie Colour option default gray datapie Grey scale option rotateinner datapie Rotate inner labels so that they are aligned with the pie chart radial axis norotateinner datapie Don t rotate inner labels default rotateouter datapie Rotate outer labels so that they are aligned with the pie chart radial axis norotateouter datapie Don t rotate outer labels default Numerical information contained in a database created by the dat
132. ntries over all the databases listed in db list for all keys in key list where the condition given by condition is true The second optional argument assign list is the same as the assignment list used by DTLforeach so that you can use the information in condition The result is stored in cmd which must be a control sequence DTLsdforcolumn db key cmd This is a faster version of DTLsdforkeys that only computes the standard deviation for a single column specified by key for a single database specified by db and doesn t provide any filtering The result is stored in cmd which must be a control sequence DTLminforkeys condition assign list db list key list cmd This command determines the minimum value over all entries for all keys in key list over all the databases listed in db list where condition is true The second optional argument assign list is the same as the assignment list used by DTLforeach so that you can use the information in condition The result is stored in cmd which must be a control sequence For example DTLminforkeys scores Score theMin 71 sets theMin to the minimum score in the database DTLminforcolumn DTLminforcolumn db key cmd This is a faster version of DTLminforkeys that only computes the minimum for a single column specified by key for a single database specified by db and do
133. o suppress line for the corresponding plot For example lines relax pgfsetdash 0Opt will have no lines for the first database and a solid line for the second database listed in db list width The width of the plot This must be a length The plot width does not include outer tick marks or labels height The height of the plot This must be a length The plot height does not include outer tick marks or labels style This setting governs whether to use lines or markers in the plot and may take one of the following values both lines and markers lines only lines or markers only markers The default is markers axes This setting governs whether to display the axes and may take one of the following values both x y or none If no value is specified both is assumed box This setting governs whether or not to surround the plot in a box It is a boolean setting taking only the values true and false Ifno value is specified t rue is assumed xtics This setting governs whether or not to display the x tick marks It is a boolean setting taking only the values true and false If no value is specified t rue is assumed If the axes setting is set to both or x this value will automatically be set to t rue otherwise it will be set to false ytics This setting governs whether or not to display the y ticks It is a boolean setting taking only the values true and false If no value is specified t rue is assumed If the axes s
134. oaddb noheader keys Temperature Time T2G headers shortstack Incubation Temperature shortstack Incubation Time shortstack Time to Growth data data csv omitlines This should be a non negative integer that specifies how many rows to skip at the start of the file By default the entries in the database must be separated by a comma and optionally delimited by the double quote character The separator can be changed to a tab separator using the command DTLsettabseparator DTLsettabseparator To set the separator to a character other than a tab you need to use DTLset separator DTLset separator character The delimiter can be changed using DTLsetdelimiter DTLsetdelimiter character For example suppose you have a file called mydata csv which contains the following FirstName Surname Score John Smith Jr 68 Jane Brown 75 Andy Brown 42 Z oe Adams 52 DTLloadrawdb then DTLloaddb mydata mydata csv is equivalent to DTLnewdb mydata DTLnewrow mydata DTLnewdbentry mydata FirstName John DTLnewdbentry mydata Surname Smith Jr DTLnewdbentry mydata Score 68 DTLnewrow mydata DTLnewdbentry mydata FirstName Jane DTLnewdbentry mydata Surname Brown DTLnewdbentry mydata Score 75 DTLnewrow mydata DTLnewdbentry mydata FirstName Andy DTLnewdbentry mydata Surname Brown DTLnewdbentry mydata Score 42 DTLn
135. of the other currency symbols Consider DTLifnumerical pounds10 95 numerical not numerical This produces numerical However ifthenelse DTLisnumerical pounds10 95 numerical not numerical produces not numerical This is due to the expansion that occurs within ifthenelse This can be prevented using noexpand for example ifthenelse DTLisnumerical noexpand pounds10 95 numerical not numerical produces numerical Likewise def cost pounds10 95 ifthenelse DTLisnumerical noexpand cost numerical not numerical produces numerical DTLiscurrency text Tests if text is currency For example ifthenelse DTLiscurrency 10 95 currency not currency produces currency The same warning given above for DTLisnumerical also applies here DTLiscurrencyunit DTLiscurrencyunit text symbol Tests if text is currency and that currency uses symbol as the unit of currency For example ifthenelse DTLiscurrencyunit 6 99 dollars not dollars produces dollars Another example def cost eurol0 50 ifthenelse DTLiscurrencyunit noexpand cost noexpand euro euros not euros produces euros Again note the use of noexpand DTLisreal DTLisreal text Tests if text is a fixed point number again an integer is not considered to be a fixed point number For example ifthenelse DTLisreal 1 5 real not real produces real DTL
136. ography without incurring a multiply defined warning message Note that you can still use cite to add citation information to the main auxiliary file If you want to add an entry to the bibliography without producing any text you can use DTLnocite DTLnocite mbib y cite key list which is analogous to nocite cite key list where again the citation information is written to mbib aux instead of the document s main auxiliary file Note that for both DTLcite and DTLnocite the mbib part must be one of the names listed in DTLmultibibs DTLloadmbb1 DTLloadmbb1 mbib y db name y bib list y This is analogous to DTLloadbb1 db name bib list described in section 9 2 Again mbib must be one of the names listed in DTLmultibibs This creates a new datatool database called db name and loads the bibliography information from mbib bb1 if it exists DTLmbibliography DTLmbibliography condition 1 mbib y db name This is analogous to DTLbibliography condition db name but is required when displaying a bibliography in which elements have been cited using DTLcite and DTLnocite Example 39 Multiple Bibliographies Suppose I need to create a document which contains a section listing all my publications but I also need to have separate sections covering each of my research topics with a mini bibliography at the end of each section As in the earlier exam
137. oints The value must be a comma separated list of decimal numbers indicating where to put the x tick marks If omitted the x tick marks are placed at equal intervals along the x axis such that each interval is not less than the length given by DTLmintickgap This setting overrides xticgap xticgap This value specifies the gap between the x tick marks yticpoints The value must be a comma separated list of decimal numbers indicating where to put the y tick marks If omitted the y tick marks are placed at equal intervals along the y axis such that each interval is not less than the length given by DTLmintickgap This setting overrides yticgap 101 yticgap This value specifies the gap between the y tick marks grid This is a boolean value that specifies whether or not to display the grid If no value is given t rue is assumed The minor grid lines are only displayed if the minor tick marks are set xticlabels The value must be a comma separated list of labels for each x tick mark If omitted the labels are the value of the x tick position rounded n digits after the decimal point where n is given by the value of the counter DTLplotroundXvar yticlabels The value must be a comma separated list of labels for each y tick mark If omitted the labels are the value of the y tick position rounded n digits after the decimal point where n is given by the value of the counter DTLplotroundYvar xlabel The value is the label for the
138. on is used otherwise a case sensitive alphabetical comparison is used Note that there is no starred version of this command instead use NDTLisieq gt XDTLisieq DTLisieg argl arg2 This checks if arg1 is equal to arg2 As with DTLifeg if arg1 and arg2 are numerical a numerical comparison is used otherwise a case insensitive alphabetical comparison is used DTLisclosedbetween DTLisclosedbetween arg min max This checks if arg lies between min and max end points included As with DTLifclosedbetween if the arguments are numerical a numerical comparison is used otherwise a case sensitive alphabetical comparison is used Note that there is no starred version of this command instead use DTLisiclosedbetween DTLisiclosedbetween DTLisiclosedbetween arg min max This checks if arg lies between min and max end points included As with ADTLifclosedbetweenx if the arguments are numerical a 19 DTLisopenbetween DTLisiopenbetwee DTLisFPlt DTLisFPlteq DTLisFPgt DTLisFPgteq numerical comparison is used otherwise a case insensitive alphabetical comparison is used DTLisopenbetween arg min max This checks if arg lies between min and max end points excluded As with DTLifopenbetween if the arguments are numerical a numerical comparison is used otherwise a case sensitive alphabetical comparison
139. ou set the colour of each bar to correspond with whatever the bar represents DTLdobarcolor DTLdobarcolor n This sets the current colour to the colour of the 1 th bar DTLbaroutlinecolor DILbarout linecolor This macro contains the colour of the bar outlines This defaults to black DTLbaroutlinewidth DTLbaroutlinewidth This length specifies the line width for the bar outlines If it is Opt the outline is not drawn The default value is Opt DTLbaratbegintikz DTLbaratbegintikz This specifies any additional commands to add to the start of the plot It defaults to nothing and is called after the unit vectors are set DTLbaratendtikz DTLbaratendtikz This specifies any additional commands to add to the end of the plot It defaults to nothing DTLeverybarhook DTLeverybarhook The specifies code to apply at every bar Within the definition of DTLstartpt DTLeverybarhook you can use the commands DTLstartpt the DTLmidpt start of the bar DTLmidpt the mid point of the bar and DTLendpt DTLendpt the end of the bar For example using the earlier fruit database renewcommands DTLeverybarhook 119 pgftext at DTLmidpt insertName space insertValue wa DTLbarchart variable insertValue axes both ylabel Quantity max 50 verticalbars false fruit insertValue Value insertName Name This puts the name followed by the quantity in brackets in the midd
140. ould also be noted that many commands will be ignored so DTLifstringeq uppercase t ext text true false produces true Spaces are considered to be equivalent to space and For example DTLifstringeq an apple an apple true false produces true Consecutive spaces are treated as the same for example DTLifstringeq an apple an apple true false produces true DTLifeqt argl arg2 t true part false part NDTLi feas arg1 arg2 true part false part If both arg1 and arg2 are numerical then this is equivalent to DTLifnumeg otherwise it is equivalent to DTLifstringeg when using DTLifeq or DTLifstringeg when using DTLifeg dtlifnumlt DTLifnumlt DTLifstringlt XDTLifstringltx dtlifnumlt numl num2 true part false paty If num1 is less than num2 then do true part otherwise to false part where num1 and num2 are plain numbers using a full stop as the decimal point and no number group separator For currency or locale dependent numbers use DTLifnumlt DTLifnumlt numl num2 true part false part If num1 is less than num2 then do true part otherwise do false part Note that both num1 and num2 must be numerical either integers real numbers or currency DTLifstringlt string1 string2 true part false part DTLifstringlt string string2
141. oundXvar DTLplotroundYvar 109 DTLplotmarks DTLplotroundYvar Unless you specify your own tick labels the y tick labels will be given by the tick points rounded to n digits after the decimal point where n is the value of the counter DTLplotroundYvar 7 2 3 Macros These macros govern the appearance of plots created using DTLplot They can be changed using renewcommand XDTLplotmarks This must be a comma separated list of pgf code to create the plot marks DTLplot cycles through this list for each database listed The pgf package provides convenient commands for generating plots using pgfuseplotmark See the pgf manual for more details DTLplotmarkcolors DTLplotlines DTLplotmarkcolors This must be a comma separated list of defined colours to apply to the plot marks DTLplot cycles through this list for each database listed If this macro is set to empty the current colour will be used instead DTLplotlines This must be a comma separated list of pgf code to set the style of the plot lines DTLplot cycles through this list for each database listed Dash patterns can be set using pgfsetdash see the pgf manual for more details If DTLplotlines is set to empty the current line style will be used instead DTLplotlinecolors DTLXAxisStyle DTLplotlinecolors This must be a comma separated list of defined colours to apply to the plot lines DTLplot cycles through this list for each database
142. overallmean DTLbarchartwidth overallmean node right black Average overallmean Set the lower bar labels to draw a brace across the current group along with the student s name and average score Nrenewcommand DTLdisplaylowerbarlabel 1 tikz baseline current bounding box center Xdraw snake brace rotate 90 0 0 DTLbargroupwidth 0 ol pd dp oe 125 5224 Clare Verdon Roger Brady Z e Adams Andy Brown Jane Brown John Smith Jr Figure 8 4 Student marks 126 DTLround theMean theMean 2 shortstack 1 Average theMean draw the bar chart DTLmultibarchart variables assignI assignII assignIIT barwidth 10pt uppermultibarlabels assignI assignII assignIII barlabel firstname surname marks surname Surname firstname FirstName assignI Assignment 1 assignII Assignment 2 assignIII Assignment 3 theMean Average caption Student marks end figure which produces Figure 8 5 Notes 1 I ve used the TikZ snake library to create a brace so I need to put usetikzlibrary snakes in the preamble See the pgf manual for more details on how to use this library 2 I used DTLbargroupwidth to indicate the width of each bar group 3 I used DTLbarchartwidth to indicate the width of the entire bar chart 127 Average 59 11 g S602 Figure 8 5 Student
143. owidx scores firstname FirstName surname Surname score Score NS firstname surname amp score amp edef currentrowidx arabic DTLrowi DTLadd rowidxII halfrowidx currentrowidx DTLassign scores rowidxII firstnamelI FirstName surnameII Surname scorelI Score firstnameII amp surnameII amp scorell end tabular end table This produces Table 5 25 Table 5 25 Two database rows per tabular row column wise First Name Surname Score First Name Surname Score Z e Adams 52 Jos de la Mere 58 Roger Brady 58 John Smith Jr 68 Andy Brown 42 Henk van der Mere 71 Jane Brown 75 Clare Verdon 45 5 11 1 Operating on Current Row If you want to select from or edit a particular row in a database without having to iterate through the database using NDTLforeach you can use the commands described in this section dt 1get row db name row idx Gets the row with index row idx from the database db name The required row is stored in the token register ele le EE 83 dtlbeforerow dtlafterrow dtlrownum dtldbname dtlrecombine the preceding rows are stored in the token register dtlbeforerow the following rows are stored in the token register dtlatterrow the row index row idx is stored in the register dtlrownum and the database name is stored in the control sequence dtldbname No check is made in dtlgetrow to see if the d
144. ple DTLround result 3 135276 2 result produces 3 14 DTLtrunc DTLt runc cmd num num digits DTLgtrunc DTLgt runc cmd num num digits This sets cmd to num truncated to num digits after the decimal character DLTt runc sets cmd locally while DTLgt runc sets cmd globally Example DTLtrunc result 3 135276 2 Nresult produces 3 13 30 DTLclip DTLclip cmd y num y DTLgclip DTLgclip cmd num This sets cmd to num with all unnecessary 0 s removed DLTclip sets cmd locally while DTLgclip sets cmd globally 4 Strings Strings are considered to be anything non numerical The datatool package loads the substr package so you can use the commands defined in that package to determine if one string is contained in another string In addition the datatool provides the following macros DTLsubstitute DTLsubstitute cmd original replacement This replaces the first occurrence of original in cmd with replacement Note that cmd must be the name of a command For example def mystr abcdce DTLsubstitute mystr c z mystr produces abzdce DTLsubstituteall DTLsubstituteall cmd y original replacement This replaces all occurrences of original in cmd with replacement where again cmd must be the name of a command For example def mystr abcdce DTLsubstituteall mystr
145. ples all my publications are stored in the file nlct bib which is somewhere on TEX s path Note that there will be some duplication as the references in the mini bibliographies will also appear in the main bibliography at the end of the document but using DTLcite and DTLmbibliography ensures that all the 146 cross referencing labels and hyperlinks if they are enabled are unique documentclass article us epackage databib DTLmultibibs kernel food be gin document section Kernel methods In this section I m going to describe some research work into ker nel methods and i n the process I m going to cit papers DTLcite kernel Cawley2007a Cawley2006a DT DT se Lloadmbbl kernel Lmbibliography ker ction Food researc kernelDB nlct nel kernelDB h related som In this section I m going to describe some research work in the area of food safety and in the process I m going to DT DT ci re DT DT en cite some related papers DTLcite food Peck1999 Barker1999a Lloadmbbl food fo Lmbibliography foo teix Loadbbl fullDB n odDB nlct d foodDB lct Lbibliography full d document Notes 1 This will create the files kernel aux and food aux These will DB newcommand refname Complete List of Publications have to be passed to BIBIEX in addition to the documents mai
146. r database and you want to display them all without having to set a variable for each column You can leave the assignment list in DTL oreach blank and iterate through the keys using DTLforeachkeyinrow For example begin table htbp caption Student Scores Iterating Through Keys centering begin tabular 1111 bfseries First Name amp bfseries Surname amp bfseries Registration No amp bfseries Score DTLforeach scores gdef doamp gdef doamp amp DTLforeachkeyinrow thisValue doamp thisValue end tabular end table This produces Table 5 11 Table 5 11 Student Scores Iterating Through Keys First Name Surname Registration No Score John Smith Jr 102689 68 Jane Brown 102647 75 Andy Brown 103569 42 Zoe Adams 105987 52 Roger Brady 106872 58 Clare Verdon 104356 45 Note that the amp must be between columns so I have defined a command called doamp that on first use redefines itself to do So for each row at the start of the key iteration 1 doamp does nothing and on subsequent iterations it does amp This ensures that the correct number of amp s are used Since each cell in the tabular environment is scoped gdef is needed instead of def In the above I needed to know how many columns are in the database and the order that the headings should appear If you are unsure you can 57 use Ndtlforeachkey to determine the number of columns and to displa
147. r line For example DTLaddtoplotlegend pgfuseplotmark x relax Some Data Note that the legend is plotted before DTLplotatendtikz so if you want to add information to the legend you will need to do the in DTLplotatstarttikz Example 27 Adding Information to a Plot Returning to the plots created in example 26 suppose I now want to annotate the plot say I want to draw your notice to a particular point say the point 1 58 48 3 then I can redefine DTLplotatendtikz to draw an annotated arrow to that point renewcommands DTLplotatendtikz draw lt line width lpt 1 58 48 3 1 6 43 node below interesting point So Figure 7 4 now looks like Figure 7 5 Obviously DTLplotatendtikz needs to be redefined before using DTLplot 107 DTLplotwidth DTLplotheight DTLticklength 74 90 T 7144 E o GroupA x Group B 67 98 F 6452 E 61 06 o 57 60 5 M Kg S 2 5414 4 50 68 x 47 22 a CH O O 43 76 40 30 i interesting point 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 Height m Figure 7 5 A scatter plot 7 2 Global Plot Settings 7 2 1 Lengths This section describes the lengths that govern the appearance of the plot created using DTLplot These lengths can be changed using setlength DTLplotwidth This length governs the length of the x axis Note that the plot width does not include any outer tick marks or labels The default va
148. r required style and then modify the commands described in this section A description of the remaining commands not listed in this section can be found in section 5 4 section 5 5 and section 5 6 DTLf ormat author von part surname y jr part forenames DTLformateditor von part surname y jr part forenames 138 These commands are used to format an author editor s name respectively The list of authors and editors are stored in the databib database as a comma separated list of von part surname jr part forenames data This ensures that when you sort on the Author or Editor field the names will be sorted by the first author or editor s surname Within DTLformatauthor and DTLformateditor you may use the following commands DTLformat forenames DTLformat forenames forenames This is used by the plain style to display the author s forenames DTLformatabbrvforenames DTLformatsurname DTLformatvon DTLformatjr DTLformatabbrvforenames forenames This is used by the abbrv style to display the author s initials which are determined from forenames Note that if any of the authors has a name starting with an accent the accented letter must be grouped in order for this command to work For example author E lise E awyn Edwards The initials are formed using DTLstoreinitials described in c
149. ra e a 73 NDELSOFEH a4 Ae 44343 73 DTLsplitstring 32 NDILSQEU sbarca eR 27 DTLstartpt i23 119 DTLstoreinitials 33 dtlstringalign 44 dtlstringformat 46 ADTLstringnull 42 1544 63 DTLSEFINGEYPE nen uns 79 BEESUB luere ner 25 ADTLsubstitute sasiada isga 32 DTLsubstituteall 32 DTLsumcolumn 70 DTLsumforkeys 69 dtlswapentriesincurrentrow AURA OBA dtd oA 85 DTLswaprows 82 DTLticklabeloffset 109 123 DTLticklength 108 NDIhBEPUDO 244 0844 beaded es 30 KEN WE MEET 140 DTLunsettype 29 DTLvarianceforall 29 DTLvarianceforcolumn 71 DTLvarianceforkeys 70 DTLXAxisStyle 110 DTLYAxisStyle 111 E environments DTLenvforeach 49 49 DILenvforeachx 49 49 longtable sss 42 43 table tesco ee eave a A s 43 abauen 42 43 45 46 48 56 59 64 69 80 thebibliography 144 tikzpicture 97 99 107 verbatim sys wae e XXE 49 etoolbox package 63 F Xfemalelabels 149 155 femalename 158 158 file types BUR ewe ew EY Y vw 129 bb u Si uA 129 130 133 137 bib assed 129 130 133 142 143 DST td eee Soule 129 foreachperson 158 fp package i ii 2 22 23 68 G getpersonfullname 159 getpersongender 158 getpersonname
150. racters may be changed using DTLsetnumberchars DTLsetnumberchars number group character decimal character Note that scientific notation is not supported and the number group character may not be used after the decimal character Currency A currency symbol followed by an integer or real number is considered to be the currency data type There are two predefined currency symbols and pounds In addition if any of the following commands are defined at the start of the document they are also considered to be a currency symbol texteuro textdollar textstirling textyen textwon textcurrency euro and yen Additional currency symbols can be defined using DTLnewcurrencysymbol DTLnewcurrencysymbol symbol Strings Anything that doesn t belong to the above three types is considered to be a string DTLifint DTLifreal 2 1 Conditionals The following conditionals are provided by the datatool base package DTLifint text true part false part If text is an integer then do true part otherwise do false part For example DTLifint 2536 integer not an integer produces integer The number group character may appear in the number for example DTLifint 2 536 integer not an integer produces integer However the number group character may only be followed by a group of three digits For example DTLifint 2 5 3 6 integer not an integer
151. raphy styles have been set otherwise they will have no effect 141 redefining DTLformatauthor so that it checks if the given surname matches mine This assumes that none of the other co author s share my surname renewcommand DTLformatauthor 4 DTLifstringeq 2 Talbot bfseries DTLformat forenames 4 DTLformatvon 1 DTLformatsurname 2 DTLformat jr 3 Notes 1 I have used ADTLi fstringeq described in section 2 1 to perform the string comparison 2 If one or more of my co authors shared the same surname as me I would also have had to check the first name however there is regrettably a lack of consistency in my bib file when it comes to my forenames Sometimes my name is givenas Nicola L C Talbot sometimes the middle initials are omitted Nicola Talbot or sometimes just initials are used N L C Talbot This can cause problems when checking the forenames but as long as the other authors who share the same surname as me don t also share the same first initial I can use DTLifStartsWith or DTLisPrefix which are described in section 2 1 and section 2 2 respectively Using the first approach I can do renewcommands DTLformatauthor 4 DTLifstringeg 2 Talbot DTLifStartswWith 4 N bfseries DTLformat forenames 4 DTLformatvon 1 DTLformat surname 2 DTLformat jr 3 Using the second approach I can do renewcomma
152. rbose Boolean key If true prints informational messages in transcript math May take one of two values fp load datatool fp or pgfmath load datatool pgfmath Default is fp delimiter Delimiter used in CSV files Default is a double quote separator Delimiter used in CSV files Default is a comma The datatool base package can be used to Determine whether an argument is an integer a real number currency or a string Scientific notation is currently not supported Locale dependent number settings are supported such as a comma as a decimal character and a full stop as a number group character Convert locale dependent numbers currency to the decimal format required by the fp or pgfmath packages enabling fixed point arithmetic to be performed on elements of the database e Names can be converted to initials Determine if strings are all upper or lower case Perform string comparisons both case sensitive and case insensitive Package Options verbose Boolean key If true prints informational messages in transcript math May take one of two values fp load datatool fp or pgfmath load datatool pgfmath Default is fp The datapie package see chapter 6 can be used to convert a database into a pie chart e Segments can be separated from the rest of the chart to make them stand out Colour grey scale options Predefined segment colours can be changed Hooks provided to add extra inform
153. s not all lower Note also that DTLifAllLowerCase MakeLowercase WORD all lower not all lower also produces all lower MakeText Lowercase defined in David Carlisle s textcase package and lowercase are also detected otherwise if a command is encountered the case of the command is considered For example DTLifAllLowerCase man oe uvre all lower not all lower produces all lower DTLifSubString string substring true part false part This tests if substring is a sub string of string This command performs a case sensitive match For example DTLifSubString An apple app is substring isn t substring produces is substring Note that spaces are considered to be equivalent to space or SO DTLifSubString An apple n a is substring isn t substring produces is substring but other commands are skipped so DTLifSubString An uppercase a pple app is substring isn t substring 15 DTLifStartsWith DTLisstring produces is substring since the uppercase command is ignored Note also that grouping is ignored so DTLifSubString An ap ple app is substring isn t substring produces is substring DTLifSubString is case sensitive so DTLifSubString An Apple app is substring isn t substring produces isn t substring DTLifStartsWith string t substring true part false part This is like DTLifSubSt ring except
154. s not dollars produces dollars Another example def cost eurol0 50 DTLifcurrencyunit cost euro euros not euros produces euros DTLifnumerical text true part false part If text is numerical either an integer real number or currency then do true part otherwise do false part For example DTLifnumerical 1 000 0 number string produces number Whereas DTLsetnumberchars DTLifnumerical 1 000 0 number string produces string Since the number group character is now a full stop and the decimal character is now a comma The number group character may only appear before the decimal character not after it Currency is also considered to be numerical DTLsetnumberchars DTLifnumerical 1 000 0 number string produces number DTLifstring DTLifstring text true part false part This is the opposite of DTLifnumerical If text is not numerical do true part otherwise do false part DTLifcasedatatype DTLifcasedatatype text string case int case real case currency case If text is a string do string case if text is an integer do int case if text is a real number do real case if text is currency do currency case For example DTLifcasedatatype 1 000 string integer real currency produces integer dtlifnumeq dtlifnumegq mum num2 true part
155. s considered to be lower than the letter a Example 16 Sorting a Database This example uses the database called scores defined in example 3 First I am going to sort the database according to the student scores in descending order highest to lowest and display the database in a table begin table htbp caption Student scores sorted by score centering DTLsort Score descending scores begin tabular llr bfseries First Name amp bfseries Surname amp bfseries Score DTLforeach scores firstname FirstName surname Surname score Score firstname amp surname amp score 74 end tabular end table This produces Table 5 20 Table 5 20 Student scores sorted by score First Name Surname Score Jane Brown 75 John Smith Jr 68 Roger Brady 58 Z e Adams 52 Clare Verdon 45 Andy Brown 42 Now I am going to sort the database according to surname and then first name and display itin a table Note that since I want to sort in ascending order I can omit the ascending part of the sort criteria I have also decided to reverse the first and second columns so that the surname is in the first column begin table htbp caption Student scores sorted by name centering DTLsort Surname FirstName scores begin tabular llr bfseries Surname amp bfseries First Name amp bfseries Score DTLforeach scores firstname FirstName surname Surnam
156. s produces Table 5 5 and the following text Jane Brown scored the highest 75 her score can be seen on row 2 Notes e the label command is placed before to ensure that it is in the same scope as the command refstepcounter DTLrowi To avoid unwanted spaces the end of line characters are commented out with the percent symbol Example 5 Filtering Rows As mentioned earlier the optional argument condition of NDTL oreach provides a means to exclude certain rows This example uses the 52 Table 5 5 Student scores Row First Name Surname Score 1 John Smith Jr 68 2 Jane Brown 75 3 Andy Brown 42 4 Z e Adams 52 5 Roger Brady 58 6 Clare Verdon 45 database defined in example 3 but only displays the information for students whose marks are above 60 At the end of the table DTLsavelastrowcount is used to store the number of rows in the table Note that DTLsavelastrowcount is outside of DTLforeach begin table htbp caption Top student scores centering begin tabular llr bfseries First Name amp bfseries Surname amp bfseries Score DTLforeachs DTLisgt score 60 scores firstname FirstName surname Surname score Score firstname amp surname amp score end tabular DTLsavelastrowcount n n students scored above 60 end table This produces Table 5 6 Note that in this example I could have specified the condition as score gt 60 since all
157. se Year field is less than or equal to 1983 DTLbibliography DTLbibfieldisle Year 1983 mybib DTLbibfieldisgt field label value This tests whether the value of the field given by field label is greater than value If the field doesn t exist for the current entry this evaluates to false For example the following will produce a bibliography which only contains entries whose Year field is greater than 1983 DTLbibliography DTLbibfieldisgt Year 1983 mybib DTLbibfieldisge field label value This tests whether the value of the field given by field label is greater than or equal to value If the field doesn t exist for the current entry this evaluates to false For example the following will produce a bibliography which only contains entries whose Year field is greater than or equal to 1983 DTLbibliography DTLbibfieldisge Year 1983 mybib 135 Note that DTLbibliography uses DTLforeachbibentry described in section 9 5 so you may also use test the value of the counter DTLbibrow within conditions You may also use the boolean commands defined by the ifthen package such as not Example 34 Creating a list of publications since a given year Suppose my boss has asked me to produce a list of my publications in reverse chronological order but doesn t want any publications published prior to the year 2000 I have a file called n1ct bib which contains all my publications whi
158. se part Test if the person identified by label is male If true do true part otherwise do false part iffemale Viffemale label true part false part Test if the person identified by label is female If true do true part otherwise do false part ifallmale ifallmale label list true part false part Tests if all the people listed in label list are male If true do true part otherwise do false part If label list is omitted applied to all defined people ifallfemale ifallfemale label list true part false part Likewise to test if all the people tested are female To determine if a string is an allowed male label ifmalelabel ifmalelabel identifier true part false part where identifier is the string to be tested If true do true part otherwise do false part For example def gender M ifmalelabel gender male not male Similarly to for an allowed female label iffemalelabel iffemalelabel identifier true part false part For example ifmalelabel gender Male 157 iffemalelabel gender Female Undefined Gender wa 10 3 2 Iterating Through Defined People You can iterate through all defined people using foreachperson foreachperson name cs full name cs gender cs label cs Ndo body At each iteration name cs full name
159. st contain a comma you must group the number Example DTLminall theMin 1 525 2 340 500 theMin produces 500 DTLmax DTLmax cmd num1 num2 DTLgmax DTLgmax cmd num1 num2 This sets the control sequence cmd to the maximum of num1 and num2 DLTmax sets cmd locally while DTLgmax sets cmd globally For example DTLmax result 256 32 result produces 256 Again num1 and num2 may be currency but the same warnings for DTLmin apply DTLmaxall DTLmaxal1 cmd number list DTLgmaxall DTLgmaxal1 cmd number list This sets the control sequence cmd to the maximum of all the numbers in number list DLTmaxall sets cmd locally while DTLgmaxall sets cmd globally Example DTLmaxall theMax 25 1 45 2 35 6 theMax 28 produces 45 2 Note that if any of the numbers in number list contain a comma you must group the number Example DTLmaxall theMax 1 525 2 340 500 theMax produces 2 340 DTLmeanforall DTLmeanforall cmd number list DTLgmeanall DTLgmeanforall cmd number list This sets the control sequence cmd to the arithmetic mean of all the numbers in number list DLTmeanforall sets cmd locally while DTLgmeanforall sets cmd globally Example DTLmeanforall theMean 25 1 45 2 35 6 theMean produces 35 3 Note that if any of the numbers in number list contain a co
160. st symbol will be used For example DTLadd result pounds3 562 65 euro452 2 result produces 4 014 85 Likewise if one value is a number and the other is a currency the type of the last value num2 will be used for the result For example DTLadd result 3 562 65 452 2 result produces 4 014 85 DTLaddall DTLaddal1 cmd number list DTLgaddall DTLgaddal1 cmd number list This sets the control sequence cmd to the sum of all the numbers in number list DLTaddall sets cmd locally while DTLgaddall sets cmd globally Example DTLaddall total 25 1 45 2 35 6 total produces 105 9 Note that if any of the numbers in number list contain a comma you must group the number Example DTLaddall total 1 525 2 340 500 total DTLsub DTLgsub DTLmul DTLgmul produces 4 365 DTLsub cmd num1 num2 DTLgsub cmd num1 num2 This sets the control sequence cmd to num1 num2 NDLTsub sets cmd locally while DTLgsub sets cmd globally For example DTLsub result 3 562 65 412 2 result will produce 3 150 45 As with DTLadd num1 and num2 may be currency DTLmul cmd num1 num2 DTLgmul cmd num1 num2 This sets the control sequence cmd to num1 x num2 DLTmul sets cmd locally while DTLgmul sets cmd globally For example DTLmul result 568 95 2
161. stream condition db name x key y key This adds points to a stream from the database called db name where the x co ordinates are given by the key x key and the y co ordinates are 111 given by the key y key DTLconverttodecimal is used to convert locale dependent values to a standard decimal that is recognised by the pgf package The optional argument condition is the same as that for DTLforeach Example 28 Adding to a Plot Stream Suppose you have a CSV file called data csv containing the following X Y 0 0 Ll 250 5 1 54043 r First load the file into a database called data DTLloaddb data data csv Now create a figure containing this data begin figure tbhp centering begin tikzpicture pgfplothandlermark pgfuseplotmark o pgfplotstreamstart DTLplotstream data x y pgfplotstreamend pgfusepath stroke end tikzpicture caption Adding to a plot stream end figure This produces Figure 7 6 o Figure 7 6 Adding to a plot stream Example 29 Plotting Multiple Keys in the Same Database Suppose I have conducted two time to growth experiments For each experiment I have recorded the log count at set times and I have recorded this information in the same data file called say growth csv which contains the following 112 Time Experiment 1 Experiment 2 073 73 7 3 6 23 3 07 3 7 60 4 9 3 8 I can load the data into a database using
162. t a member of that club The data can be loaded as follows DTLloaddb clubs clubs csv Suppose at the beginning of your document you have specified which club you are interested in Rockin or Single and store it in DIdent newcommand DIdent Rockin You can now display the members for this particular club as follows begin table htbp caption Club Membership centering begin tabular 1l11 bfseries First Name amp bfseries Surname amp bfseries Status XDTLforeachx not DTLiseq status clubs firstname First Name surname Surname status DIdent firstname amp surname amp status IS end tabular end table The result is shown in Table 5 17 Table 5 17 Club Membership First Name Surname Status John Smith Jr member Andy Brown friend Z e Adams member Roger Brady friend Clare Verdon member 62 DTLstringnull DTLnumbernull DTLifnull 5 5 Null Values If a database is created using DTLnewdb DTLnewrow and DTLnewdbent ry rather than loading it from an ASCII file it is possible for some of the entries to have null values when a value is not assigned to a given key for a given row Note that a null value is not the same as an empty value Empty values can be tested using etoolbox s ifdefempty or similar When you iterate through the database using DTLforeach described in section 5 4 if an entry is missing for a given row the associated command given
163. tbp centering DTLpiechart variable quantity fruit name Name quantity Quantity caption A pie chart end figure This creates Figure 6 1 There are no outer labels by default but they can be set using the outerlabel setting The following sets the outer label to the value of the Name key begin figure htbp centering DTLpiechart variable quantity outerlabel name fruit name Name quantity Quantity caption A pie chart outer labels set end figure 88 Figure 6 1 A pie chart Pears Apples Lemons Limes Cherries Peaches Figure 6 2 A pie chart outer labels set 89 This creates Figure 6 2 You may prefer the labels to be rotated The following switches on the rotation for the inner and outer labels begin figure htbp centering DTLpiechart variable quantity outerlabel name rotateinner rotateouter fruit name Name quantity Quantity caption A pie chart rotation enabled end figure This creates Figure 6 3 3 bg wo Lemons Limes saypea Figure 6 3 A pie chart rotation enabled Example 20 Separating Segments from the Pie Chart You may want to separate one or more segments from the pie chart perhaps to emphasize them You can do this using the cutaway setting The following separates the first and third segments from the pie chart begin figure htbp centering DTLpiechart variable quantity out
164. ted code datatool pdf Example 4 Student Scores Labelling In the previous example the student scores stored in the database 51 scores were placed in a table In this example the table will be modified slightly to number each student according to the row Suppose I also want to identify which row Jane Brown is in and reference it in the text The easiest way to do this is to construct a label on each row which uniquely identifies that student The label can t simply be constructed from the surname as there are two students with the same surname In order to create a unique label I can either construct a label from both the surname and the first name or I can use the student s registration number or I can use the student s score since all the scores are unique The former method will cause a problem since one of the names Z e contains an accent command Although the registration numbers are all unique they are not particularly memorable so I shall instead use the scores begin table htbp caption Student scores centering begin tabular cllc bfseries Row amp bfseries First Name amp bfseries Surname amp bfseries Score DTLforeach scores firstname FirstName surname Surname score Score 1 label row score theDTLrowi amp firstname amp surname amp score end tabular end table Jane Brown scored the highest 75 her score can be seen on row ref row 75 Thi
165. tes undefines the database given by db name 5 11 Advanced Database Commands This section describes more advanced commands Further details can be found in the documented code datatool pdf DTLgetdatatype DTLgetdatatype cs db key Gets the data type for the given key key for the database given by db The data type is stored in cs which must be a command name The type will be one of DTLunsettype e DTLunsettype not set DTLstringtype e DTLstringtype string DTLinttype e DTLinttype integer DTLrealtype e DTLrealtype real number or DTLcurrencytype e DTLcurrenttype currency dtlforeachkey dtlforeachkey key cs col cs type cs header cs Mint db do t body This iterates through all the keys in the database given by db In each iteration key cs is set to the key col cs is set to the column index type 79 cs is set to the data type as for DTLgetdatatype header cs is set to the header for that column and then body is done Note that key cs col cs type cs and header cs must all be control sequences No check is performed to determine if that control sequence already exists and the control sequences are defined globally since it s likely that dtlforeachkey may be used within a tabular environment so you need to make sure you don t override an existing command of the same name dtlforcolumn dtlforcolumn cs db key
166. ue of the field given by field label equals value If the field doesn t exist for the current entry this evaluates to false For example the following will produce a bibliography which only contains entries which have the Year field set to 2004 DTLbibliography DTLbibfieldiseq Year 2004 mybib DTLbibfieldcontains DTLbibfieldcontains field label sub string This tests whether the value of the field given by field label contains sub string For example the following will produce a bibliography which only contains entries where the author field contains the name Knuth 134 DTLbibfieldislt DTLbibfieldisle DTLbibfieldisgt DTLbibfieldisge DTLbibliography DTLbibfieldcontains Author Knuth mybib DTLbibfieldislt field label value y This tests whether the value of the field given by field label is less than value If the field doesn t exist for the current entry this evaluates to false For example the following will produce a bibliography which only contains entries whose Year field is less than 1983 DTLbibliography DTLbibfieldislt Year 1983 mybib DTLbibfieldisle field label value y This tests whether the value of the field given by field label is less than or equal to value If the field doesn t exist for the current entry this evaluates to false For example the following will produce a bibliography which only contains entries who
167. umber I didn t bother to assign a command to the key StudentNo Table 5 4 Student scores First Name Surname Score John Smith Jr 68 Jane Brown 75 Andy Brown 42 Z e Adams 52 Roger Brady 58 Clare Verdon 45 The macro DTLforeach may be nested up to three times Each level uses the corresponding counters DTLrowi DTLrowiiand DTLrowiiiwhich keep track of the current row Note that these counters are only incremented when condition is satis fied therefore they will not have the correct value in condition These counters are incremented using refstepcounter before the start of text so they may be referenced using label however remem ber that label references the last counter to be incremented using refstepcounter in the current scope The label should therefore be the first command in text to ensure that it references the current row counter Diheurrenta ndex At the start of each iteration in DTLforeach DTLcurrentindex is set to the arabic value of the current row counter Note that this is only set after the condition is tested so it should only be used in the body of DTLforeach not in the condition It is also only set locally so if you use it in a tabular environment it can only be used before the first instance of or amp in the current iteration Within the body of DTLforeach ie within text the following conditionals may be used 50 DTLiffirstrow DTLiffirstrow true
168. x axis If omitted the axis has no label ylabel The value is the label for the y axis If omitted the axis has no label legend This setting governs whether or not to display the legend and where it should be displayed It may take one of the following values none don t display the legend north northeast east southeast south southwest west or northwest If the value is omitted northeast is assumed legendlabels The value must be a comma separated list of labels for the legend If omitted the database names are used Example 25 A Basic Graph Suppose you have a file called groupa csv that contains the following Height Weight 1 55 45 4 1 54 48 0 1 56 59 0 1 567550 2 1 57 46 0 1 58 48 3 1 59 5665 159 591 1 60 60 9 1 62 56 2 102 First load this into a database called groupa DTLloaddb groupa groupa csv The data can now be converted into a scatter plot as follows begin figure htbp centering DTLplot groupa x Height y Weight caption A scatter plot end figure This produces Figure 7 1 60 90 o 59 35 57 80 5625 o 54 70 53 15 51 60 50 05 5 48 50 o 46 95 F o 45 40 le J 154 155 156 1 56 1 57 1 58 1 59 1 60 1 60 1 61 1 62 Figure 7 1 A scatter plot Alternatively you can use the style setting to change it into a line plot begin figure htbp centering DTLplot groupa x Height y Weight style lines
169. y the header row For example begin table htbp caption Student Scores centering Work out the column alignments def colalign dtlforeachkey theKey theCol theType theHead in scores do edef colalign colalign 1 Begin the tabular environment edef dobegintabular noexpand begin tabular colalign dobegintabular Do the header row gdef doamp gdef doamp amp dtlforeachkey theKey theCol theType theHead in scores do doamp bfseries theHead Iterate through the data DTLforeach scores gdef doamp gdef doamp amp DTLforeachkeyinrow thisValue doamp thisValue end tabular end table Table 5 12 Student Scores Using dtlforeachkey and DTLforeachkeyinrow FirstName Surname StudentNo Score John Smith Jr 102689 68 Jane Brown 102647 75 Andy Brown 103569 42 Z e Adams 105987 52 Roger Brady 106872 58 Clare Verdon 104356 45 Notes In order to determine the column alignment for the tabular environment I first define colalign to nothing and then I iterate through the keys appending 1 to colalign Since colalign only contains alphabetical characters I can just use edef for this I could modify this to check the data type and say use 1 left alignment for columns containing strings and c centred for the other columns dtlforeachkey theKey theCol theType theHead in scores do ifnum theType 0 rel

Download Pdf Manuals

image

Related Search

Related Contents

  The Swan Corporation KSEU-3020 User's Manual  Kenroy Home 32560TBW Installation Guide  Organise and prepare food products and services  TruDR eSeries User Manual  OM, McCulloch, MAC 5616 LITE, 952715749, 2014  SeaChanger™ HMI Profile & Wash  DMC-41x3 User Manual - Ultra Sistemas de Controle  Findoo Watch Bedienungsanleitung (D)    

Copyright © All rights reserved.
Failed to retrieve file