Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How to define a style file that adds a couple of extra letters to the latin alphabet, and the corresponding lettergroups?

I'm using the index package, and compiling the .idx files with texindy like this:

texindy -o book.main.ind -L english -M lang/english/utf8 -M style1 book.main.idx

I'm working on an index that has words from the Pāḷi language, such as ānāpānasati, saṃsāra, ñāṇavimutti.

The \index commands give these word using the TeX accents, so in the text the above words would be indexed with:

\index[general]{\=an\=ap\=anasati}
\index[general]{sa\d{m}s\=ara}
\index[general]{\~n\=a\d{n}avimutti}

I tried adding the letter groups, but the ā, ñ, etc. letters don't begin new groups, they are just included under the latin letters a, n, etc.

(define-letter-group "ā" :after "a" :before "b")
(define-letter-group "ñ" :after "n" :before "o")

(merge-rule "\=a" "ā" :string)
(merge-rule "\={a}" "ā" :string)
(merge-rule "\d{m}" "ṃ" :string)
(merge-rule "\d {m}" "ṃ" :string)
(merge-rule "\~n" "ñ" :string)
(merge-rule "\~ n" "ñ" :string)
share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

Longer post

I have prepared two versions for Pāḷi language to be used by xindy: general one (English sorting rules plus several new letters and a portion of sorting rules from Pāḷi) and a minimal one (for Pāḷi language only).

I am running examples with lualatex, those work with xelatex too. The engines use Latin Modern for typesetting. Several phonetic letters weren't rendered correctly, so I used Code2000 font. If you want to run pdflatex, please, consider to use iec2utf, that's a Lua script programmed by michal-h21.

I have used several resources (listed below) to get Pāḷi words as test cases. In case I misspelled some of them, I am sorry for that.


To 1. General version (Sorting rules of some Western languages plus Pāḷi)

I wanted to make sure that not only letters will be added but also that Pāḷi words will be sorted properly. I have extracted new letters from http://www.omniglot.com/writing/pali.htm and http://en.wikipedia.org/wiki/Pali. Moreover, I've also kept in mind this file http://pratyeka.org/narada/pali_alphabets.pdf and I've added several phonetic symbols to the alphabet as an experiment if Xindy can handle that (it can).

I have downloaded and installed Code2000 font to make sure that all letters, especially those uncommon ones, will be displayed correctly.

I enclose a list of 36 letter groups:

% run: lualatex or xelatex typeset-paligeneral.tex
% Alphabet has 36 elements.
\documentclass[a4paper]{article}
\pagestyle{empty}
%\usepackage{luatextra}
%\usepackage{xltxtra}
\newenvironment{alphabet}{\begin{tabular}{*{16}{l}}}{\end{tabular}}
\addtolength{\voffset}{-0.5in}
\addtolength{\textheight}{2in}
\usepackage{fontspec}
% http://web.archive.org/web/20101122142710/http://code2000.net/code2000_page.htm
\setmainfont{Code2000}

