% % Copyright (C) 1998-2019 Javier Bezos http://www.texnia.com % % This file may be distributed and/or modified under the conditions of % the MIT License. A version can be found at the end of this file. % % Repository: https://github.com/jbezos/esindex % \ProvidesPackage{esindex}[2019/10/10 v1.7 Spanish indexes (and more)] \def\esx@level{`\!} \def\esx@actual{`\@} \def\esx@encap{`\|} \def\esx@quote{`\"} \DeclareOption{ignorespaces}{% \def\esx@zapspace#1\esx@zapspace{\zap@space#1 \@empty}} \DeclareOption{replaceindex}{% \AtBeginDocument{% \let\esx@trueindex\index \let\index\esindex}} \DeclareOption{nospanish}{\esx@spanishfalse} \newif\ifesx@babel \DeclareOption{babel}{% \let\esindexlanguage\foreignlanguage \esx@babeltrue} \DeclareOption*{% \@expandtwoargs\in@{=}{\CurrentOption}% \ifin@ \expandafter\esx@process\CurrentOption\esx@process \else \esx@error \fi} \def\esx@process#1=#2\esx@process{% \@ifundefined{esx@#1}{\esx@error}{% \expandafter\edef\csname esx@#1\endcsname {\string`\expandafter\noexpand\csname\string#2\endcsname}}} \def\esx@error{\PackageError{esindex}{Unknown index parameter}% {Except for ignorespaces, nospanish, babel, replaceindex, ^^J% options in this package ave the form parameter=value, where^^J% parameter stands for of the following MakeIndex ones:^^J% encap, level, actual, quote}} \newif\ifesx@spanish \esx@spanishtrue \let\esx@spanishaccents\relax \let\esx@spanishquotes\relax \let\esx@zapspace\@empty \def\esx@trueindex{\index} \ProcessOptions \begingroup \catcode`\|=\catcode\esx@encap \lccode`\|=\esx@encap\relax \catcode`\!=\catcode\esx@level \lccode`\!=\esx@level\relax \catcode`\&=\catcode\esx@actual \lccode`\&=\esx@actual\relax \catcode`\*=13 \lccode`\*=\esx@quote\relax \catcode`\'=13 \catcode`\"=13 \catcode`\~=13 \catcode`\^^A=12 \gdef\esindex#1#{\esx@index{#1}} \lowercase{ \gdef\esx@index#1#2{% \let\esx@g\@empty % used to build the keysort@actual list \esx@bar@idx#2|\@@ \expandafter\esx@@index\esx@b!\@@ \toks@\expandafter{\esx@g}% \protected@edef\esx@g{\noexpand\esx@trueindex#1{\the\toks@\esx@a}}% \esx@g} } \lowercase{ \gdef\esx@bar@idx#1|#2\@@{% \def\esx@b{#1}\def\esx@a{#2}% \ifx\esx@a\@empty\else\esx@bar@eat#2\fi} } \lowercase{ \gdef\esx@bar@eat#1|{\def\esx@a{|#1}} } \gdef\esindexexpandkey{% \protected@edef\esindexkey{\esindexkey}} \gdef\esindexexpandsubkey{% \ifx\esindexsubkey\relax\else \protected@edef\esindexsubkey{\esindexsubkey}% \fi} \gdef\esindexexpandsubsubkey{% \ifx\esindexsubsubkey\relax\else \protected@edef\esindexsubsubkey{\esindexsubsubkey}% \fi} \gdef\esindexexpandkeys{% \esindexexpandkey \esindexexpandsubkey \esindexexpandsubsubkey} % The following is called for every ! level, much like a loop. #1 is % the current level. \lowercase{ \gdef\esx@@index#1!#2\@@{% \begingroup \let\IeC\@firstofone \def\@tabacckludge##1{\csname\string##1\endcsname}% \esx@spanishaccents \def\esindexkey{#1}% % Apply \esindexsort \@ifundefined{esx@sort@\expandafter\strip@prefix\meaning\esindexkey}% {\@temptokena{#1}}% {\@temptokena\expandafter\expandafter\expandafter{% \csname esx@sort@\expandafter\strip@prefix\meaning\esindexkey\endcsname}}% \edef\esindexkey{\the\@temptokena}% % Execute \everyesindex and apply accents, so that \'a becomes a, and % redefinitions in \everyesindex are also "applied" \the\everyesindex \esindexexpandkeys \esx@spanishreplacements \protected@edef\esindexkey{% \esindexkey \ifx\esindexsubkey\relax\else ^^A\esindexsubkey \fi \ifx\esindexsubsubkey\relax\else ^^A\esindexsubsubkey \fi}% \@temptokena\expandafter{\esindexkey}% % Key now in \@temptokena % Particles, with \ignorewords. \esx@remwords works on \@temptokena \@for\esx@a:=\esx@ignorewords\do{% \expandafter\esx@remwords\expandafter{\esx@a}}% \toks@\expandafter{\esx@g}% \esx@g here contains previous ! levels % Key still in \@temptokena, now without particles. % Add current key and @, and also remove spaces if 'ignorespaces'. \protected@xdef\esx@g{% \the\toks@ \expandafter\esx@zapspace\the\@temptokena\esx@zapspace \string &}% % Key built until now in \esx@g (including previous levels, % current level key, but not the current actual entry). \endgroup \begingroup % Used in the protected expansion below, and only for " in spanish: \esx@spanishquotes % Set actual, if there is a saved one with \esindexactual. \def\esx@a{#1}% \@ifundefined{esx@actual@\expandafter\strip@prefix\meaning\esx@a}% {}% {\expandafter\let\expandafter\esx@a \csname esx@actual@\expandafter\strip@prefix\meaning\esx@a\endcsname}% % Wrap with the language, if not main (babel option). This idea % can be extended to consider more generic contexts \ifesx@babel \bbl@ifsamestring\languagename\bbl@main@language {}% {\@temptokena\expandafter{\esx@a}% \edef\esx@a{\string\esindexlanguage{\languagename}{\the\@temptokena}}}% \fi % Add actual, and go to the next ! level \toks@\expandafter{\esx@g}% \def\esx@b{#2}% \ifx\esx@b\@empty % ie, if no further ! levels \protected@xdef\esx@g{\the\toks@\esx@a}% \else \protected@xdef\esx@g{\the\toks@\esx@a!}% \esx@@index#2\@@ % if there are, continue \fi \endgroup} } \ifesx@spanish \lowercase{ \def\esx@spanishquotes{% \def*##1{% <- its lower case is the quote char (") \ifcat##1a% \@ifundefined{spanish@sh@\string*\string##1@}% {\string*##1}% {\string*\string*##1}% \else \string*\string##1% \fi}} \gdef\esx@spanishaccents{% \def\'##1{\@ifundefined{esx@index@q@\string##1}% {##1}% {\csname esx@index@q@\string##1\endcsname}}% \def\~##1{\string##1\esindexlastchar}% \def\"##1{\@ifundefined{esx@index@qq@\string##1}% {\string"##1}% {\csname esx@index@qq@\string##1\endcsname}}% \ifnum\catcode`\'=\active \let'\'% \fi \ifnum\catcode`\~=\active \let~\~% \fi \ifnum\catcode`\"=\active \let"\"% \fi} } \fi \endgroup % Finishes special catcodes \def\ignorewords#1{% \protected@edef\esx@ignorewords{\zap@space#1 \@empty}} \let\esx@ignorewords\@empty \def\esx@remwords#1{% \def\esx@c##1 #1 \esx@c{\esx@a##1 #1 \esx@a}% \def\esx@a##1 #1 ##2\esx@a{% \ifx\@empty##2\@empty \@firstofone##1##2% \else \@firstofone##1 \esx@c##2\esx@c \fi}% \expandafter\esx@remwords@ii\expandafter{\the\@temptokena}{#1}}% \def\esx@remwords@ii#1#2{% \protected@xdef\esx@b{\expandafter\esx@a\space#1 #2 \esx@a}% \@temptokena\expandafter{\esx@b}} \def\esindexsort#1{% \def\esx@a{#1}% \@namedef{esx@sort@\expandafter\strip@prefix\meaning\esx@a}} \def\esindexactual#1{% \def\esx@a{#1}% \@namedef{esx@actual@\expandafter\strip@prefix\meaning\esx@a}} \newtoks\everyesindex %------------------------- \long\def\esx@afterfi#1\fi{\fi#1} \def\esx@replace#1#2#3{% in #1 -> repl #2 by #3 \toks@{}% \def\esx@replace@aux##1#2##2#2{% \ifx\esx@nil##2% \toks@\expandafter{\the\toks@##1}% \else \toks@\expandafter{\the\toks@##1#3}% \esx@afterfi \esx@replace@aux##2#2% \fi}% \expandafter\esx@replace@aux#1#2\esx@nil#2% \edef#1{\the\toks@}} \let\esindexsubkey\relax \let\esindexsubsubkey\relax \newcommand\esindexreplace[2]{% \esx@replace\esindexkey{#1}{#2}} \newcommand\esindexreplacesub[3]{% \ifx\esindexsubkey\relax \let\esindexsubkey\esindexkey \fi \esindexreplace{#1}{#2}% \esx@replace\esindexsubkey{#1}{#3}} \newcommand\esindexreplacesubsub[4]{% \ifx\esindexsubsubkey\relax \let\esindexsubsubkey\esindexkey \fi \esindexreplacesub{#1}{#2}{#3}% \esx@replace\esindexsubsubkey{#1}{#4}} %------------------------- \let\esx@spanishreplacements\relax \let\esx@@spanishreplacements\relax \ifesx@spanish \def\esx@index@q@n{n\esindexlastchar} \def\esx@index@q@N{N\esindexlastchar} \@namedef{esx@index@q@\string\i}{i} \def\esx@index@qq@o{.o} \def\esx@index@qq@O{.O} \def\esx@index@qq@a{.a} \def\esx@index@qq@A{.A} \def\esx@index@qq@u{u} \def\esx@index@qq@U{U} \def\esx@index@qq@c{c} \def\esx@index@qq@C{C} \def\esx@@spanishreplacements{% \esindexreplace{á}{a}% \esindexreplace{é}{e}% \esindexreplace{í}{i}% \esindexreplace{ó}{o}% \esindexreplace{ú}{u}% \esindexreplace{ñ}{n\esindexlastchar}% \esindexreplace{ü}{u}% \esindexreplace{Á}{A}% \esindexreplace{É}{E}% \esindexreplace{Í}{I}% \esindexreplace{Ó}{O}% \esindexreplace{Ú}{U}% \esindexreplace{Ñ}{N\esindexlastchar}% \esindexreplace{Ü}{U}} \fi \begingroup \catcode`\^=7 \ifx\directlua\@undefined \ifx\XeTeXinterchartoks\@undefined \catcode`\^^ff=12 \xdef\esindexlastchar{^^ff} \else % Hats in xetex seem buggy. Limit to 4. \catcode`\^^^^ffff=12 \xdef\esindexlastchar{^^^^ffff} \global\let\esx@spanishreplacements\esx@@spanishreplacements \fi \else \catcode`\^^^^^^10ffff=12 \xdef\esindexlastchar{^^^^^^10ffff} \global\let\esx@spanishreplacements\esx@@spanishreplacements \fi \endgroup \endinput MIT License ----------- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.