5

The current question is essentially the same as Customizing header in index to include current index entry but with headers managed thanks to titleps package (and not thanks to fancyhdr package). The solution provided for this question relies on \markboth that:

  • fancyhdr can deal with,
  • titleps can't deal with as it doesn't make sense for it,

and I can't see any way to adapt this solution to titleps.

So my question is: with titleps package, how to get headers of the index containing the first/last index entry on that page (as in a dictionary). In other words, if the current page of the index starts and ends with entries respectively:

bar 15, 18

and:

foo 21, 42, 84

I'd like the header to contain:

bar-foo

or, at least, the corresponding first letters:

B-F

Update

As requested by cfr, here is a minimal example of what is possible with fanchyhdr but that I didn't succeed to adapt to titleps (in order to switch between the two cases, just comment/uncomment fanchyhdr and titleps loading).

\documentclass{article}
\usepackage{filecontents}
\usepackage[xindy]{imakeidx}
\usepackage{fancyhdr}
% \usepackage{titleps}
%
\makeatletter
%%%%%%%%%%%%%%%%%%%
% Index pagestyle %
%%%%%%%%%%%%%%%%%%%
%
\@ifpackageloaded{fancyhdr}{%
  % Here is the `fancyhdr' one the solution provided
  \fancypagestyle{indexpagestyle}{%
    \fancyhead{}
    \fancyhead[RO,LE]{\rightmark -- \leftmark}
  }
}{%
  \@ifpackageloaded{titleps}{%
    % Here is the `titleps' equivalent one
    \newpagestyle{indexpagestyle}[]{%
      \sethead
      {%
        % Here probably something else than \rightmark and \leftmark
        (\rightmark) -- (\leftmark)%
      }%
      {}%
      {}%
      \headrule%
      \setfoot{}{\thepage}{}%
    }%
  }{%
  }
}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Macro to use in the index style file to collect the index marks %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\@ifpackageloaded{fancyhdr}{%
  % Here is the `fancyhdr' one the solution provided
  \newcommand{\indexmark}[1]{#1\markboth{#1}{#1}}
}{%
  \@ifpackageloaded{titleps}{%
    %
    % Here is the `titleps' equivalent I'd like to get (\markboth doesn't make
    % sense for `titleps')
    \newcommand{\indexmark}[1]{???}
  }{%
  }
}
%
\makeatother
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Index style file (shared by the two cases) %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\begin{filecontents*}{\jobname.xdy}
(markup-index :open  "~n
\begin{theindex}
  \providecommand*\lettergroupDefault[1]{}
  \providecommand*\lettergroup[1]{\textbf{#1}}
  ~n"
  :close "~n~n\end{theindex}~n"
:tree)

(markup-keyword-list :open "\indexmark{" :close "}" )
\end{filecontents*}
%
% You need to tell it to use your style file
\makeindex[options={-M \jobname.xdy}]
%
\begin{document}
%
% Lots of index entries
Aachen\index{Aachen} aardvark\index{aardvark} aargh\index{aargh} Aarhus\index{Aarhus} Aaron\index{Aaron} Aaronvitch\index{Aaronvitch} Ababa\index{Ababa} aback\index{aback} abacus\index{abacus} abaft\index{abaft} abalone\index{abalone} abandon\index{abandon} abandoner\index{abandoner} abase\index{abase} abaser\index{abaser} abash\index{abash} abashed\index{abashed} abate\index{abate} abated\index{abated} abater\index{abater} abattoir\index{abattoir} Abba\index{Abba} abbess\index{abbess} abbey\index{abbey} abbot\index{abbot} Abbott\index{Abbott} abbreviate\index{abbreviate} abbreviated\index{abbreviated} abbreviation\index{abbreviation} abbé\index{abbé} ABC\index{ABC} abdicate\index{abdicate} abdication\index{abdication} abdomen\index{abdomen} abdominal\index{abdominal} abduct\index{abduct} abductee\index{abductee} abduction\index{abduction} abductor\index{abductor} Abdul\index{Abdul} Abe\index{Abe} abeam\index{abeam} Abel\index{Abel} Abelard\index{Abelard} Abelson\index{Abelson} Aberconwy\index{Aberconwy} Aberdeen\index{Aberdeen} Aberdeenshire\index{Aberdeenshire} Abernathy\index{Abernathy} aberrant\index{aberrant} aberration\index{aberration} Aberystwyth\index{Aberystwyth} abet\index{abet} abettor\index{abettor} abeyance\index{abeyance} abeyant\index{abeyant} abhor\index{abhor} abhorrence\index{abhorrence} abhorrent\index{abhorrent} abhorrer\index{abhorrer} abidance\index{abidance} abide\index{abide} abider\index{abider} Abidjan\index{Abidjan} Abigail\index{Abigail} Abilene\index{Abilene} ability\index{ability} abiogenesis\index{abiogenesis} abiogenic\index{abiogenic} abiotic\index{abiotic} abject\index{abject} abjection\index{abjection} abjectness\index{abjectness} abjuration\index{abjuration} abjure\index{abjure} ablate\index{ablate} ablation\index{ablation} ablaze\index{ablaze} able-bodied\index{able-bodied} able\index{able} abler\index{abler} abloom\index{abloom} ablution\index{ablution} abnegate\index{abnegate} abnegation\index{abnegation} abnormal\index{abnormal} abnormality\index{abnormality} aboard\index{aboard} abode\index{abode} abolish\index{abolish} abolition\index{abolition} abolitionism\index{abolitionism} abolitionist\index{abolitionist} abominable\index{abominable} abominate\index{abominate} abomination\index{abomination} aboriginal\index{aboriginal} Aboriginals\index{Aboriginals} aborigine\index{aborigine} abort\index{abort} aborter\index{aborter} abortion\index{abortion} abortionist\index{abortionist} abortive\index{abortive} abound\index{abound} about\index{about} above\index{above} aboveboard\index{aboveboard} aboveground\index{aboveground} abracadabra\index{abracadabra} abrade\index{abrade} abrader\index{abrader} Abraham\index{Abraham} Abram\index{Abram} abrasion\index{abrasion} abrasive\index{abrasive} abrasiveness\index{abrasiveness} abreaction\index{abreaction} abreast\index{abreast} abridge\index{abridge} abridged\index{abridged} abridger\index{abridger} abroad\index{abroad} abrogate\index{abrogate} abrogation\index{abrogation} abrogator\index{abrogator} abrupt\index{abrupt} abruptness\index{abruptness} abs\index{abs} abscess\index{abscess} abscissa\index{abscissa} abscissae\index{abscissae} abscission\index{abscission} abscond\index{abscond} abseil\index{abseil} abseiler\index{abseiler} absence\index{absence} absent-minded\index{absent-minded} absent-mindedness\index{absent-mindedness} absent\index{absent} absentee\index{absentee} absenteeism\index{absenteeism} absenter\index{absenter} absentia\index{absentia} absinthe\index{absinthe} absolute\index{absolute} absoluteness\index{absoluteness} absolution\index{absolution} absolutism\index{absolutism} absolve\index{absolve} absolver\index{absolver} absorb\index{absorb} absorbed\index{absorbed} absorbency\index{absorbency} absorbent\index{absorbent} absorbs\index{absorbs} absorption\index{absorption} absorptivity\index{absorptivity} abstain\index{abstain} abstemious\index{abstemious} abstemiousness\index{abstemiousness} abstention\index{abstention} abstinence\index{abstinence} abstinent\index{abstinent} abstract\index{abstract} abstracted\index{abstracted} abstractedness\index{abstractedness} abstracter\index{abstracter} abstraction\index{abstraction} abstractionism\index{abstractionism} abstractionist\index{abstractionist} abstractness\index{abstractness} abstractor\index{abstractor} abstruse\index{abstruse} abstruseness\index{abstruseness} absurd\index{absurd} absurdity\index{absurdity} absurdness\index{absurdness} Abu\index{Abu} Abuja\index{Abuja} abundance\index{abundance} abundant\index{abundant} abusable\index{abusable} abuse\index{abuse} abuser\index{abuser} abusive\index{abusive} abusiveness\index{abusiveness} abut\index{abut} abuzz\index{abuzz} abysmal\index{abysmal} abyss\index{abyss} abyssal\index{abyssal} Abyssinia\index{Abyssinia} Abyssinian\index{Abyssinian} Ac\index{Ac} AC\index{AC} acacia\index{acacia} academe\index{academe} academia\index{academia} academic\index{academic} academician\index{academician} academicianship\index{academicianship} academy\index{academy} Acadia\index{Acadia} acanthus\index{acanthus} Acapulco\index{Acapulco} ACAS\index{ACAS} acc.\index{acc.} accede\index{accede} accelerate\index{accelerate} acceleration\index{acceleration} accelerator\index{accelerator} accelerometer\index{accelerometer} accent\index{accent} accented\index{accented} accentual\index{accentual} accentuate\index{accentuate} accentuation\index{accentuation} accept\index{accept} acceptability\index{acceptability} acceptable\index{acceptable} acceptableness\index{acceptableness} acceptably\index{acceptably} acceptance\index{acceptance} acceptant\index{acceptant} accepted\index{accepted} acceptingness\index{acceptingness} acceptor\index{acceptor} access\index{access} accessibility\index{accessibility} accessible\index{accessible} accessibly\index{accessibly} accession\index{accession} accessors\index{accessors} accessory\index{accessory} accidence\index{accidence} accident-prone\index{accident-prone} accident\index{accident} accidental\index{accidental} acclaim\index{acclaim} acclaimer\index{acclaimer} acclamation\index{acclamation} acclimate\index{acclimate} acclimation\index{acclimation} acclimatisation\index{acclimatisation} acclimatise\index{acclimatise} acclimatization\index{acclimatization} acclimatize\index{acclimatize} acclivity\index{acclivity} accolade\index{accolade} accommodate\index{accommodate} accommodating\index{accommodating} accommodation\index{accommodation} accommodative\index{accommodative} accompanied\index{accompanied} accompanier\index{accompanier} accompany\index{accompany} accomplice\index{accomplice} accomplish\index{accomplish} accomplished\index{accomplished} accord\index{accord} accordance\index{accordance} accordant\index{accordant} accordion\index{accordion} accordionist\index{accordionist} accost\index{accost} account\index{account} accountability's\index{accountability's} accountability\index{accountability} accountable\index{accountable} accountably\index{accountably} accountancy\index{accountancy} accountant\index{accountant} accounted\index{accounted} accounting\index{accounting} accoutre\index{accoutre} Accra\index{Accra} accredit\index{accredit} accreditation\index{accreditation} accredited\index{accredited} accreted\index{accreted} accretion\index{accretion} accretive\index{accretive} accrual\index{accrual} accrue\index{accrue} acct\index{acct} acculturate\index{acculturate} acculturation\index{acculturation} accumulate\index{accumulate} accumulation\index{accumulation} accumulative\index{accumulative} accumulator\index{accumulator} accuracy\index{accuracy} accurate\index{accurate} accurately\index{accurately} accurateness\index{accurateness} accursed\index{accursed} accursedness\index{accursedness} accusal\index{accusal} accusation\index{accusation} accusative\index{accusative} accusatory\index{accusatory} accuse\index{accuse} accused\index{accused} accustom\index{accustom} accustomed\index{accustomed} accustomedness\index{accustomedness} ace\index{ace} acellular\index{acellular} acer\index{acer} acerbate\index{acerbate} acerbic\index{acerbic} acerbity\index{acerbity} acetaminophen\index{acetaminophen} acetate\index{acetate} acetic\index{acetic} acetogenic\index{acetogenic} acetone\index{acetone} acetylcholine\index{acetylcholine} acetylene\index{acetylene} Achaean\index{Achaean} ache\index{ache} ached\index{ached} achene\index{achene} aches\index{aches} achievable\index{achievable} achieve\index{achieve} achieved\index{achieved} achievement's\index{achievement's} achievement\index{achievement} achievements\index{achievements} achiever\index{achiever} achieves\index{achieves} achieving\index{achieving} Achilles\index{Achilles} aching\index{aching} achromatic\index{achromatic} achy\index{achy} acid\index{acid} acidification\index{acidification} acidify\index{acidify} acidity\index{acidity} acidophil\index{acidophil} acidophiles\index{acidophiles} acidoses\index{acidoses} acidosis\index{acidosis} acidulous\index{acidulous} Ackerman\index{Ackerman} acknowledge\index{acknowledge} acknowledgeable\index{acknowledgeable} acknowledged\index{acknowledged} ACM\index{ACM} acme\index{acme} acne\index{acne} acolyte\index{acolyte} aconite\index{aconite} acorn\index{acorn} acoustic\index{acoustic} acoustical\index{acoustical} acoustician\index{acoustician} acoustics\index{acoustics} acquaint\index{acquaint} acquaintance\index{acquaintance} acquaintanceship\index{acquaintanceship} acquainted\index{acquainted} acquiesce\index{acquiesce} acquiescence\index{acquiescence} acquiescent\index{acquiescent} acquirable\index{acquirable} acquire\index{acquire} acquirement\index{acquirement} acquisition\index{acquisition} acquisitions\index{acquisitions} acquisitive\index{acquisitive} acquisitiveness\index{acquisitiveness} acquit\index{acquit} acquittal\index{acquittal} acquittance\index{acquittance} acquitter\index{acquitter} acre\index{acre} acreage\index{acreage} acrid\index{acrid} acridity\index{acridity} acridness\index{acridness} acrimonious\index{acrimonious} acrimoniousness\index{acrimoniousness} acrimony\index{acrimony} acrobat\index{acrobat} acrobatic\index{acrobatic} acrobatics\index{acrobatics} acronym\index{acronym} acrophobia\index{acrophobia} acropolis\index{acropolis} across\index{across} acrostic\index{acrostic} acrylate\index{acrylate} acrylic\index{acrylic} act's\index{act's} act\index{act} actinic\index{actinic} actinide\index{actinide} actinium\index{actinium} actinometer\index{actinometer} action\index{action} actionable\index{actionable} actioned\index{actioned} actioning\index{actioning} activate\index{activate} activated\index{activated} activating\index{activating} activation\index{activation} activator\index{activator} active\index{active} actively\index{actively} activeness\index{activeness} activism\index{activism} activity\index{activity} Acton\index{Acton} actor\index{actor} actress\index{actress} actual\index{actual} actuality\index{actuality} actuarial\index{actuarial} actuary\index{actuary} actuate\index{actuate} actuation\index{actuation} actuator\index{actuator} acuity\index{acuity} acumen\index{acumen} acupressure\index{acupressure} acupuncture\index{acupuncture} acute\index{acute} acuteness\index{acuteness} acyclic\index{acyclic} acyclovir\index{acyclovir} ad's\index{ad's} ad\index{ad} adage\index{adage} adagio\index{adagio} Adair\index{Adair} Adam\index{Adam} adamant\index{adamant} Adamski\index{Adamski} Adamson\index{Adamson} adapt\index{adapt} adaptability\index{adaptability} adaptation\index{adaptation} adapted\index{adapted} adaptive\index{adaptive} adaptivity\index{adaptivity} adaptor\index{adaptor} ADC\index{ADC} add-on\index{add-on} add\index{add} addend\index{addend} addenda\index{addenda} addendum\index{addendum} addict\index{addict} addiction\index{addiction} Addis\index{Addis} Addison\index{Addison} addition\index{addition} additional\index{additional} additive\index{additive} additivity\index{additivity} addle\index{addle} addorsed\index{addorsed} address\index{address} addressed\index{addressed} addressee\index{addressee} addresses\index{addresses} addressing\index{addressing} adduce\index{adduce} adducer\index{adducer} adduct\index{adduct} adduction\index{adduction} adductor\index{adductor} Adelaide\index{Adelaide} Adele\index{Adele} Aden\index{Aden} Adenauer\index{Adenauer} adenine\index{adenine} adenoid\index{adenoid} adenoidal\index{adenoidal} adenoma\index{adenoma} adenomata\index{adenomata} adenoviral\index{adenoviral} adenovirus\index{adenovirus} adept\index{adept} adeptness\index{adeptness} adequacy\index{adequacy} adequate\index{adequate} adequateness\index{adequateness} adhere\index{adhere} adherence\index{adherence} adherent\index{adherent} adhesion\index{adhesion} adhesive\index{adhesive} adhesiveness\index{adhesiveness} adiabatic\index{adiabatic} adieu\index{adieu} adipose\index{adipose} Adirondack\index{Adirondack} adiós\index{adiós} adjacency\index{adjacency} adjacent\index{adjacent} adjectival\index{adjectival} adjective\index{adjective} adjoin\index{adjoin} adjourn\index{adjourn} adjudge\index{adjudge} adjudicate\index{adjudicate} adjudication\index{adjudication} adjudicator\index{adjudicator} adjunct\index{adjunct} adjuration\index{adjuration} adjure\index{adjure} adjust\index{adjust} adjusted\index{adjusted} adjustor's\index{adjustor's} adjusts\index{adjusts} adjutant\index{adjutant} Adkins\index{Adkins} Adler\index{Adler} adman\index{adman} admen\index{admen} admin\index{admin} adminicle\index{adminicle} adminicular\index{adminicular} administer\index{administer} administrable\index{administrable} administrate\index{administrate} administration\index{administration} administrator\index{administrator} administratrix\index{administratrix} admirable\index{admirable} admiral\index{admiral} admiralty\index{admiralty} admiration\index{admiration} admire\index{admire} admissibility\index{admissibility} admissible\index{admissible} admission\index{admission} admit\index{admit} admittance\index{admittance} admitted\index{admitted} admixture\index{admixture} admonish\index{admonish} admonisher\index{admonisher} admonition\index{admonition} admonitory\index{admonitory} ado\index{ado} adobe\index{adobe} adolescence's\index{adolescence's} adolescence\index{adolescence} adolescent\index{adolescent} Adolph\index{Adolph} Adonis\index{Adonis} adopt\index{adopt} adopted\index{adopted} adoption\index{adoption} adopts\index{adopts} adorable\index{adorable} adorableness\index{adorableness} adoration\index{adoration} adore\index{adore} adorn\index{adorn} adorned\index{adorned} adrenal\index{adrenal} adrenalin\index{adrenalin} adrenaline\index{adrenaline} Adrian\index{Adrian} Adriatic\index{Adriatic} Adrienne\index{Adrienne} adrift\index{adrift} adroit\index{adroit} adroitness\index{adroitness} ads\index{ads} ADSL\index{ADSL} adsorb\index{adsorb} adsorbate\index{adsorbate} adsorbent\index{adsorbent} adsorption\index{adsorption} ADte\index{ADte} adulate\index{adulate} adulation\index{adulation} adulator\index{adulator} adult\index{adult} adulterant\index{adulterant} adulterate\index{adulterate} adulterated\index{adulterated} adulteration\index{adulteration} adulterer\index{adulterer} adulteress\index{adulteress} adulterous\index{adulterous} adultery\index{adultery} adulthood\index{adulthood} adumbrate\index{adumbrate} adumbration\index{adumbration} advance\index{advance} advantage\index{advantage} advantageous\index{advantageous} advantageousness's\index{advantageousness's} advantageousness\index{advantageousness} advent\index{advent} Adventist's\index{Adventist's} adventist\index{adventist} adventitious\index{adventitious} adventure's\index{adventure's} adventure\index{adventure} adventures\index{adventures} adventuresome\index{adventuresome} adventuress\index{adventuress} adventurism\index{adventurism} adventurous\index{adventurous} adventurously\index{adventurously} adventurousness\index{adventurousness} adverb\index{adverb} adverbial\index{adverbial} adversarial\index{adversarial} adversary\index{adversary} adverse\index{adverse} adverseness\index{adverseness} adversity\index{adversity} advert\index{advert} advertise\index{advertise} advertised\index{advertised} advertising\index{advertising} advice\index{advice} advisabilities\index{advisabilities} advisability's\index{advisability's} advisability\index{advisability} advisable\index{advisable} advise\index{advise} advisedly\index{advisedly} advisee\index{advisee} advisor\index{advisor} advisory\index{advisory} advocacy\index{advocacy} advocate\index{advocate} adware\index{adware} adze\index{adze} Aegean\index{Aegean} aegis\index{aegis} aegrotat\index{aegrotat} Aeneas\index{Aeneas} Aeneid\index{Aeneid} aeolian\index{aeolian} Aeolus\index{Aeolus} aeon\index{aeon} aerate\index{aerate} aeration\index{aeration} aerator\index{aerator} aerial\index{aerial} aerialist\index{aerialist} aerie\index{aerie} aero\index{aero} aero-engine\index{aero-engine} aeroacoustic\index{aeroacoustic} aerobatic\index{aerobatic} aerobic\index{aerobic} aerodrome\index{aerodrome} aerodynamic\index{aerodynamic} aerodynamics\index{aerodynamics} aeroelastic\index{aeroelastic} aeroelasticity\index{aeroelasticity} aerofoil\index{aerofoil} aerogel\index{aerogel} aerogramme\index{aerogramme} aerolite\index{aerolite} aeromagnetic\index{aeromagnetic} aeromedical\index{aeromedical} aeromodeller\index{aeromodeller} aeromodelling\index{aeromodelling} aeronautic\index{aeronautic} aeronautical\index{aeronautical} aeronautics\index{aeronautics} aerophone\index{aerophone} aeroplane\index{aeroplane} aeroponic\index{aeroponic} aeroponically\index{aeroponically} aerosol\index{aerosol} aerospace\index{aerospace} Aeschylus\index{Aeschylus} Aesculapius\index{Aesculapius} Aesop\index{Aesop} aesthete\index{aesthete} aesthetic\index{aesthetic} aestheticism\index{aestheticism} aestival\index{aestival} aestivate\index{aestivate} aether\index{aether} aetiology\index{aetiology} AFAIK\index{AFAIK} afar\index{afar} AFC\index{AFC} affability\index{affability} affable\index{affable} affair\index{affair} affect\index{affect} affectation\index{affectation} affected\index{affected} affectedly\index{affectedly} affecter\index{affecter} affecting\index{affecting} affection\index{affection} affectionate\index{affectionate} affectionately\index{affectionately} affective\index{affective} affects\index{affects} afferent\index{afferent} affiance\index{affiance} affidavit\index{affidavit} affiliate\index{affiliate} affiliated\index{affiliated} affiliation\index{affiliation} affine\index{affine} affinity\index{affinity} affirm\index{affirm} affirmation\index{affirmation} affirmed\index{affirmed} affirms\index{affirms} affix\index{affix} afflatus\index{afflatus} afflict\index{afflict} affliction\index{affliction} affluence\index{affluence} affluent\index{affluent} afford\index{afford} affordable\index{affordable} afforest\index{afforest} afforestation\index{afforestation} affray\index{affray} affricate\index{affricate} affrication\index{affrication} affricative\index{affricative} affright\index{affright} affront\index{affront} Afghan\index{Afghan} Afghani\index{Afghani} Afghanistan\index{Afghanistan} aficionado\index{aficionado} afield\index{afield} afire\index{afire} aflame\index{aflame}
%
% Set index pagestyle
\pagestyle{indexpagestyle}
\printindex
\end{document}
  • Please provide an example of what you've got so that people actually have something to work from. We currently have no idea what your code looks like or how you've configured things. Right now, a perfectly sensible answer is don't load titleps and add <code from the Q&A you linked to>. After all, literally the only thing we know is that you are loading titleps somehow somewhere in some .tex file that may or may not have any use for it. – cfr Oct 26 '16 at 2:13
  • @cfr Minimal example provided. In my real use case, I need to load titleps instead of fancyhdr because the former is much more flexible and, IIRC, provides features I needed fancyhdr doesn't provide. – Denis Bitouzé Oct 26 '16 at 5:52
  • +1 for the excellently prepared sample code, making it easy to compare the two approaches. – gernot Oct 27 '16 at 14:53
  • Is \markboth required for some reason? (eg, hardcoded in some class or package you are using). If not, this is a XY-problem :-) and the solution is not to use it at all and rely instead on the tools provided by titleps - see sec. 7 about extramarks which explains how to do it, with an example. – Javier Bezos Dec 13 '16 at 12:28
2
+100

Here is a solution using an approach similar to \label-\ref. It should work for any package costumizing the page header/footer, as the commands \indexentryfirst and \indexentrylast always hold the first and the last index entry on the current page (at least after latexing the document sufficiently often), while setting them does not interfere with page marking.

\documentclass{article}
\usepackage{filecontents}
\usepackage[xindy]{imakeidx}
\usepackage{titleps}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\indexmark[1]{#1\indexentry{#1}}
\makeatletter
\newcommand\indexentry[1]%
  {\@bsphack
   \protected@write\@auxout{}%
     {\string\newindexentry{#1}{\thepage}}%
   \@esphack
  }
\newcommand\newindexentry[2]%
  {\expandafter\@newindexentryfirst\csname first@#2\endcsname{#1}%
   \expandafter\@newindexentrylast \csname last@#2\endcsname{#1}%
  }
\newcommand\@newindexentryfirst[2]{\ifx#1\relax\gdef#1{#2}\fi}
\newcommand\@newindexentrylast [2]{\gdef#1{#2}}
\newcommand\indexentryfirst
  {\expandafter\@indexentryX\csname first@\thepage\endcsname{First}}
\newcommand\indexentrylast
  {\expandafter\@indexentryX\csname last@\thepage\endcsname{Last}}
\newcommand\@indexentryX[2]%
  {\ifx#1\relax
     \nfss@text{\reset@font\bfseries ??}%
     \@latex@warning{#2 index entry on page \thepage \space undefined}%
   \else
     #1%
   \fi
  }
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newpagestyle{indexpagestyle}[]%
  {\sethead
    {\indexentryfirst -- \indexentrylast}%
    {}%
    {}%
   \headrule%
   \setfoot{}{\thepage}{}%
  }%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{filecontents*}{\jobname.xdy}
(markup-index :open  "~n
\begin{theindex}
  \providecommand*\lettergroupDefault[1]{}
  \providecommand*\lettergroup[1]{\textbf{#1}}
  ~n"
  :close "~n~n\end{theindex}~n"
:tree)

(markup-keyword-list :open "\indexmark{" :close "}" )
\end{filecontents*}
\makeindex[options={-M \jobname.xdy}]

\begin{document}
Aachen\index{Aachen} aardvark\index{aardvark} aargh\index{aargh}
Aarhus\index{Aarhus} Aaron\index{Aaron} Aaronvitch\index{Aaronvitch}
Ababa\index{Ababa} aback\index{aback} abacus\index{abacus}
abaft\index{abaft} abalone\index{abalone} abandon\index{abandon}
abandoner\index{abandoner} abase\index{abase} abaser\index{abaser}
abash\index{abash} abashed\index{abashed} abate\index{abate}
abated\index{abated} abater\index{abater} abattoir\index{abattoir}
Abba\index{Abba} abbess\index{abbess} abbey\index{abbey}
abbot\index{abbot} Abbott\index{Abbott} abbreviate\index{abbreviate}
abbreviated\index{abbreviated} abbreviation\index{abbreviation}
abbé\index{abbé} ABC\index{ABC} abdicate\index{abdicate}
abdication\index{abdication} abdomen\index{abdomen}
abdominal\index{abdominal} abduct\index{abduct}
abductee\index{abductee} abduction\index{abduction}
abductor\index{abductor} Abdul\index{Abdul} Abe\index{Abe}
abeam\index{abeam} Abel\index{Abel} Abelard\index{Abelard}
Abelson\index{Abelson} Aberconwy\index{Aberconwy}
Aberdeen\index{Aberdeen} Aberdeenshire\index{Aberdeenshire}
Abernathy\index{Abernathy} aberrant\index{aberrant}
aberration\index{aberration} Aberystwyth\index{Aberystwyth}
abet\index{abet} abettor\index{abettor} abeyance\index{abeyance}
abeyant\index{abeyant} abhor\index{abhor} abhorrence\index{abhorrence}
abhorrent\index{abhorrent} abhorrer\index{abhorrer}
abidance\index{abidance} abide\index{abide} abider\index{abider}
Abidjan\index{Abidjan} Abigail\index{Abigail} Abilene\index{Abilene}
ability\index{ability} abiogenesis\index{abiogenesis}
abiogenic\index{abiogenic} abiotic\index{abiotic} abject\index{abject}
abjection\index{abjection} abjectness\index{abjectness}
abjuration\index{abjuration} abjure\index{abjure} ablate\index{ablate}
ablation\index{ablation} ablaze\index{ablaze}
able-bodied\index{able-bodied} able\index{able} abler\index{abler}
abloom\index{abloom} ablution\index{ablution} abnegate\index{abnegate}
abnegation\index{abnegation} abnormal\index{abnormal}
abnormality\index{abnormality} aboard\index{aboard} abode\index{abode}
abolish\index{abolish} abolition\index{abolition}
abolitionism\index{abolitionism} abolitionist\index{abolitionist}
abominable\index{abominable} abominate\index{abominate}
abomination\index{abomination} aboriginal\index{aboriginal}
Aboriginals\index{Aboriginals} aborigine\index{aborigine}
abort\index{abort} aborter\index{aborter} abortion\index{abortion}
abortionist\index{abortionist} abortive\index{abortive}
abound\index{abound} about\index{about} above\index{above}
aboveboard\index{aboveboard} aboveground\index{aboveground}
abracadabra\index{abracadabra} abrade\index{abrade}
abrader\index{abrader} Abraham\index{Abraham} Abram\index{Abram}
abrasion\index{abrasion} abrasive\index{abrasive}
abrasiveness\index{abrasiveness} abreaction\index{abreaction}
abreast\index{abreast} abridge\index{abridge} abridged\index{abridged}
abridger\index{abridger} abroad\index{abroad} abrogate\index{abrogate}
abrogation\index{abrogation} abrogator\index{abrogator}
abrupt\index{abrupt} abruptness\index{abruptness} abs\index{abs}
abscess\index{abscess} abscissa\index{abscissa}
abscissae\index{abscissae} abscission\index{abscission}
abscond\index{abscond} abseil\index{abseil} abseiler\index{abseiler}
absence\index{absence} absent-minded\index{absent-minded}
absent-mindedness\index{absent-mindedness} absent\index{absent}
absentee\index{absentee} absenteeism\index{absenteeism}
absenter\index{absenter} absentia\index{absentia}
absinthe\index{absinthe} absolute\index{absolute}
absoluteness\index{absoluteness} absolution\index{absolution}
absolutism\index{absolutism} absolve\index{absolve}
absolver\index{absolver} absorb\index{absorb} absorbed\index{absorbed}
absorbency\index{absorbency} absorbent\index{absorbent}
absorbs\index{absorbs} absorption\index{absorption}
absorptivity\index{absorptivity} abstain\index{abstain}
abstemious\index{abstemious} abstemiousness\index{abstemiousness}
abstention\index{abstention} abstinence\index{abstinence}
abstinent\index{abstinent} abstract\index{abstract}
abstracted\index{abstracted} abstractedness\index{abstractedness}
abstracter\index{abstracter} abstraction\index{abstraction}
abstractionism\index{abstractionism}
abstractionist\index{abstractionist} abstractness\index{abstractness}
abstractor\index{abstractor} abstruse\index{abstruse}
abstruseness\index{abstruseness} absurd\index{absurd}
absurdity\index{absurdity} absurdness\index{absurdness} Abu\index{Abu}
Abuja\index{Abuja} abundance\index{abundance} abundant\index{abundant}
abusable\index{abusable} abuse\index{abuse} abuser\index{abuser}
abusive\index{abusive} abusiveness\index{abusiveness} abut\index{abut}
abuzz\index{abuzz} abysmal\index{abysmal} abyss\index{abyss}
abyssal\index{abyssal} Abyssinia\index{Abyssinia}
Abyssinian\index{Abyssinian} Ac\index{Ac} AC\index{AC}
acacia\index{acacia} academe\index{academe} academia\index{academia}
academic\index{academic} academician\index{academician}
academicianship\index{academicianship} academy\index{academy}
Acadia\index{Acadia} acanthus\index{acanthus} Acapulco\index{Acapulco}
ACAS\index{ACAS} acc.\index{acc.} accede\index{accede}
accelerate\index{accelerate} acceleration\index{acceleration}
accelerator\index{accelerator} accelerometer\index{accelerometer}
accent\index{accent} accented\index{accented}
accentual\index{accentual} accentuate\index{accentuate}
accentuation\index{accentuation} accept\index{accept}
acceptability\index{acceptability} acceptable\index{acceptable}
acceptableness\index{acceptableness} acceptably\index{acceptably}
acceptance\index{acceptance} acceptant\index{acceptant}
accepted\index{accepted} acceptingness\index{acceptingness}
acceptor\index{acceptor} access\index{access}
accessibility\index{accessibility} accessible\index{accessible}
accessibly\index{accessibly} accession\index{accession}
accessors\index{accessors} accessory\index{accessory}
accidence\index{accidence} accident-prone\index{accident-prone}
accident\index{accident} accidental\index{accidental}
acclaim\index{acclaim} acclaimer\index{acclaimer}
acclamation\index{acclamation} acclimate\index{acclimate}
acclimation\index{acclimation} acclimatisation\index{acclimatisation}
acclimatise\index{acclimatise} acclimatization\index{acclimatization}
acclimatize\index{acclimatize} acclivity\index{acclivity}
accolade\index{accolade} accommodate\index{accommodate}
accommodating\index{accommodating} accommodation\index{accommodation}
accommodative\index{accommodative} accompanied\index{accompanied}
accompanier\index{accompanier} accompany\index{accompany}
accomplice\index{accomplice} accomplish\index{accomplish}
accomplished\index{accomplished} accord\index{accord}
accordance\index{accordance} accordant\index{accordant}
accordion\index{accordion} accordionist\index{accordionist}
accost\index{accost} account\index{account}
accountability's\index{accountability's}
accountability\index{accountability} accountable\index{accountable}
accountably\index{accountably} accountancy\index{accountancy}
accountant\index{accountant} accounted\index{accounted}
accounting\index{accounting} accoutre\index{accoutre}
Accra\index{Accra} accredit\index{accredit}
accreditation\index{accreditation} accredited\index{accredited}
accreted\index{accreted} accretion\index{accretion}
accretive\index{accretive} accrual\index{accrual} accrue\index{accrue}
acct\index{acct} acculturate\index{acculturate}
acculturation\index{acculturation} accumulate\index{accumulate}
accumulation\index{accumulation} accumulative\index{accumulative}
accumulator\index{accumulator} accuracy\index{accuracy}
accurate\index{accurate} accurately\index{accurately}
accurateness\index{accurateness} accursed\index{accursed}
accursedness\index{accursedness} accusal\index{accusal}
accusation\index{accusation} accusative\index{accusative}
accusatory\index{accusatory} accuse\index{accuse}
accused\index{accused} accustom\index{accustom}
accustomed\index{accustomed} accustomedness\index{accustomedness}
ace\index{ace} acellular\index{acellular} acer\index{acer}
acerbate\index{acerbate} acerbic\index{acerbic}
acerbity\index{acerbity} acetaminophen\index{acetaminophen}
acetate\index{acetate} acetic\index{acetic}
acetogenic\index{acetogenic} acetone\index{acetone}
acetylcholine\index{acetylcholine} acetylene\index{acetylene}
Achaean\index{Achaean} ache\index{ache} ached\index{ached}
achene\index{achene} aches\index{aches} achievable\index{achievable}
achieve\index{achieve} achieved\index{achieved}
achievement's\index{achievement's} achievement\index{achievement}
achievements\index{achievements} achiever\index{achiever}
achieves\index{achieves} achieving\index{achieving}
Achilles\index{Achilles} aching\index{aching}
achromatic\index{achromatic} achy\index{achy} acid\index{acid}
acidification\index{acidification} acidify\index{acidify}
acidity\index{acidity} acidophil\index{acidophil}
acidophiles\index{acidophiles} acidoses\index{acidoses}
acidosis\index{acidosis} acidulous\index{acidulous}
Ackerman\index{Ackerman} acknowledge\index{acknowledge}
acknowledgeable\index{acknowledgeable}
acknowledged\index{acknowledged} ACM\index{ACM} acme\index{acme}
acne\index{acne} acolyte\index{acolyte} aconite\index{aconite}
acorn\index{acorn} acoustic\index{acoustic}
acoustical\index{acoustical} acoustician\index{acoustician}
acoustics\index{acoustics} acquaint\index{acquaint}
acquaintance\index{acquaintance}
acquaintanceship\index{acquaintanceship} acquainted\index{acquainted}
acquiesce\index{acquiesce} acquiescence\index{acquiescence}
acquiescent\index{acquiescent} acquirable\index{acquirable}
acquire\index{acquire} acquirement\index{acquirement}
acquisition\index{acquisition} acquisitions\index{acquisitions}
acquisitive\index{acquisitive} acquisitiveness\index{acquisitiveness}
acquit\index{acquit} acquittal\index{acquittal}
acquittance\index{acquittance} acquitter\index{acquitter}
acre\index{acre} acreage\index{acreage} acrid\index{acrid}
acridity\index{acridity} acridness\index{acridness}
acrimonious\index{acrimonious} acrimoniousness\index{acrimoniousness}
acrimony\index{acrimony} acrobat\index{acrobat}
acrobatic\index{acrobatic} acrobatics\index{acrobatics}
acronym\index{acronym} acrophobia\index{acrophobia}
acropolis\index{acropolis} across\index{across}
acrostic\index{acrostic} acrylate\index{acrylate}
acrylic\index{acrylic} act's\index{act's} act\index{act}
actinic\index{actinic} actinide\index{actinide}
actinium\index{actinium} actinometer\index{actinometer}
action\index{action} actionable\index{actionable}
actioned\index{actioned} actioning\index{actioning}
activate\index{activate} activated\index{activated}
activating\index{activating} activation\index{activation}
activator\index{activator} active\index{active}
actively\index{actively} activeness\index{activeness}
activism\index{activism} activity\index{activity} Acton\index{Acton}
actor\index{actor} actress\index{actress} actual\index{actual}
actuality\index{actuality} actuarial\index{actuarial}
actuary\index{actuary} actuate\index{actuate}
actuation\index{actuation} actuator\index{actuator}
acuity\index{acuity} acumen\index{acumen}
acupressure\index{acupressure} acupuncture\index{acupuncture}
acute\index{acute} acuteness\index{acuteness} acyclic\index{acyclic}
acyclovir\index{acyclovir} ad's\index{ad's} ad\index{ad}
adage\index{adage} adagio\index{adagio} Adair\index{Adair}
Adam\index{Adam} adamant\index{adamant} Adamski\index{Adamski}
Adamson\index{Adamson} adapt\index{adapt}
adaptability\index{adaptability} adaptation\index{adaptation}
adapted\index{adapted} adaptive\index{adaptive}
adaptivity\index{adaptivity} adaptor\index{adaptor} ADC\index{ADC}
add-on\index{add-on} add\index{add} addend\index{addend}
addenda\index{addenda} addendum\index{addendum} addict\index{addict}
addiction\index{addiction} Addis\index{Addis} Addison\index{Addison}
addition\index{addition} additional\index{additional}
additive\index{additive} additivity\index{additivity}
addle\index{addle} addorsed\index{addorsed} address\index{address}
addressed\index{addressed} addressee\index{addressee}
addresses\index{addresses} addressing\index{addressing}
adduce\index{adduce} adducer\index{adducer} adduct\index{adduct}
adduction\index{adduction} adductor\index{adductor}
Adelaide\index{Adelaide} Adele\index{Adele} Aden\index{Aden}
Adenauer\index{Adenauer} adenine\index{adenine} adenoid\index{adenoid}
adenoidal\index{adenoidal} adenoma\index{adenoma}
adenomata\index{adenomata} adenoviral\index{adenoviral}
adenovirus\index{adenovirus} adept\index{adept}
adeptness\index{adeptness} adequacy\index{adequacy}
adequate\index{adequate} adequateness\index{adequateness}
adhere\index{adhere} adherence\index{adherence}
adherent\index{adherent} adhesion\index{adhesion}
adhesive\index{adhesive} adhesiveness\index{adhesiveness}
adiabatic\index{adiabatic} adieu\index{adieu} adipose\index{adipose}
Adirondack\index{Adirondack} adiós\index{adiós}
adjacency\index{adjacency} adjacent\index{adjacent}
adjectival\index{adjectival} adjective\index{adjective}
adjoin\index{adjoin} adjourn\index{adjourn} adjudge\index{adjudge}
adjudicate\index{adjudicate} adjudication\index{adjudication}
adjudicator\index{adjudicator} adjunct\index{adjunct}
adjuration\index{adjuration} adjure\index{adjure} adjust\index{adjust}
adjusted\index{adjusted} adjustor's\index{adjustor's}
adjusts\index{adjusts} adjutant\index{adjutant} Adkins\index{Adkins}
Adler\index{Adler} adman\index{adman} admen\index{admen}
admin\index{admin} adminicle\index{adminicle}
adminicular\index{adminicular} administer\index{administer}
administrable\index{administrable} administrate\index{administrate}
administration\index{administration}
administrator\index{administrator}
administratrix\index{administratrix} admirable\index{admirable}
admiral\index{admiral} admiralty\index{admiralty}
admiration\index{admiration} admire\index{admire}
admissibility\index{admissibility} admissible\index{admissible}
admission\index{admission} admit\index{admit}
admittance\index{admittance} admitted\index{admitted}
admixture\index{admixture} admonish\index{admonish}
admonisher\index{admonisher} admonition\index{admonition}
admonitory\index{admonitory} ado\index{ado} adobe\index{adobe}
adolescence's\index{adolescence's} adolescence\index{adolescence}
adolescent\index{adolescent} Adolph\index{Adolph} Adonis\index{Adonis}
adopt\index{adopt} adopted\index{adopted} adoption\index{adoption}
adopts\index{adopts} adorable\index{adorable}
adorableness\index{adorableness} adoration\index{adoration}
adore\index{adore} adorn\index{adorn} adorned\index{adorned}
adrenal\index{adrenal} adrenalin\index{adrenalin}
adrenaline\index{adrenaline} Adrian\index{Adrian}
Adriatic\index{Adriatic} Adrienne\index{Adrienne} adrift\index{adrift}
adroit\index{adroit} adroitness\index{adroitness} ads\index{ads}
ADSL\index{ADSL} adsorb\index{adsorb} adsorbate\index{adsorbate}
adsorbent\index{adsorbent} adsorption\index{adsorption}
ADte\index{ADte} adulate\index{adulate} adulation\index{adulation}
adulator\index{adulator} adult\index{adult}
adulterant\index{adulterant} adulterate\index{adulterate}
adulterated\index{adulterated} adulteration\index{adulteration}
adulterer\index{adulterer} adulteress\index{adulteress}
adulterous\index{adulterous} adultery\index{adultery}
adulthood\index{adulthood} adumbrate\index{adumbrate}
adumbration\index{adumbration} advance\index{advance}
advantage\index{advantage} advantageous\index{advantageous}
advantageousness's\index{advantageousness's}
advantageousness\index{advantageousness} advent\index{advent}
Adventist's\index{Adventist's} adventist\index{adventist}
adventitious\index{adventitious} adventure's\index{adventure's}
adventure\index{adventure} adventures\index{adventures}
adventuresome\index{adventuresome} adventuress\index{adventuress}
adventurism\index{adventurism} adventurous\index{adventurous}
adventurously\index{adventurously}
adventurousness\index{adventurousness} adverb\index{adverb}
adverbial\index{adverbial} adversarial\index{adversarial}
adversary\index{adversary} adverse\index{adverse}
adverseness\index{adverseness} adversity\index{adversity}
advert\index{advert} advertise\index{advertise}
advertised\index{advertised} advertising\index{advertising}
advice\index{advice} advisabilities\index{advisabilities}
advisability's\index{advisability's} advisability\index{advisability}
advisable\index{advisable} advise\index{advise}
advisedly\index{advisedly} advisee\index{advisee}
advisor\index{advisor} advisory\index{advisory}
advocacy\index{advocacy} advocate\index{advocate} adware\index{adware}
adze\index{adze} Aegean\index{Aegean} aegis\index{aegis}
aegrotat\index{aegrotat} Aeneas\index{Aeneas} Aeneid\index{Aeneid}
aeolian\index{aeolian} Aeolus\index{Aeolus} aeon\index{aeon}
aerate\index{aerate} aeration\index{aeration} aerator\index{aerator}
aerial\index{aerial} aerialist\index{aerialist} aerie\index{aerie}
aero\index{aero} aero-engine\index{aero-engine}
aeroacoustic\index{aeroacoustic} aerobatic\index{aerobatic}
aerobic\index{aerobic} aerodrome\index{aerodrome}
aerodynamic\index{aerodynamic} aerodynamics\index{aerodynamics}
aeroelastic\index{aeroelastic} aeroelasticity\index{aeroelasticity}
aerofoil\index{aerofoil} aerogel\index{aerogel}
aerogramme\index{aerogramme} aerolite\index{aerolite}
aeromagnetic\index{aeromagnetic} aeromedical\index{aeromedical}
aeromodeller\index{aeromodeller} aeromodelling\index{aeromodelling}
aeronautic\index{aeronautic} aeronautical\index{aeronautical}
aeronautics\index{aeronautics} aerophone\index{aerophone}
aeroplane\index{aeroplane} aeroponic\index{aeroponic}
aeroponically\index{aeroponically} aerosol\index{aerosol}
aerospace\index{aerospace} Aeschylus\index{Aeschylus}
Aesculapius\index{Aesculapius} Aesop\index{Aesop}
aesthete\index{aesthete} aesthetic\index{aesthetic}
aestheticism\index{aestheticism} aestival\index{aestival}
aestivate\index{aestivate} aether\index{aether}
aetiology\index{aetiology} AFAIK\index{AFAIK} afar\index{afar}
AFC\index{AFC} affability\index{affability} affable\index{affable}
affair\index{affair} affect\index{affect}
affectation\index{affectation} affected\index{affected}
affectedly\index{affectedly} affecter\index{affecter}
affecting\index{affecting} affection\index{affection}
affectionate\index{affectionate} affectionately\index{affectionately}
affective\index{affective} affects\index{affects}
afferent\index{afferent} affiance\index{affiance}
affidavit\index{affidavit} affiliate\index{affiliate}
affiliated\index{affiliated} affiliation\index{affiliation}
affine\index{affine} affinity\index{affinity} affirm\index{affirm}
affirmation\index{affirmation} affirmed\index{affirmed}
affirms\index{affirms} affix\index{affix} afflatus\index{afflatus}
afflict\index{afflict} affliction\index{affliction}
affluence\index{affluence} affluent\index{affluent}
afford\index{afford} affordable\index{affordable}
afforest\index{afforest} afforestation\index{afforestation}
affray\index{affray} affricate\index{affricate}
affrication\index{affrication} affricative\index{affricative}
affright\index{affright} affront\index{affront} Afghan\index{Afghan}
Afghani\index{Afghani} Afghanistan\index{Afghanistan}
aficionado\index{aficionado} afield\index{afield} afire\index{afire}
aflame\index{aflame}
%
% Set index pagestyle
\clearpage
\pagestyle{indexpagestyle}
\printindex
\end{document}
  • @DenisBitouzé Since I've placed a bounty on this question, would you mind temporarily unaccepting this answer for a few days in case in case a different answer comes up (people tend not to answer questions with accepted answers.) This is an interesting approach, but conceptually quite different from the one in the linked question. – Alan Munn Oct 26 '16 at 22:08
  • @AlanMunn Done. Sorry for having been so hasty. And, BTW, thanks for the bounty! – Denis Bitouzé Oct 27 '16 at 6:01
  • I finally accept your first answer instead of the second one because the latter has the following trouble the former doesn't have: in case of book class, the index' title, specified thanks to \makeindex's title option, is taken in account in headers except for the last page if it is an odd page. – Denis Bitouzé Oct 31 '16 at 8:35
2

Here is a solution in the spirit of the fancyhdr approach. The main point is to define the titleps page style in the following way.

\makeatletter
\newcommand\MarkbothHack
  {\let\ORIGttl@titlemarks\ttl@titlemarks
   \let\ttl@titlemarks\relax
  } 
\newcommand\UndoMarkbothHack
  {\clearpage
   \markboth{}{}%
   \let\ttl@titlemarks\ORIGttl@titlemarks
  }
\makeatother

\newcommand\wordrange{\rightmark\ -- \leftmark}
\newpagestyle{indexpagestyle}%
  {\sethead{\wordrange}{}{}%
   \headrule
   \setfoot{}{\thepage}{}%
  }%

Usage:

\clearpage
\MarkbothHack
\pagestyle{indexpagestyle}%
\printindex
\UndoMarkbothHack

A more sophisticated definition of \wordrange avoids hyphens in the case that there are no index entries on a page (may happen for two-sided documents) or just one (may happen in the case of a single-column index).

\usepackage{ifthen}
\newcommand\wordrange
  {\ifthenelse{\equal{\leftmark}{}}%
     {\rightmark}%
     {\ifthenelse{\equal{\rightmark}{\leftmark}}%
        {\rightmark}%
        {\rightmark\ -- \leftmark}%
     }
  }

Here is the code of the example, in the book variant of the comment below. By (un)commenting the appropriate lines, you can choose between fancyhdr and titleps, as well as between single-column and double-column index. In the single-column index the last index page contains just one entry, to demonstrate that the definition of \wordrange also handles this case correctly.

\documentclass{book}
\usepackage{ifthen}
\usepackage{filecontents}
\usepackage[xindy]{imakeidx}
%\usepackage{fancyhdr}
\usepackage{titleps}
\usepackage{lipsum}

\makeatletter
\@ifpackageloaded{fancyhdr}%
  {\fancypagestyle{indexpagestyle}%
     {\fancyhead{}
      \fancyhead[RO,LE]{\wordrange}
     }
   \newcommand\MarkbothHack{}
   \newcommand\UndoMarkbothHack{\markboth{}{}}
  }%
{\@ifpackageloaded{titleps}%
  {\newpagestyle{indexpagestyle}%
     {\sethead[][][\wordrange]{\wordrange}{}{}%
      \headrule
      \setfoot{}{\thepage}{}%
     }%
   \newcommand\MarkbothHack
     {\let\ORIGttl@titlemarks\ttl@titlemarks
      \let\ttl@titlemarks\relax
     } 
   \newcommand\UndoMarkbothHack
     {\clearpage
      \markboth{}{}%
      \let\ttl@titlemarks\ORIGttl@titlemarks
     }
  }%
{}
}
\makeatother

\newcommand\wordrange
  {\ifthenelse{\equal{\leftmark}{}}%
     {\rightmark}%
     {\ifthenelse{\equal{\rightmark}{\leftmark}}%
        {\rightmark}%
        {\rightmark\ -- \leftmark}%
     }
  }
\newcommand{\indexmark}[1]{#1\markboth{#1}{#1}}
\makeindex[options={-M \jobname.xdy}] % two columns
%\makeindex[options={-M \jobname.xdy},columns=1] % one column

\begin{filecontents*}{\jobname.xdy}
(markup-index :open  "~n
\begin{theindex}
  \providecommand*\lettergroupDefault[1]{}
  \providecommand*\lettergroup[1]{\textbf{#1}}
  ~n"
  :close "~n~n\end{theindex}~n"
:tree)

(markup-keyword-list :open "\indexmark{" :close "}" )
\end{filecontents*}

\begin{document}
Aachen\index{Aachen} aardvark\index{aardvark} aargh\index{aargh}
Aarhus\index{Aarhus} Aaron\index{Aaron} Aaronvitch\index{Aaronvitch}
Ababa\index{Ababa} aback\index{aback} abacus\index{abacus}
abaft\index{abaft} abalone\index{abalone} abandon\index{abandon}
abandoner\index{abandoner} abase\index{abase} abaser\index{abaser}
abash\index{abash} abashed\index{abashed} abate\index{abate}
abated\index{abated} abater\index{abater} abattoir\index{abattoir}
Abba\index{Abba} abbess\index{abbess} abbey\index{abbey}
abbot\index{abbot} Abbott\index{Abbott} abbreviate\index{abbreviate}
abbreviated\index{abbreviated} abbreviation\index{abbreviation}
abbé\index{abbé} ABC\index{ABC} abdicate\index{abdicate}
abdication\index{abdication} abdomen\index{abdomen}
abdominal\index{abdominal} abduct\index{abduct}
abductee\index{abductee} abduction\index{abduction}
abductor\index{abductor} Abdul\index{Abdul} Abe\index{Abe}
abeam\index{abeam} Abel\index{Abel} Abelard\index{Abelard}
Abelson\index{Abelson} Aberconwy\index{Aberconwy}
Aberdeen\index{Aberdeen} Aberdeenshire\index{Aberdeenshire}
Abernathy\index{Abernathy} aberrant\index{aberrant}
aberration\index{aberration} Aberystwyth\index{Aberystwyth}
abet\index{abet} abettor\index{abettor} abeyance\index{abeyance}
abeyant\index{abeyant} abhor\index{abhor} abhorrence\index{abhorrence}
abhorrent\index{abhorrent} abhorrer\index{abhorrer}
abidance\index{abidance} abide\index{abide} abider\index{abider}
Abidjan\index{Abidjan} Abigail\index{Abigail} Abilene\index{Abilene}
ability\index{ability} abiogenesis\index{abiogenesis}
abiogenic\index{abiogenic} abiotic\index{abiotic} abject\index{abject}
abjection\index{abjection} abjectness\index{abjectness}
abjuration\index{abjuration} abjure\index{abjure} ablate\index{ablate}
ablation\index{ablation} ablaze\index{ablaze}
able-bodied\index{able-bodied} able\index{able} abler\index{abler}
abloom\index{abloom} ablution\index{ablution} abnegate\index{abnegate}
abnegation\index{abnegation} abnormal\index{abnormal}
abnormality\index{abnormality} aboard\index{aboard} abode\index{abode}
abolish\index{abolish} abolition\index{abolition}
abolitionism\index{abolitionism} abolitionist\index{abolitionist}
abominable\index{abominable} abominate\index{abominate}
abomination\index{abomination} aboriginal\index{aboriginal}
Aboriginals\index{Aboriginals} aborigine\index{aborigine}
abort\index{abort} aborter\index{aborter} abortion\index{abortion}
abortionist\index{abortionist} abortive\index{abortive}
abound\index{abound} about\index{about} above\index{above}
aboveboard\index{aboveboard} aboveground\index{aboveground}
abracadabra\index{abracadabra} abrade\index{abrade}
abrader\index{abrader} Abraham\index{Abraham} Abram\index{Abram}
abrasion\index{abrasion} abrasive\index{abrasive}
abrasiveness\index{abrasiveness} abreaction\index{abreaction}
abreast\index{abreast} abridge\index{abridge} abridged\index{abridged}
abridger\index{abridger} abroad\index{abroad} abrogate\index{abrogate}
abrogation\index{abrogation} abrogator\index{abrogator}
abrupt\index{abrupt} abruptness\index{abruptness} abs\index{abs}
abscess\index{abscess} abscissa\index{abscissa}
abscissae\index{abscissae} abscission\index{abscission}
abscond\index{abscond} abseil\index{abseil} abseiler\index{abseiler}
absence\index{absence} absent-minded\index{absent-minded}
absent-mindedness\index{absent-mindedness} absent\index{absent}
absentee\index{absentee} absenteeism\index{absenteeism}
absenter\index{absenter} absentia\index{absentia}
absinthe\index{absinthe} absolute\index{absolute}
absoluteness\index{absoluteness} absolution\index{absolution}
absolutism\index{absolutism} absolve\index{absolve}
absolver\index{absolver} absorb\index{absorb} absorbed\index{absorbed}
absorbency\index{absorbency} absorbent\index{absorbent}
absorbs\index{absorbs} absorption\index{absorption}
absorptivity\index{absorptivity} abstain\index{abstain}
abstemious\index{abstemious} abstemiousness\index{abstemiousness}
abstention\index{abstention} abstinence\index{abstinence}
abstinent\index{abstinent} abstract\index{abstract}
abstracted\index{abstracted} abstractedness\index{abstractedness}
abstracter\index{abstracter} abstraction\index{abstraction}
abstractionism\index{abstractionism}
abstractionist\index{abstractionist} abstractness\index{abstractness}
abstractor\index{abstractor} abstruse\index{abstruse}
abstruseness\index{abstruseness} absurd\index{absurd}
absurdity\index{absurdity} absurdness\index{absurdness} Abu\index{Abu}
Abuja\index{Abuja} abundance\index{abundance} abundant\index{abundant}
abusable\index{abusable} abuse\index{abuse} abuser\index{abuser}
abusive\index{abusive} abusiveness\index{abusiveness} abut\index{abut}
abuzz\index{abuzz} abysmal\index{abysmal} abyss\index{abyss}
abyssal\index{abyssal} Abyssinia\index{Abyssinia}
Abyssinian\index{Abyssinian} Ac\index{Ac} AC\index{AC}
acacia\index{acacia} academe\index{academe} academia\index{academia}
academic\index{academic} academician\index{academician}
academicianship\index{academicianship} academy\index{academy}
Acadia\index{Acadia} acanthus\index{acanthus} Acapulco\index{Acapulco}
ACAS\index{ACAS} acc.\index{acc.} accede\index{accede}
accelerate\index{accelerate} acceleration\index{acceleration}
accelerator\index{accelerator} accelerometer\index{accelerometer}
accent\index{accent} accented\index{accented}
accentual\index{accentual} accentuate\index{accentuate}
accentuation\index{accentuation} accept\index{accept}
acceptability\index{acceptability} acceptable\index{acceptable}
acceptableness\index{acceptableness} acceptably\index{acceptably}
acceptance\index{acceptance} acceptant\index{acceptant}
accepted\index{accepted} acceptingness\index{acceptingness}
acceptor\index{acceptor} access\index{access}
accessibility\index{accessibility} accessible\index{accessible}
accessibly\index{accessibly} accession\index{accession}
accessors\index{accessors} accessory\index{accessory}
accidence\index{accidence} accident-prone\index{accident-prone}
accident\index{accident} accidental\index{accidental}
acclaim\index{acclaim} acclaimer\index{acclaimer}
acclamation\index{acclamation} acclimate\index{acclimate}
acclimation\index{acclimation} acclimatisation\index{acclimatisation}
acclimatise\index{acclimatise} acclimatization\index{acclimatization}
acclimatize\index{acclimatize} acclivity\index{acclivity}
accolade\index{accolade} accommodate\index{accommodate}
accommodating\index{accommodating} accommodation\index{accommodation}
accommodative\index{accommodative} accompanied\index{accompanied}
accompanier\index{accompanier} accompany\index{accompany}
accomplice\index{accomplice} accomplish\index{accomplish}
accomplished\index{accomplished} accord\index{accord}
accordance\index{accordance} accordant\index{accordant}
accordion\index{accordion} accordionist\index{accordionist}
accost\index{accost} account\index{account}
accountability's\index{accountability's}
accountability\index{accountability} accountable\index{accountable}
accountably\index{accountably} accountancy\index{accountancy}
accountant\index{accountant} accounted\index{accounted}
accounting\index{accounting} accoutre\index{accoutre}
Accra\index{Accra} accredit\index{accredit}
accreditation\index{accreditation} accredited\index{accredited}
accreted\index{accreted} accretion\index{accretion}
accretive\index{accretive} accrual\index{accrual} accrue\index{accrue}
acct\index{acct} acculturate\index{acculturate}
acculturation\index{acculturation} accumulate\index{accumulate}
accumulation\index{accumulation} accumulative\index{accumulative}
accumulator\index{accumulator} accuracy\index{accuracy}
accurate\index{accurate} accurately\index{accurately}
accurateness\index{accurateness} accursed\index{accursed}
accursedness\index{accursedness} accusal\index{accusal}
accusation\index{accusation} accusative\index{accusative}
accusatory\index{accusatory} accuse\index{accuse}
accused\index{accused} accustom\index{accustom}
accustomed\index{accustomed} accustomedness\index{accustomedness}
ace\index{ace} acellular\index{acellular} acer\index{acer}
acerbate\index{acerbate} acerbic\index{acerbic}
acerbity\index{acerbity} acetaminophen\index{acetaminophen}
acetate\index{acetate} acetic\index{acetic}
acetogenic\index{acetogenic} acetone\index{acetone}
acetylcholine\index{acetylcholine} acetylene\index{acetylene}
Achaean\index{Achaean} ache\index{ache} ached\index{ached}
achene\index{achene} aches\index{aches} achievable\index{achievable}
achieve\index{achieve} achieved\index{achieved}
achievement's\index{achievement's} achievement\index{achievement}
achievements\index{achievements} achiever\index{achiever}
achieves\index{achieves} achieving\index{achieving}
Achilles\index{Achilles} aching\index{aching}
achromatic\index{achromatic} achy\index{achy} acid\index{acid}
acidification\index{acidification} acidify\index{acidify}
acidity\index{acidity} acidophil\index{acidophil}
acidophiles\index{acidophiles} acidoses\index{acidoses}
acidosis\index{acidosis} acidulous\index{acidulous}
Ackerman\index{Ackerman} acknowledge\index{acknowledge}
acknowledgeable\index{acknowledgeable}
acknowledged\index{acknowledged} ACM\index{ACM} acme\index{acme}
acne\index{acne} acolyte\index{acolyte} aconite\index{aconite}
acorn\index{acorn} acoustic\index{acoustic}
acoustical\index{acoustical} acoustician\index{acoustician}
acoustics\index{acoustics} acquaint\index{acquaint}
acquaintance\index{acquaintance}
acquaintanceship\index{acquaintanceship} acquainted\index{acquainted}
acquiesce\index{acquiesce} acquiescence\index{acquiescence}
acquiescent\index{acquiescent} acquirable\index{acquirable}
acquire\index{acquire} acquirement\index{acquirement}
acquisition\index{acquisition} acquisitions\index{acquisitions}
acquisitive\index{acquisitive} acquisitiveness\index{acquisitiveness}
acquit\index{acquit} acquittal\index{acquittal}
acquittance\index{acquittance} acquitter\index{acquitter}
acre\index{acre} acreage\index{acreage} acrid\index{acrid}
acridity\index{acridity} acridness\index{acridness}
acrimonious\index{acrimonious} acrimoniousness\index{acrimoniousness}
acrimony\index{acrimony} acrobat\index{acrobat}
acrobatic\index{acrobatic} acrobatics\index{acrobatics}
acronym\index{acronym} acrophobia\index{acrophobia}
acropolis\index{acropolis} across\index{across}
acrostic\index{acrostic} acrylate\index{acrylate}
acrylic\index{acrylic} act's\index{act's} act\index{act}
actinic\index{actinic} actinide\index{actinide}
actinium\index{actinium} actinometer\index{actinometer}
action\index{action} actionable\index{actionable}
actioned\index{actioned} actioning\index{actioning}
activate\index{activate} activated\index{activated}
activating\index{activating} activation\index{activation}
activator\index{activator} active\index{active}
actively\index{actively} activeness\index{activeness}
activism\index{activism} activity\index{activity} Acton\index{Acton}
actor\index{actor} actress\index{actress} actual\index{actual}
actuality\index{actuality} actuarial\index{actuarial}
actuary\index{actuary} actuate\index{actuate}
actuation\index{actuation} actuator\index{actuator}
acuity\index{acuity} acumen\index{acumen}
acupressure\index{acupressure} acupuncture\index{acupuncture}
acute\index{acute} acuteness\index{acuteness} acyclic\index{acyclic}
acyclovir\index{acyclovir} ad's\index{ad's} ad\index{ad}
adage\index{adage} adagio\index{adagio} Adair\index{Adair}
Adam\index{Adam} adamant\index{adamant} Adamski\index{Adamski}
Adamson\index{Adamson} adapt\index{adapt}
adaptability\index{adaptability} adaptation\index{adaptation}
adapted\index{adapted} adaptive\index{adaptive}
adaptivity\index{adaptivity} adaptor\index{adaptor} ADC\index{ADC}
add-on\index{add-on} add\index{add} addend\index{addend}
addenda\index{addenda} addendum\index{addendum} addict\index{addict}
addiction\index{addiction} Addis\index{Addis} Addison\index{Addison}
addition\index{addition} additional\index{additional}
additive\index{additive} additivity\index{additivity}
addle\index{addle} addorsed\index{addorsed} address\index{address}
addressed\index{addressed} addressee\index{addressee}
addresses\index{addresses} addressing\index{addressing}
adduce\index{adduce} adducer\index{adducer} adduct\index{adduct}
adduction\index{adduction} adductor\index{adductor}
Adelaide\index{Adelaide} Adele\index{Adele} Aden\index{Aden}
Adenauer\index{Adenauer} adenine\index{adenine} adenoid\index{adenoid}
adenoidal\index{adenoidal} adenoma\index{adenoma}
adenomata\index{adenomata} adenoviral\index{adenoviral}
adenovirus\index{adenovirus} adept\index{adept}
adeptness\index{adeptness} adequacy\index{adequacy}
adequate\index{adequate} adequateness\index{adequateness}
adhere\index{adhere} adherence\index{adherence}
adherent\index{adherent} adhesion\index{adhesion}
adhesive\index{adhesive} adhesiveness\index{adhesiveness}
adiabatic\index{adiabatic} adieu\index{adieu} adipose\index{adipose}
Adirondack\index{Adirondack} adiós\index{adiós}
adjacency\index{adjacency} adjacent\index{adjacent}
adjectival\index{adjectival} adjective\index{adjective}
adjoin\index{adjoin} adjourn\index{adjourn} adjudge\index{adjudge}
adjudicate\index{adjudicate} adjudication\index{adjudication}
adjudicator\index{adjudicator} adjunct\index{adjunct}
adjuration\index{adjuration} adjure\index{adjure} adjust\index{adjust}
adjusted\index{adjusted} adjustor's\index{adjustor's}
adjusts\index{adjusts} adjutant\index{adjutant} Adkins\index{Adkins}
Adler\index{Adler} adman\index{adman} admen\index{admen}
admin\index{admin} adminicle\index{adminicle}
adminicular\index{adminicular} administer\index{administer}
administrable\index{administrable} administrate\index{administrate}
administration\index{administration}
administrator\index{administrator}
administratrix\index{administratrix} admirable\index{admirable}
admiral\index{admiral} admiralty\index{admiralty}
admiration\index{admiration} admire\index{admire}
admissibility\index{admissibility} admissible\index{admissible}
admission\index{admission} admit\index{admit}
admittance\index{admittance} admitted\index{admitted}
admixture\index{admixture} admonish\index{admonish}
admonisher\index{admonisher} admonition\index{admonition}
admonitory\index{admonitory} ado\index{ado} adobe\index{adobe}
adolescence's\index{adolescence's} adolescence\index{adolescence}
adolescent\index{adolescent} Adolph\index{Adolph} Adonis\index{Adonis}
adopt\index{adopt} adopted\index{adopted} adoption\index{adoption}
adopts\index{adopts} adorable\index{adorable}
adorableness\index{adorableness} adoration\index{adoration}
adore\index{adore} adorn\index{adorn} adorned\index{adorned}
adrenal\index{adrenal} adrenalin\index{adrenalin}
adrenaline\index{adrenaline} Adrian\index{Adrian}
Adriatic\index{Adriatic} Adrienne\index{Adrienne} adrift\index{adrift}
adroit\index{adroit} adroitness\index{adroitness} ads\index{ads}
ADSL\index{ADSL} adsorb\index{adsorb} adsorbate\index{adsorbate}
adsorbent\index{adsorbent} adsorption\index{adsorption}
ADte\index{ADte} adulate\index{adulate} adulation\index{adulation}
adulator\index{adulator}

\clearpage
\MarkbothHack
\pagestyle{indexpagestyle}
\printindex
\UndoMarkbothHack

\chapter*{Foo}
\lipsum
\end{document}
  • Much simpler solution! :) Did you notice the last page of the index has empty headers? – Denis Bitouzé Oct 27 '16 at 15:39
  • @DenisBitouzé Thanks for the notification. The problem was that only one of the three methods for placing the \pagestyle command that I originally thought would work, guarantees that the indexpagestyle is still in effect on the last page. I have modified my answer. – gernot Oct 27 '16 at 20:18
  • This solution works nicely for the MWE but still has a problems in more general cases, e.g. in case of (a) book class , (b) the index followed by a (say unnumbered) chapter, (c) the index ending on a odd page: then the header of the page before the following chapter contains the last index entry twice. I'm not sure if I should provide an extra MWE showing this problem or if it is enough to explain how to modify yours, anyway here I go: replace article by book, remove all words after adventurously\index{adventurously}, add \chapter*{Foo} after \UndoSideEffectOfIndexPageStyle. – Denis Bitouzé Oct 28 '16 at 8:28
  • @DenisBitouzé Good point, some more undo actions required. I've updated the solution. – gernot Oct 28 '16 at 9:17
  • Close to be perfect! :) Just one extra point, which wasn't originally requested and may be controversial so feel free to not answer it (especially because I managed to answer it thanks to xifthen's \equal): suppose the index last page contains a single entry (say "foo"), one could expect the header to contain "foo" instead of "foo -- foo". – Denis Bitouzé Oct 28 '16 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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