# How to make a reverse dictionary via glossaries package?

I want to compile an new English terms on my proffesional field collections. It's much like a dictionary but in reverse sort of words for learning convenience, e.g.

...
romance ...
...(other words whose root is "-ance")
science ...
...
romantic ...
...
Titantic ...
...
scientific ...


I am going to write the words as follow

\newglossaryentry{romantic}{name=romantic,
description={(corresponding paraphrase)}
}


but can't find any sort option fit my demand. Please give me a hand.

-
Please repost your question here again in full. Posts on TeX.SX must be mostly self-contained. Thanks. –  Martin Scharrer Apr 6 '11 at 10:45
…and with a more descriptive title. –  Will Robertson Apr 6 '11 at 12:17
I've pasted in the text there, but it's still not clear to me what the question is after. This example doesn't make clear how this kind of index differs from a dictionary. –  Charles Stewart Apr 6 '11 at 13:13
It sounds as if the words should be sorted depending on their endings (-ance, -tic). I think this could be only done if one add a sensible sort key to each entry. –  Ulrike Fischer Apr 6 '11 at 13:36
I understand your question. It seems you can use a quick fix with some scripting, for the .glo file. To convert \glossaryentry{abc?blah blah} to \glossaryentry{cba?blah blah}. It won't be very difficult to implement with awk, perl, etc. –  Leo Liu Apr 6 '11 at 15:51

If I understand you right you want to compile a dictionary based on some kind of two-level sorting procedure: Firstly, group the words according to a set of predefined suffixes (such as "antic" in romantic or semantic) and sort the groups; secondly, sort the words of each group.

You can do this using the tools of the xstring package:

\documentclass{article}

\usepackage{xstring}
\usepackage{glossaries}


Define an appropriate wrapper around the \newglossaryentry command provided by the glossaries package:

\newcommand*{\mynewglossaryentry}[2]{%
\bgroup%
\StrBefore{#1}{-}[\root]%
\StrBehind{#1}{-}[\suffix]%
\StrExpand{{\root\suffix}{name=\root\suffix, description={#2}, sort=\suffix\root}}{\keyvallist}%
\expandafter\newglossaryentry\keyvallist%
\egroup%
}


Now, define dictionary entries as follows:

\mynewglossaryentry{sem-antic}{description of semantic}
\mynewglossaryentry{rom-antic}{description of romantic}
\mynewglossaryentry{immin-ence}{description of imminence}
\mynewglossaryentry{depend-ence}{description of dependence}
\mynewglossaryentry{immin-ent}{description of imminent}
\mynewglossaryentry{depend-ent}{description of dependent}

\makeglossaries


The hyphen in the first argument of \mynewglossaryentry is solely used to indicate the suffixes controlling first-level sorting. It will not show up in the dictionary. Moreover, it is not part of the label of a dictionary entry—the label is the word itself:

\begin{document}

\noindent
\gls{semantic}, \gls{romantic}, \gls{imminence}, \gls{dependence}, \gls{imminent}, \gls{dependent}

\printglossary[style=listgroup]

\end{document}


The resulting output is:

-