\begin{document}
\section{Paligeneral}
\subsection{Alphabet}
\begin{alphabet}
a\,A & á\,Á & à\,À & ă\,Ă & â\, & ã\,à & ä\,Ä & ą\,Ą & å\,Å & æ\,Æ & ǽ\,Ǽ\\
ā\,Ā\\
b\,B\\
c\,C & ć\,Ć & ĉ\,Ĉ & ç\,Ç & č\,Č\\
d\,D & ð\,ð & đ\,đ & ď\,Ď\\
ḍ\,Ḍ & ɖ\,Ɖ\\
e\,E & é\,É & è\,È & ě\,Ě & ê\,Ê & ë\,Ë & ę\,Ę & þ\,Þ\\
f\,F\\
g\,G & ĝ\,Ĝ & ğ\,Ğ\\
h\,H & ĥ\,Ĥ & ı\,I\\
i\,I & í\,Í & ì\,Ì & î\,Î & ï\,Ï\\
ī\,Ī\\
j\,J & ĵ\,Ĵ\\
k\,K\\
l\,L & ĺ\,Ĺ & ł\,Ł & ľ\,Ľ\\
ḷ\,Ḷ & ɭ\,ɭ\\
m\,M\\
ṃ\,Ṃ & ŋ\,Ŋ & ɱ\,ɱ\\
n\,N & ń\,Ń & ň\,Ň\\
ṅ\,Ṅ & ɲ\,Ɲ\\
ñ\,Ñ\\
ṇ\,Ṇ & ɳ\,ɳ\\
o\,O & ó\,Ó & ő\,Ő & ò\,Ò & ö\,Ö & ø\,Ø & ǿ\,Ǿ & ô\,Ô & õ\,Õ & œ\,Œ\\
p\,P\\
q\,Q\\
r\,R & ŕ\,Ŕ & ř\,Ř\\
s\,S & ś\,Ś & ŝ\,Ŝ & ş\,Ş & š\,Š\\
t\,T & ť\,Ť\\
ṭ\,Ṭ & ʈ\,Ʈ\\
u\,U & ú\,Ú & ù\,Ù & ŭ\,Ŭ & ů\,Ů & û\,Û & ü\,Ü & ű\,Ű\\
ū\,Ū\\
v\,V\\
w\,W\\
x\,X\\
y\,Y & ý\,Ý & ÿ\,Ÿ\\
z\,Z & ź\,Ź & ż\,Ż & ž\,Ž
\end{alphabet}

\subsection{Ligatures}
\begin{flushleft}
`ß' is sorted like `s\,s', but \emph{after} it in otherwise equal words.
\end{flushleft}

\subsection{Upper-/lowercase words}
Capitalized or uppercase words are sorted \emph{before} otherwise equal lowercase words.

\subsection{Special characters}
The order of special characters and letters is:
\begin{flushleft}
?\hspace{4mm}!\hspace{4mm}.\hspace{4mm}letters\hspace{4mm}-\hspace{4mm}'
\end{flushleft}

\end{document}

mwe, general version, list of letters

Usage

Please download these two files to your working directory:

wget http://striz7.fame.utb.cz/tex-sx/pi/utf8.pl-paligeneral.in.xdy  
wget http://striz7.fame.utb.cz/tex-sx/pi/utf8.pl-paligeneral.in-test.xdy  

We run these three lines on the first example (mal-paligeneral.tex):

lualatex mal-paligeneral.tex
xindy -M texindy -M utf8.pl-paligeneral.in-test -M bonus mal-paligeneral.idx
lualatex mal-paligeneral.tex

If you wish to check out the vector versions, please download:

wget http://striz7.fame.utb.cz/tex-sx/pi/typeset-paligeneral.pdf
wget http://striz7.fame.utb.cz/tex-sx/pi/mal-paligeneral.pdf

This is the content of the TeX file, I will enclose a preview of it at the end of this post so we can compare those two versions.

% run: lualatex or xelatex mal-paligeneral.tex
% uncomment line 9 or 10, respectively
%
%lualatex mal-paligeneral.tex
%xindy -M texindy -M utf8.pl-paligeneral.in-test -M bonus mal-paligeneral.idx
%lualatex mal-paligeneral.tex
%
\documentclass[a4paper]{article}
\usepackage{luatextra} % for lualatex engine
%\usepackage{xltxtra} % for xelatex engine
\pagestyle{empty}
\usepackage{makeidx}
\makeindex
\usepackage[colorlinks]{hyperref}
\usepackage{filecontents}
\begin{filecontents*}{bonus.xdy}
(markup-letter-group :open-head "~n  \textbf{" :close-head "}")
\end{filecontents*}

\begin{document}
Regular text.
\index{pāḷi}
\index{ānāpānasati}
\index{saṃsāra}
\index{ñāṇavimutti}
% Pali Buddhist Dictionary
\index{insight}
\index{paññā}
\index{vipassanā}
\index{ñāṇa}
\index{nirvāṇa}
\index{nibbāna}
\index{permanency}
%\index{vipallāsa}
%\index{personality}
%\index{sakkāya}
%\index{diṭṭhi}
% sortedCanonList.txt
\index{aādiparokkhāyañca}
\index{sammāyojitajālavāta}
\index{ṃsati}
\index{ḷukhappa}
\index{homaidaṃ}
\index{sumanosmīti}
\index{sāmākanīvāre}
\index{vīriyārambhassa}
\index{jeṭṭhasissa}
\index{ñattikammavācāpi}
\index{ñattikammaṃ}
\index{ārammaṇamariyādā}
\index{aāgamo}
\begingroup
\def\thispagestyle#1{}
\printindex
\endgroup
\end{document}

To 2. Minimal version (Pāḷi language only)

This is a list of 41 letter groups used in the alphabet.

% run: lualatex or xelatex typeset-paliminimal.tex
% Alphabet has 41 elements.
\documentclass[a4paper]{article}
\pagestyle{empty}
%\usepackage{luatextra}
%\usepackage{xltxtra}
\newenvironment{alphabet}{\begin{tabular}{*{16}{l}}}{\end{tabular}}
\addtolength{\voffset}{-0.75in}
\addtolength{\textheight}{2in}
\usepackage{fontspec}
% http://web.archive.org/web/20101122142710/http://code2000.net/code2000_page.htm
\setmainfont{Code2000}

\begin{document}
\section{Paliminimal}
\subsection{Alphabet}
\begin{alphabet}
a\,A\\
ā\,Ā\\
i\,I\\
ī\,Ī\\
u\,U\\
ū\,Ū\\
e\,E\\
o\,O\\
k\,K\\
kh\,Kh\,KH\\
g\,G\\
gh\,Gh\,GH\\
ṅ\,Ṅ & ɲ\,Ɲ\\
c\,C\\
ch\,Ch\,CH\\
j\,J\\
jh\,Jh\,JH\\
ñ\,Ñ\\
ṭ\,Ṭ & ʈ\,Ʈ\\
ṭh\,Ṭh\,ṬH\\
ḍ\,Ḍ & ɖ\,Ɖ\\
ḍh\,Ḍh\,ḌH\\
ṇ\,Ṇ & ɳ\,ɳ\\
t\,T\\
th\,Th\,TH\\
d\,D\\
dh\,Dh\,DH\\
n\,N\\
p\,P\\
ph\,Ph\,PH\\
b\,B\\
bh\,Bh\,BH\\
m\,M\\
y\,Y\\
r\,R\\
l\,L\\
v\,V\\
s\,S\\
h\,H\\
ḷ\,Ḷ & ɭ\,ɭ\\
ṃ\,Ṃ & ŋ\,Ŋ & ɱ\,ɱ
\end{alphabet}
\subsection{Ligatures}
\begin{flushleft}
`ß' is sorted like `s\,s', but \emph{after} it in otherwise equal words.
\end{flushleft}
\subsection{Upper-/lowercase words}
Capitalized or uppercase words are sorted \emph{before} otherwise equal lowercase words.
\subsection{Special characters}
The order of special characters and letters is:
\begin{flushleft}
?\hspace{4mm}!\hspace{4mm}.\hspace{4mm}letters\hspace{4mm}-\hspace{4mm}'
\end{flushleft}
\end{document}

mwe, part 2, minimal version

Usage

Please download these two files:

wget http://striz7.fame.utb.cz/tex-sx/pi/utf8.pl-paliminimal.in.xdy
wget http://striz7.fame.utb.cz/tex-sx/pi/utf8.pl-paliminimal.in-test.xdy

We run these three lines (the terms are identical to those used in the first example for comparison reasons):

lualatex mal-paliminimal.tex
xindy -M texindy -M utf8.pl-paliminimal.in-test -M bonus mal-paliminimal.idx
lualatex mal-paliminimal.tex

If you would like to check out the vector versions, the PDF files can be downloaded as follows:

wget http://striz7.fame.utb.cz/tex-sx/pi/typeset-paliminimal.pdf
wget http://striz7.fame.utb.cz/tex-sx/pi/mal-paliminimal.pdf

This is the content of the second TeX file and a preview of both versions is enclosed. The general version can be seen on left, the minimal version is the column of words on right.

% run: lualatex or xelatex mal-paliminimal.tex
% uncomment line 9 or 10, respectively
%
%lualatex mal-paliminimal.tex
%xindy -M texindy -M utf8.pl-paliminimal.in-test -M bonus mal-paliminimal.idx
%lualatex mal-paliminimal.tex
%
\documentclass[a4paper]{article}
\usepackage{luatextra} % for lualatex engine
%\usepackage{xltxtra} % for xelatex engine
\pagestyle{empty}
\usepackage{makeidx}
\makeindex
\usepackage[colorlinks]{hyperref}
\usepackage{filecontents}
\begin{filecontents*}{bonus.xdy}
(markup-letter-group :open-head "~n  \textbf{" :close-head "}")
\end{filecontents*}

\begin{document}
Regular text.
\index{pāḷi}
\index{ānāpānasati}
\index{saṃsāra}
\index{ñāṇavimutti}
% Pali Buddhist Dictionary
\index{insight}
\index{paññā}
\index{vipassanā}
\index{ñāṇa}
\index{nirvāṇa}
\index{nibbāna}
\index{permanency}
%\index{vipallāsa}
%\index{personality}
%\index{sakkāya}
%\index{diṭṭhi}
% sortedCanonList.txt
\index{aādiparokkhāyañca}
\index{sammāyojitajālavāta}
\index{ṃsati}
\index{ḷukhappa}
\index{homaidaṃ}
\index{sumanosmīti}
\index{sāmākanīvāre}
\index{vīriyārambhassa}
\index{jeṭṭhasissa}
\index{ñattikammavācāpi}
\index{ñattikammaṃ}
\index{ārammaṇamariyādā}
\index{aāgamo}
\begingroup
\def\thispagestyle#1{}
\printindex
\endgroup
\end{document}

This is a preview of indices, both versions (general version on left, minimal version on right)

share|improve this answer
add comment

Gotcha!

So in the preamble of our .tex source, we say

\usepackage{index}
\newindex{general}{general-idx}{general-ind}{General Index}

In the text, we define the index entries in this fashion:

\index[general]{\=an\=ap\=anasati}
\index[general]{sa\d{m}s\=ara}
\index[general]{\~n\=a\d{n}avimutti}

When we compile the .tex document, we will get our book.main.general-idx file, which we have to process with xindy.

The main problem is that texindy loads many .xdy modules before it gets to our custom style1.xdy.

We have to invoke xindy directly, with an extended style1.xdy, that only defines what we need to be defined.

So I opened the modules (/usr/share/xindy/...) which texindy walks through as reported in its output,

