If we want sorting in index according to the Swedish sorting rules we usually pass -C utf8 -L swedish
to xindy
.
The key problem I found is that we are not able to pass multiple nested parentheses on the input side, the output side, e.g. markup-locref
, is having no difficulties.
So the mentioned strategy is fine, to turn off generating of the second command, \hyperpage
, a command used by the hyperref
package, which is passed to xindy
, otherwise we would need to handle it anyway by external tools.
Our problem splits into two parts: if we use one single command after the @
operator (typeset material) or after the |
operator (index references).
- After the
@
operator I use a new single command where I can use any typeset material, in the following example I pass colors, mathematics, font styles, indentation and other material to the index entry. It is not used for sorting, so xindy
passes it untouched.
- However, if we use the
|
operator, we don't use backslash in the command and we must notify xindy
what it is as it is becoming a part of merging, sorting, grouping, tagging etc. We create our own xdy
file and we use define-attributes
and markup-locref
there. Thanks to the filecontents
package it is easy to have these definitions in the main TeX file.
That solves our two-part problem for most indices. I enclose a simple example and a preview of the first page. I run these three commands to process the example.
lualatex xindyno1.tex
xindy -M texindy -M mal-style -C utf8 -L swedish -o xindyno1.ind xindyno1.idx
lualatex xindyno1.tex
%! lualatex xindyno1.tex
\documentclass{article}
\usepackage{luatextra} % Due to Swedish Ä letter, use inputenc (pdflatex) or fontspec (xelatex) instead.
\usepackage{xcolor}
\usepackage[hyperindex=false,colorlinks]{hyperref}
\usepackage{filecontents}
\usepackage{makeidx}
\makeindex
\begin{document}
\begin{filecontents*}{mal-style.xdy}
(define-attributes (("texttt" "textsc" "myown")) )
(markup-locref :attr "textbf" :open "\textbf{\hyperpage{" :close "}}")
(markup-locref :attr "textit" :open "\textit{\hyperpage{" :close "}}")
(markup-locref :attr "texttt" :open "\texttt{\hyperpage{" :close "}}")
(markup-locref :attr "textsc" :open "\textsc{\hyperpage{" :close "}}")
(markup-locref :attr "myown" :open "\myown{\hyperpage{" :close "}}")
(markup-locref :attr "hyperpage" :open "\hyperpage{" :close "}")
(markup-locref :attr "default" :open "\hyperpage{" :close "}")
\end{filecontents*}
\def\myshift#1{\makebox[0pt][r]{\texttt{--}}\texttt{#1}}
\def\myown#1{{\Huge#1}}
\def\mycommand#1{{\color{green}#1}}
\def\mydef#1{\texttt{\makebox[0pt][r]{\char"5C}#1}}
\def\mymath#1{{\color{blue}$#1$}}
\def\myfavorite#1{{\color{cyan}\makebox[0pt][r]{I $\heartsuit$\ }{\color{cyan}#1}}}
\begingroup % Print index without page number.
\def\thispagestyle#1{}
\pagestyle{empty}
\printindex
\endgroup
\section{My section}\label{mysection}
I refer to my section~\ref{mysection}.
Start. Nunc ligula faucibus\index{xindy|textbf}.
\index{vector@Vector}
\index{runme@\mycommand{runme}}
\index{asquared@\mymath{a^2}}
\index{bsquared@\mymath{b^2}}
\index{csquared@\mymath{c^2}}
\index{roof|myown}
\index{mal@\myshift{mal}}
\index{nature@\textbf{Nature}}
\index{home!my own 1}
\index{home!my own 2}
\index{definition@\mydef{definition}}
\index{Velocity}
Nullarutrum porttitor...
\index{alcohol}\index{beauty}\index{älf}\index{zero}
\newpage
\index{vectors@\myfavorite{vectors}}
\index{roof|myown}
\index{roof}
End.
\end{document}

Next examples of indices
An index is just regular typeset material as any other, usually generated from the idx
file containing many \indexentry
commands to the ind
file, it consists of the theindex
environment with a bunch of commands, typically with many \item
, \indexspace
, \lettergroup
and \lettergroupDefault
, which we can redefine, if needed.
I enclose snapshots of my work. The first example contains glyphs of the specific font which we are referring to (picture on left), the second example contains CJKV glyphs, to be more specific, those are kanjis used in Japanese (picture on right).
