1;;; -*- mode: lisp; coding: utf-8; -*-
2
3;; Unfortunately xindy is out-of-the-box hyperref-incompatible.  This
4;; configuration is a workaround, which requires to pass option
5;; hyperindex=false to hyperref.
6;; textit and emph not currently used, spxpagem replaces former textbf
7(define-attributes (("textbf" "textit" "emph" "spxpagem" "default")))
8(markup-locref :open "\textbf{\hyperpage{" :close "}}" :attr "textbf")
9(markup-locref :open "\textit{\hyperpage{" :close "}}" :attr "textit")
10(markup-locref :open "\emph{\hyperpage{" :close "}}" :attr "emph")
11(markup-locref :open "\spxpagem{\hyperpage{" :close "}}" :attr "spxpagem")
12(markup-locref :open "\hyperpage{" :close "}" :attr "default")
13
14(require "numeric-sort.xdy")
15
16;; xindy base module latex.xdy loads tex.xdy and the latter instructs
17;; xindy to ignore **all** TeX macros in .idx entries, except those
18;; explicitely described in merge rule.  But when after applying all
19;; merge rules an empty string results, xindy raises an error:
20
21;;   ERROR: CHAR: index 0 should be less than the length of the string
22
23;; For example when using pdflatex with utf-8 characters the index
24;; file will contain \IeC macros and they will get ignored except if
25;; suitable merge rules are loaded early.  The texindy script coming
26;; with xindy provides this, but only for Latin scripts.  The texindy
27;; man page says to use rather xelatex or lualatex in case of Cyrillic
28;; scripts.
29
30;; Sphinx contributes LICRcyr2utf8.xdy to provide support for Cyrillic
31;; scripts for the pdflatex engine.
32
33;; Another issue caused by xindy ignoring all TeX macros except those
34;; explicitely declared reveals itself when attempting to index ">>>",
35;; as the ">" is converted to "\textgreater{}" by Sphinx's LaTeX
36;; escaping.
37
38;; To fix this, Sphinx does **not** use texindy, and does not even
39;; load the xindy latex.xdy base module.
40
41;(require "latex.xdy")
42
43;; Rather it incorporates some suitable extracts from latex.xdy and
44;; tex.xdy with additional Sphinx contributed rules.
45
46;; But, this means for pdflatex and Latin scripts that the xindy file
47;; tex/inputenc/uf8.xdy is not usable because it refers to the macro
48;; \IeC only sporadically, and as tex.xdy is not loaded, a rule such as
49;;     (merge-rule "\'e" "é" :string)
50;; does not work, it must be
51;;     (merge-rule "\IeC {\'e}" "é" :string)
52;; So Sphinx contributes LICRlatin2utf8.xdy to mitigate that problem.
53
54;;;;;;;; extracts from tex.xdy (discarding most original comments):
55
56;;;
57;;; TeX conventions
58;;;
59
60;; Discard leading and trailing white space. Collapse multiple white
61;; space characters to blank.
62
63(merge-rule "^ +" "" :eregexp)
64(merge-rule " +$" "" :eregexp)
65(merge-rule "  +" " " :eregexp)
66
67;; Handle TeX markup
68
69(merge-rule "\\([{}$%&#])" "\1" :eregexp)
70
71;;;;;;;; end of extracts from xindy's tex.xdy
72
73;;;;;;;; extracts from latex.xdy:
74
75;; Standard location classes: arabic and roman numbers, and alphabets.
76
77(define-location-class "arabic-page-numbers" ("arabic-numbers"))
78(define-location-class "roman-page-numbers"  ("roman-numbers-lowercase"))
79(define-location-class "Roman-page-numbers"  ("roman-numbers-uppercase"))
80(define-location-class "alpha-page-numbers"  ("alpha"))
81(define-location-class "Alpha-page-numbers"  ("ALPHA"))
82
83;; Output Markup
84
85(markup-letter-group-list :sep "~n~n  \indexspace~n")
86
87(markup-indexentry :open "~n  \item "           :depth 0)
88(markup-indexentry :open "~n    \subitem "      :depth 1)
89(markup-indexentry :open "~n      \subsubitem " :depth 2)
90
91(markup-locclass-list :open ", " :sep ", ")
92(markup-locref-list   :sep ", ")
93
94;;;;;;;; end of extracts from latex.xdy
95
96;; The LaTeX \index command turns \ into normal character so the TeX macros
97;; written to .idx files are not followed by a blank. This is different
98;; from non-ascii letters which end up (with pdflatex) as \IeC macros in .idx
99;; file, with a blank space after \IeC
100
101;; Details of the syntax are explained at
102;;     http://xindy.sourceforge.net/doc/manual-3.html
103;; In absence of :string, "xindy uses an auto-detection mechanism to decide,
104;; if the pattern is a regular expression or not". But it is not obvious to
105;; guess, for example "\\_" is not detected as RE but "\\P\{\}" is, so for
106;; being sure we apply the :string switch everywhere and do not use \\ etc...
107
108;; Go back from sphinx.util.texescape TeX macros to UTF-8
109
110(merge-rule "\sphinxleftcurlybrace{}" "{" :string)
111(merge-rule "\sphinxrightcurlybrace{}" "}" :string)
112(merge-rule "\_" "_" :string)
113(merge-rule "{[}" "[" :string)
114(merge-rule "{]}" "]" :string)
115(merge-rule "\textbackslash{}" "\" :string)  ; " for Emacs syntax highlighting
116(merge-rule "\textasciitilde{}" "~~" :string); the ~~ escape is needed here
117(merge-rule "\textasciicircum{}" "^" :string)
118(merge-rule "\sphinxhyphen{}" "-" :string)
119(merge-rule "\textquotesingle{}" "'" :string)
120(merge-rule "\textasciigrave{}" "`" :string)
121(merge-rule "\textless{}" "<" :string)
122(merge-rule "\textgreater{}" ">" :string)
123(merge-rule "\P{}" "¶" :string)
124(merge-rule "\S{}" "§" :string)
125(merge-rule "\texteuro{}" "€" :string)
126(merge-rule "\(\infty\)" "∞" :string)
127(merge-rule "\(\pm\)" "±" :string)
128(merge-rule "\(\rightarrow\)" "→" :string)
129(merge-rule "\(\checkmark\)" "✓" :string)
130(merge-rule "\textendash{}" "–" :string)
131(merge-rule "\textbar{}" "|" :string)
132(merge-rule "\(\sp{\text{0}}\)" "⁰" :string)
133(merge-rule "\(\sp{\text{1}}\)" "¹" :string)
134(merge-rule "\(\sp{\text{2}}\)" "²" :string)
135(merge-rule "\(\sp{\text{3}}\)" "³" :string)
136(merge-rule "\(\sp{\text{4}}\)" "⁴" :string)
137(merge-rule "\(\sp{\text{5}}\)" "⁵" :string)
138(merge-rule "\(\sp{\text{6}}\)" "⁶" :string)
139(merge-rule "\(\sp{\text{7}}\)" "⁷" :string)
140(merge-rule "\(\sp{\text{8}}\)" "⁸" :string)
141(merge-rule "\(\sp{\text{9}}\)" "⁹" :string)
142(merge-rule "\(\sb{\text{0}}\)" "₀" :string)
143(merge-rule "\(\sb{\text{1}}\)" "₁" :string)
144(merge-rule "\(\sb{\text{2}}\)" "₂" :string)
145(merge-rule "\(\sb{\text{3}}\)" "₃" :string)
146(merge-rule "\(\sb{\text{4}}\)" "₄" :string)
147(merge-rule "\(\sb{\text{5}}\)" "₅" :string)
148(merge-rule "\(\sb{\text{6}}\)" "₆" :string)
149(merge-rule "\(\sb{\text{7}}\)" "₇" :string)
150(merge-rule "\(\sb{\text{8}}\)" "₈" :string)
151(merge-rule "\(\sb{\text{9}}\)" "₉" :string)
152(merge-rule "\IeC {\textalpha }" "α" :string)
153(merge-rule "\IeC {\textbeta }" "β" :string)
154(merge-rule "\IeC {\textgamma }" "γ" :string)
155(merge-rule "\IeC {\textdelta }" "δ" :string)
156(merge-rule "\IeC {\textepsilon }" "ε" :string)
157(merge-rule "\IeC {\textzeta }" "ζ" :string)
158(merge-rule "\IeC {\texteta }" "η" :string)
159(merge-rule "\IeC {\texttheta }" "θ" :string)
160(merge-rule "\IeC {\textiota }" "ι" :string)
161(merge-rule "\IeC {\textkappa }" "κ" :string)
162(merge-rule "\IeC {\textlambda }" "λ" :string)
163(merge-rule "\IeC {\textmu }" "μ" :string)
164(merge-rule "\IeC {\textnu }" "ν" :string)
165(merge-rule "\IeC {\textxi }" "ξ" :string)
166(merge-rule "\IeC {\textomicron }" "ο" :string)
167(merge-rule "\IeC {\textpi }" "π" :string)
168(merge-rule "\IeC {\textrho }" "ρ" :string)
169(merge-rule "\IeC {\textsigma }" "σ" :string)
170(merge-rule "\IeC {\texttau }" "τ" :string)
171(merge-rule "\IeC {\textupsilon }" "υ" :string)
172(merge-rule "\IeC {\textphi }" "φ" :string)
173(merge-rule "\IeC {\textchi }" "χ" :string)
174(merge-rule "\IeC {\textpsi }" "ψ" :string)
175(merge-rule "\IeC {\textomega }" "ω" :string)
176(merge-rule "\IeC {\textAlpha }" "Α" :string)
177(merge-rule "\IeC {\textBeta }" "Β" :string)
178(merge-rule "\IeC {\textGamma }" "Γ" :string)
179(merge-rule "\IeC {\textDelta }" "Δ" :string)
180(merge-rule "\IeC {\textEpsilon }" "Ε" :string)
181(merge-rule "\IeC {\textZeta }" "Ζ" :string)
182(merge-rule "\IeC {\textEta }" "Η" :string)
183(merge-rule "\IeC {\textTheta }" "Θ" :string)
184(merge-rule "\IeC {\textIota }" "Ι" :string)
185(merge-rule "\IeC {\textKappa }" "Κ" :string)
186(merge-rule "\IeC {\textLambda }" "Λ" :string)
187(merge-rule "\IeC {\textMu }" "Μ" :string)
188(merge-rule "\IeC {\textNu }" "Ν" :string)
189(merge-rule "\IeC {\textTheta }" "Θ" :string)
190(merge-rule "\IeC {\textIota }" "Ι" :string)
191(merge-rule "\IeC {\textKappa }" "Κ" :string)
192(merge-rule "\IeC {\textLambda }" "Λ" :string)
193(merge-rule "\IeC {\textMu }" "Μ" :string)
194(merge-rule "\IeC {\textNu }" "Ν" :string)
195(merge-rule "\IeC {\textXi }" "Ξ" :string)
196(merge-rule "\IeC {\textOmicron }" "Ο" :string)
197(merge-rule "\IeC {\textPi }" "Π" :string)
198(merge-rule "\IeC {\textRho }" "Ρ" :string)
199(merge-rule "\IeC {\textSigma }" "Σ" :string)
200(merge-rule "\IeC {\textTau }" "Τ" :string)
201(merge-rule "\IeC {\textUpsilon }" "Υ" :string)
202(merge-rule "\IeC {\textPhi }" "Φ" :string)
203(merge-rule "\IeC {\textChi }" "Χ" :string)
204(merge-rule "\IeC {\textPsi }" "Ψ" :string)
205(merge-rule "\IeC {\textOmega }" "Ω" :string)
206(merge-rule "\IeC {\textohm }" "Ω" :string)
207
208;; This xindy module provides some basic support for "see"
209(require "makeindex.xdy")
210
211;; This creates one-letter headings and works fine with utf-8 letters.
212;; For Cyrillic with pdflatex works thanks to LICRcyr2utf8.xdy
213(require "latin-lettergroups.xdy")
214
215;; currently we don't (know how to easily) separate "Numbers" from
216;; "Symbols" with xindy as is the case with makeindex.
217(markup-index :open  "\begin{sphinxtheindex}
218\let\lettergroup\sphinxstyleindexlettergroup
219\let\lettergroupDefault\sphinxstyleindexlettergroupDefault
220\let\spxpagem\sphinxstyleindexpagemain
221\let\spxentry\sphinxstyleindexentry
222\let\spxextra\sphinxstyleindexextra
223
224"
225	      :close "
226
227\end{sphinxtheindex}
228"
229	      :tree)
230
231