Opening logfile "/dev/null" (done)
Reading indexstyle...
Loading module "/tmp/1DxWUsIHQG"...
Loading module "lang/english/latin9-lang.xdy"...
Loading module "lang/english/latin9.xdy"...
Finished loading module "lang/english/latin9.xdy".
Finished loading module "lang/english/latin9-lang.xdy".
Loading module "tex/inputenc/latin.xdy"...
Finished loading module "tex/inputenc/latin.xdy".
Loading module "texindy.xdy"...
Loading module "numeric-sort.xdy"...
Finished loading module "numeric-sort.xdy".
Loading module "latex.xdy"...
Loading module "tex.xdy"...
Finished loading module "tex.xdy".
Finished loading module "latex.xdy".
Loading module "latex-loc-fmts.xdy"...
Finished loading module "latex-loc-fmts.xdy".
Loading module "makeindex.xdy"...
Finished loading module "makeindex.xdy".
Loading module "latin-lettergroups.xdy"...
Finished loading module "latin-lettergroups.xdy".
Finished loading module "texindy.xdy".
Loading module "page-ranges.xdy"...
Finished loading module "page-ranges.xdy".
Loading module "word-order.xdy"...
Finished loading module "word-order.xdy".
Loading module "lang/english/utf8.xdy"...
WARNING: define-letter-group: prefix "�" now maps to letter group "Þ"
Finished loading module "lang/english/utf8.xdy".
Loading module "book-order.xdy"...
Finished loading module "book-order.xdy".
Finished loading module "/tmp/1DxWUsIHQG".
Finished reading indexstyle.
Finalizing indexstyle... (done)

Reading raw-index "/tmp/4o3huWTPhU"...
Finished reading raw-index.

Processing index... [10%] [20%] [30%] [40%] [50%] [60%] [70%] [80%] [90%] [100%]
Finished processing index.

Writing markup... [10%] [20%] [30%] [40%] [50%] [60%] [70%] [80%] [90%] [100%]
Markup written into file "book.main.general-ind".

And copied the necessary parts to style1.xdy, extending the definitions for the Pali letters where necessary. In the file below, the latin alpabet is extended with the letters ā, ī, ṃ, ñ. There's more in Pali, but this will do for now.

style1.xdy:

;; xindy style file for an index with extended alphabet

(define-attributes (("default" "textbf" "textit" "hyperpage")))

;; "see" and "see also"

(define-crossref-class "see")
(markup-crossref-list :class "see" :open "\see{" :sep "; " :close "}{}")
(define-crossref-class "seealso")
(markup-crossref-list :class "seealso" :open "\seealso{" :sep "; " :close "}{}")

(markup-crossref-layer-list :sep ", ")

(require "base/numeric-sort.xdy")

(define-location-class "arabic-page-numbers" ("arabic-numbers"))
(define-location-class "roman-page-numbers"  ("roman-numbers-lowercase"))
(define-location-class "Roman-page-numbers"  ("roman-numbers-uppercase"))
(define-location-class "alpha-page-numbers"  ("alpha"))
(define-location-class "Alpha-page-numbers"  ("ALPHA"))

(define-location-class-order ("roman-page-numbers"
                  "Roman-page-numbers"
                  "arabic-page-numbers"
                  "alpha-page-numbers"
                  "Alpha-page-numbers"
                  "see"
                  "seealso"))

(require "lang/english/utf8.xdy")

