Debian Codegraph @

texmf-dist/doc/latex/datatool/samples/sample-sort.tex

raw
1 % This file is public domain
2
3 \documentclass{article}
4
5 \usepackage[margin=1in]{geometry}
6
7 \usepackage[T1]{fontenc}
8 \usepackage[utf8]{inputenc}
9 \usepackage{datatool}
10
11 % Sample database
12
13 \DTLnewdb{data}
14
15 % Add a word to the database. (The Definition column is provided to
16 % distinguish the entries when the database is displayed. The
17 % Definition column is not used by the sort code.)
18
19 % Syntax: \newword{string}
20
21 \makeatletter
22 \newcommand*{\newword}[1]{%
23 \DTLnewrow{data}%
24 \DTLnewdbentry{data}{Word}{#1}%
25 % Convert word to its definition and add
26 {%
27 \def\thisword{#1}%
28 \@onelevel@sanitize\thisword
29 \dtlexpandnewvalue % ensure \thisword gets expanded
30 \DTLnewdbentry{data}{Definition}{\thisword}%
31 }%
32 }
33 \makeatother
34
35 \newword{High Water}
36 \newword{!}
37 \newword{[}
38 \newword{~}
39 \newword{\#define}
40 \newword{High water}
41 \newword{highwater}
42 \newword{1st Street}
43 \newword{high water}
44 \newword{1st~Street}
45 \newword{10~Downing Street}
46 \newword{10~Downing Avenue}
47 \newword{10 Downing Road}
48 \newword{\#include}
49 \newword{1 (one)}
50 \newword{1\datatoolparenstart(one)}
51 \newword{10\datatoolparenstart(ten)}
52 \newword{10 (ten)}
53 \newword{42\datatoolparenstart(forty-two)}
54 \newword{42 (forty-two)}
55 \newword{100\datatoolparenstart(one hundred)}
56 \newword{100 (one hundred)}
57 \newword{4\datatoolparenstart(four)}
58 \newword{4 (four)}
59 \newword{The Ten Samurai}
60 \newword{London, Jack}
61 \newword{London}
62 \newword{10 Samurai, The}
63 \newword{10 Samurai}
64 \newword{Ten Samurai, The}
65 \newword{Ten Samurai}
66 \newword{10 Samurai\datatoolsubjectcomma The}
67 \newword{Ten Samurai\datatoolsubjectcomma The}
68 \newword{London\datatoolpersoncomma Jack}
69 \newword{London\datatoolplacecomma UK}
70 \newword{London\datatoolsubjectcomma History of}
71 \newword{Zebra}
72 \newword{zebra}
73 \newword{alpha}
74 \newword{Alpha}
75 \newword{seal}
76 \newword{sea lion}
77 \newword{elephant}
78 \newword{Élite}
79
80 \begin{document}
81 This is a sample document testing datatool's comparison
82 handlers. Note that UTF-8 characters are treated as two tokens
83 (the first and second octets) with regular (pdf)\LaTeX, so the
84 definition column on the following pages shows the two octets
85 for the UTF-8 character É as ÃĽ, which is how \LaTeX\ sees them. XeLaTeX will treat it as a single
86 token.
87
88 \newpage
89
90 \section{Unsorted data}
91
92 \begin{tabular}{ll}
93 \bfseries Word & \bfseries Definition
94 \DTLforeach*{data}{\Word=Word,\Definition=Definition}{%
95 \\\Word & \ttfamily \Definition
96 }
97 \end{tabular}
98
99 \section{Case-Insensitive Sort}
100
101 \DTLsort*{Word}{data}
102
103 \begin{tabular}{ll}
104 \bfseries Word & \bfseries Definition
105 \DTLforeach*{data}{\Word=Word,\Definition=Definition}{%
106 \\\Word & \ttfamily \Definition
107 }
108 \end{tabular}
109
110
111 \section{Case-Sensitive Sort}
112
113 \DTLsort{Word}{data}
114
115 \begin{tabular}{ll}
116 \bfseries Word & \bfseries Definition
117 \DTLforeach*{data}{\Word=Word,\Definition=Definition}{%
118 \\\Word & \ttfamily \Definition
119 }
120 \end{tabular}
121
122 \section{Word-Order Sort}
123
124 \dtlsort{Word}{data}{\dtlwordindexcompare}
125
126 \begin{tabular}{ll}
127 \bfseries Word & \bfseries Definition
128 \DTLforeach*{data}{\Word=Word,\Definition=Definition}{%
129 \\\Word & \ttfamily \Definition
130 }
131 \end{tabular}
132
133 \end{document}