1

Following this question, I have a new challenge for you ! Quick summary :

For a given index entry appearing on pages 1 to 4, I need page ranges on my index to appear as " 1 s." and not "1--4".

This was the answer, using a .ist file with this piece of code :

suffix_2p " s"
suffix_3p " s"
suffix_mp " s"

BUT: here is the trick. If the page ranges are part of a longer list here is the wanted result :

Word, 1, 4, 7 s., 12, 15 s.

Right now, I can get :

Word, 1, 4, 7 s., 12, 15 s..

Or :

Word, 1, 4, 7 s, 12, 15 s.

Does anyone have any idea on this ?

Here is my code :


\begin{filecontents*}{alphab.ist}

headings_flag 1
delim_0 "} , "
delim_1 ", "
delim_2 ", "
delim_t ". "
item_0 "\n  \\item \\textbf{"
item_1 "\n    \\subitem "
item_01 "\n    \\subitem "
item_x1 "}.\n    \\subitem "

suffix_2p " s."
suffix_3p " s."
suffix_mp " s."


\end{filecontents*}







\documentclass[12pt,twoside]{book}
\usepackage[paperheight=240mm,paperwidth=160mm, left=22mm, right = 20mm, top = 20mm, bottom = 22mm]{geometry}

\usepackage[cam,width=17.5truecm,height=25.54truecm,center,dvips,noinfo]{crop}
\usepackage[french]{babel}


\usepackage{fontspec}
\usepackage{xltabular}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{lipsum}
\usepackage[newparttoc]{titlesec}%
\usepackage{titletoc}
\usepackage{supertabular}
\usepackage{xcolor}
\definecolor{gray}{HTML}{BCBDC0}
\definecolor{white}{HTML}{FFFFFF}
\usetikzlibrary{positioning,shapes.misc}
\usepackage{emptypage}







\newcounter{subpara}
\setcounter{subpara}{0}
\newcommand\numsubpara[1]{\vspace{0.5cm}\par\refstepcounter{subpara} \fontsize{10}{12}\selectfont \thesubpara. \fontsize{12}{12}\selectfont \space#1\space\vspace{0.3cm}\\  \fontsize{12}{12}\selectfont}


\usepackage{multicol}
\setlength{\columnsep}{0.6cm}


\usepackage{imakeidx}
\indexsetup{othercode=\footnotesize}

\renewcommand*{\seename}{V.}
\renewcommand*{\alsoname}{V. aussi}

\makeatletter
\renewcommand\@idxitem{\par}
\renewcommand\subitem{}
\makeatother

\makeatletter
\newcommand{\Index}[1]{\imki@wrindexentry{MyIndex}{#1}{\thesubpara}}
\makeatother

\makeindex[name=MyIndex, options= -s alphab.ist]%

\indexsetup{
  %level=\chapter,% <-- already default
  othercode={%
    \thispagestyle{alphab-title}%
    \small\raggedright
  }
}

\makeatletter
\renewcommand{\indexname}{}

\makeatother


\begin{document}

\chapter{Test1}
\section{Test2}
\numsubpara{title1}
\Index{Test}
\section{Test2}
\numsubpara{title1}
\Index{Test}

\newpage bla \newpage bla \chapter{Test3} \numsubpara{title3} \Index{Bla} \chapter{Test4} \numsubpara{title4} \Index{Bla}

\numsubpara{title5}
\numsubpara{title6}
\Index{Bla}

\newpage
\setlength{\columnsep}{-9.6cm}
\begin{multicols}{2}
\printindex[MyIndex]
\end{multicols}
\setlength{\columnsep}{0.6cm}

\end{document}

1 Answer 1

2

That's not difficult, actually. Change the .ist to have

suffix_2p " s\\maybeadddot"
suffix_3p " s\\maybeadddot"
suffix_mp " s\\maybeadddot"

and add the following in a \makeatletter context:

\newcommand{\maybeadddot}{\@ifnextchar.{}{.}}

This way, s will be followed by \maybeadddot in the .ind file; if it is followed by a period, the macro does nothing, otherwise it prints a period.

1
  • You are too good... Well played and thank you !
    – Guliup
    May 7, 2020 at 18:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .