summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/datatool/samples/sample-sort.tex
blob: bce750819dc3c57ca6e0c35a1887b28740cc1b90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
% This file is public domain

\documentclass{article}

\usepackage{datatool}

% Sample database

\DTLnewdb{data}

% Add a word to the database. (The Definition column is provided to
% distinguish the entries when the database is displayed. The
% Definition column is not used by the sort code.)

% Syntax: \newword{string}

\makeatletter
\newcommand*{\newword}[1]{%
  \DTLnewrow{data}%
  \DTLnewdbentry{data}{Word}{#1}%
% Convert word to its definition and add
  {%
    \def\thisword{#1}\@onelevel@sanitize\thisword
    \dtlexpandnewvalue % ensure \theword gets expanded
    \DTLnewdbentry{data}{Definition}{\thisword}%
  }%
}
\makeatother

\newword{High Water}
\newword{!}
\newword{[}
\newword{~}
\newword{\#define}
\newword{High water}
\newword{highwater}
\newword{1st Street}
\newword{high water}
\newword{1st~Street}
\newword{10~Downing Street}
\newword{10~Downing Avenue}
\newword{10 Downing Road}
\newword{\#include}
\newword{1 (one)}
\newword{1\datatoolparenstart(one)}
\newword{10\datatoolparenstart(ten)}
\newword{10 (ten)}
\newword{42\datatoolparenstart(forty-two)}
\newword{42 (forty-two)}
\newword{100\datatoolparenstart(one hundred)}
\newword{100 (one hundred)}
\newword{4\datatoolparenstart(four)}
\newword{4 (four)}
\newword{The Ten Samurai}
\newword{London, Jack}
\newword{London}
\newword{10 Samurai, The}
\newword{10 Samurai}
\newword{Ten Samurai, The}
\newword{Ten Samurai}
\newword{10 Samurai\datatoolsubjectcomma The}
\newword{Ten Samurai\datatoolsubjectcomma The}
\newword{London\datatoolpersoncomma Jack}
\newword{London\datatoolplacecomma UK}
\newword{London\datatoolsubjectcomma History of}
\newword{Zebra}
\newword{zebra}
\newword{alpha}
\newword{Alpha}
\newword{seal}
\newword{sea lion}

\begin{document}

\section{Unsorted data}

\begin{tabular}{ll}
\bfseries Word & \bfseries Definition
\DTLforeach*{data}{\Word=Word,\Definition=Definition}{%
\\\Word & \ttfamily \Definition
}
\end{tabular}

\section{Case-Insensitive Sort}

\DTLsort*{Word}{data}

\begin{tabular}{ll}
\bfseries Word & \bfseries Definition
\DTLforeach*{data}{\Word=Word,\Definition=Definition}{%
\\\Word & \ttfamily \Definition
}
\end{tabular}


\section{Case-Sensitive Sort}

\DTLsort{Word}{data}

\begin{tabular}{ll}
\bfseries Word & \bfseries Definition
\DTLforeach*{data}{\Word=Word,\Definition=Definition}{%
\\\Word & \ttfamily \Definition
}
\end{tabular}

\section{Word-Order Sort}

\dtlsort{Word}{data}{\dtlwordindexcompare}

\begin{tabular}{ll}
\bfseries Word & \bfseries Definition
\DTLforeach*{data}{\Word=Word,\Definition=Definition}{%
\\\Word & \ttfamily \Definition
}
\end{tabular}

\end{document}