Debian Codegraph @

texmf-dist/doc/latex/datatool/datatool-user-examples/datatool-user-example012.tex

raw
1 % This file is embedded in datatool-user.pdf version 3.4.3 2025-12-04
2 % Example 12 Icelandic Sorting and Letter Groups
3 % Label: "ex:icelandiclettergroup"
4 % arara: pdflatex
5 % arara: pdfcrop
6 \documentclass[12pt]{article}
7 \pagestyle{empty}
8 \usepackage[utf8]{inputenc}
9 \usepackage[T1]{fontenc}
10 \usepackage{datatool-base}
11 \ExplSyntaxOn
12
13 \newcommand{\DTLisLocaleHandler}[1]{
14 \regex_replace_case_all:nN
15 {
16 { Á } { A\cL\x{7f} }
17 { á } { a\cL\x{7f} }
18 { Ð } { D\cL\x{7f} }
19 { ð } { d\cL\x{7f} }
20 { É } { E\cL\x{7f} }
21 { é } { e\cL\x{7f} }
22 { Í } { I\cL\x{7f} }
23 { í } { i\cL\x{7f} }
24 { Ó } { O\cL\x{7f} }
25 { ó } { o\cL\x{7f} }
26 { Ú } { U\cL\x{7f} }
27 { ú } { u\cL\x{7f} }
28 { Ý } { Y\cL\x{7f} }
29 { ý } { y\cL\x{7f} }
30 { Þ } { \cL\x{5b} }
31 { þ } { \cL\x{7b} }
32 { Æ } { \cL\x{5c} }
33 { æ } { \cL\x{7c} }
34 { Ö } { \cL\x{5d} }
35 { ö } { \cL\x{7d} }
36 { ([[:punct:]]+) } { \cO"\1 }
37 }
38 #1
39 }
40
41 \newcommand{\DTLisLocaleGetInitialLetter}[2]{
42 \tl_set:Nn #2 { #1 }
43 \regex_replace_case_all:nN
44 {
45 { A\cL\x{7f} } { Á } { a\cL\x{7f} } { á }
46 { D\cL\x{7f} } { Ð } { d\cL\x{7f} } { ð }
47 { E\cL\x{7f} } { É } { e\cL\x{7f} } { é }
48 { I\cL\x{7f} } { Í } { i\cL\x{7f} } { í }
49 { O\cL\x{7f} } { Ó } { o\cL\x{7f} } { ó }
50 { U\cL\x{7f} } { Ú } { u\cL\x{7f} } { ú }
51 { Y\cL\x{7f} } { Ý } { y\cL\x{7f} } { ý }
52 { \cL\x{5b} } { Þ } { \cL\x{7b} } { þ }
53 { \cL\x{5c} } { Æ } { \cL\x{7c} } { æ }
54 { \cL\x{5d} } { Ö } { \cL\x{7d} } { ö }
55 } #2
56 \exp_args:No \datatool_get_first_letter:nN { #2 } #2
57 }
58
59 \ExplSyntaxOff
60
61 \let\DTLCurrentLocaleWordHandler\DTLisLocaleHandler \let\DTLCurrentLocaleGetInitialLetter\DTLisLocaleGetInitialLetter
62
63 \newcommand{\mylist}{bókstafinn, vera, eða,
64 ég, býsna, þú, vakna, epli, bragðs, aldar, bað, bolli, ýmist, af,
65 óáreiðanleg, bær, dalur, ör, þorn, þau, október, esja, öngull, dæmi, að, yfir,
66 öðrum, orð, detta, áhrif, yngri, óvinur, ætlað}
67 \begin{document}
68 \DTLsortwordlist{\mylist}{\DTLsortletterhandler}
69 \renewcommand{\DTLlistformatitem}[1]{#1 (\DTLsortedletter{#1})}
70 Sorted list: \DTLformatlist{\mylist}.
71 \end{document}