(define-alphabet "latin-pali"
("a" "ā" "b" "c" "d" "e" "f" "g" "h" "i" "ī" "j" "k" "l" "m" "ṃ" "n" "ñ" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"))
(define-letter-groups
("a" "ā" "b" "c" "d" "e" "f" "g" "h" "i" "ī" "j" "k" "l" "m" "ṃ" "n" "ñ" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"))

;; =======================
;; merge rules
;; =======================

;; for the pali words

;; TODO: some variations of the TeX accent markups could be combined using an :eregexp instead of :string replacements

(merge-rule "\=a" "ā" :string)
(merge-rule "\={a}" "ā" :string)
(merge-rule "\=A" "Ā" :string)
(merge-rule "\={A}" "Ā" :string)
(merge-rule "\={\i}" "ī" :string)
(merge-rule "\={\i }" "ī" :string)
(merge-rule "\d{m}" "ṃ" :string)
(merge-rule "\d {m}" "ṃ" :string)
(merge-rule "\~~n" "ñ" :string)
(merge-rule "\~~ n" "ñ" :string)

;; LaTeX and TeX conventions

(merge-rule "\\LaTeXe *" "LaTeX2e" :eregexp :again)
(merge-rule "\\BibTeX *" "BibTeX" :eregexp :again)
(merge-rule "\\AmSTeX *" "AmSTeX" :eregexp :again)
(merge-rule "\\AmSLaTeX *" "AmSLaTeX" :eregexp :again)
(merge-rule "\\XeT *" "XeT" :eregexp :again)

(require "base/tex.xdy")

(markup-locref :open "\textbf{" :close "}" :attr "textbf")
(markup-locref :open "\textit{" :close "}" :attr "textit")
(markup-locref :open "\hyperpage{" :close "}" :attr "hyperpage")

;; =======================
;; sort rules
;; =======================

;; list pali capitals under pali lowercase

(sort-rule "Ā" "ā")
(sort-rule "Ṃ" "ṃ")
(sort-rule "Ī" "ī")
(sort-rule "Ñ" "ñ")

;; list latin capitals under latin lowercase

(sort-rule "A" "a")
(sort-rule "B" "b")
(sort-rule "C" "c")
(sort-rule "D" "d")
(sort-rule "E" "e")
(sort-rule "F" "f")
(sort-rule "G" "g")
(sort-rule "H" "h")
(sort-rule "I" "i")
(sort-rule "J" "j")
(sort-rule "K" "k")
(sort-rule "L" "l")
(sort-rule "M" "m")
(sort-rule "N" "n")
(sort-rule "O" "o")
(sort-rule "P" "p")
(sort-rule "Q" "q")
(sort-rule "R" "r")
(sort-rule "S" "s")
(sort-rule "T" "t")
(sort-rule "U" "u")
(sort-rule "V" "v")
(sort-rule "W" "w")
(sort-rule "X" "x")
(sort-rule "Y" "y")
(sort-rule "Z" "z")

;; ======================
;; markup rules
;; ======================

(require "base/page-ranges.xdy")

(markup-index :open
"\begin{theindex}
  \providecommand*\lettergroupDefault[1]{}
  \providecommand*\lettergroup[1]{%
      \par\textbf{#1}\par
      \nopagebreak
  }
"
          :close "~n~n\end{theindex}~n"
          :tree)

(markup-indexentry :open "~n  \item "           :depth 0)
(markup-indexentry :open "~n    \subitem "      :depth 1)
(markup-indexentry :open "~n      \subsubitem " :depth 2)

(markup-locclass-list :open ", " :sep ", ")
(markup-locref-list   :sep ", ")

;; letter group markup

(markup-letter-group-list :sep "~n~n  \indexspace~n")

(markup-letter-group :open-head "~n  \lettergroupDefault{" :close-head "}" :group "default")
(markup-letter-group :open-head "~n  \lettergroup{" :close-head "}")

If we now invoke xindy with

xindy -I latex -o book.main.general-ind -M style1 book.main.general-idx

We will get the ind file as below, with the extra lettergroups, which we can use with \printindex[general] in the appropriate place in the .tex document.

  \lettergroup{a}
  \item abiding, \hyperpage{33}
  \item absorption
    \subitem in daily activities, \hyperpage{132}
  \item accomplishments
    \subitem worldly, \hyperpage{66}

  \indexspace

  \lettergroup{ā}
  \item \=acariya, \hyperpage{96}
  \item \=Al\=ara K\=al\=ama, \hyperpage{51}

  \indexspace

...

  \lettergroup{n}
  \item names, \hyperpage{21}, \hyperpage{23}, \hyperpage{183}
  \item nature
    \subitem existing according to, \hyperpage{69}
  \item nibb\=ana, \hyperpage{32}, \hyperpage{33}
    \subitem causes of, \hyperpage{76}
    \subitem meaning of, \hyperpage{54}
  \item nimitta, \hyperpage{41}

  \indexspace

  \lettergroup{ñ}
  \item \~n\=ayapa\d {t}ipanno
    \subitem those who practice for realisation of the path, \hyperpage{58}

...

May this be for the happiness of many TeXnicians.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.