For a given work, I have a continuous numerotation throughout all the document using a counter.
I need the index entries refer to the paragraph numbers and not to the pages. This is the same issue than this thread, except I am not using memoir but book. Unfortunately, the solution presented does not work anymore switching from one document class to an other.
I have been looking at this other thread. The solution looks really good, except it displays the counter's title instead of the counter's number.
Here is the code :
\begin{filecontents*}{raphink.ist}
delim_0 ""
\end{filecontents*}
\documentclass[a4paper]{report}
\usepackage{etoolbox}
\newcounter{subpara}
\newcommand\numsubpara[1]{%
\stepcounter{subpara}%
\expandafter\gdef\csname cursec\thesubpara\endcsname{#1}%
\thesubpara. \textbf{#1}}
\usepackage{imakeidx}
\makeindex[options=-s raphink]
\makeatletter
\let\@Index\@index
\patchcmd{\@Index}{\@wrindex}{\@Wrindex}{}{}
\let\@Wrindex\@wrindex
\patchcmd{\@Wrindex}{\thepage}{\thesubpara}{}{}
\let\xIndex\index
\patchcmd{\xIndex}{\@index}{\@Index}{}{}
\patchcmd{\xIndex}{\@index}{\@Index}{}{}
\let\protected@iwrite\protected@write
\patchcmd{\protected@iwrite}{\write}{\immediate\write}{}{}
\patchcmd{\@Wrindex}{\protected@write}{\protected@iwrite}{}{}
\makeatother
\newcommand{\Index}[1]{\xIndex{#1|transform}}
\newcommand{\transform}[1]{\forcsvlist\decodesec{#1}}
\newcommand{\decodesec}[1]{, \csname cursec#1\endcsname}
\begin{document}
\chapter{Test1}
\numsubpara{title1}
\Index{Test}
\chapter{Test2}
\numsubpara{title2}
\Index{Test}
\printindex
\end{document}
And the result :
If I have well understood, I would have to switch this :
\newcommand\numsubpara[1]{%
\stepcounter{subpara}%
\expandafter\gdef\csname cursec\thesubpara\endcsname{#1}%
\thesubpara. \textbf{#1}}
For that :
\newcommand\numsubpara[1]{%
\stepcounter{subpara}%
\expandafter\gdef\csname cursec\thesubpara\endcsname{\thesubpara}%
\thesubpara. \textbf{#1}}
But when I do this, I get this result :
Instead of "Test, 1,2".
Does anyone know how to have the index entries refer to the paragraph numbers and not to the pages ?



memoiras it encompasses all thatbookdoes, and much more? Just replacebookwithmemoirand perhaps change some of the options in your\documentclasscommand. – Peter Wilson Apr 24 '20 at 16:56memoir: a lot of different formatting do not work anymore. Here are some examples : I have used \usepackage[newparttoc]{titlesec} to format \part title in my toc, doesn't work anymore; I have used \usepackage[cam,width=17.5truecm,height=25.54truecm,center,dvips,noinfo]{crop} for printing marks, doesn't work anymore; \setstretch{1.1}; etc... A solution working withbookwould be really appreciated ! Thanks :) – Guliup Apr 27 '20 at 08:12\thesubparaalways refers to the very last value the counter takes. If you make a test with 4 indexedsubparasrather than two in your examples, you always get values of 4, indicating that\thesubparavalue in your index refers to the variable at its 'last state' in the document, not at the value it had in the place where it was set (which is what you want to get) - so it does not refer to the pages in you current example. If that's what you wanted to know (not sure) – LaTeX Ninja Apr 27 '20 at 12:42\thesubparawas working this way, thank you very much. It explains why it is not working... Do you have any idea how to build something working? By the way, I have tried making a test with 4 indexedsubpara, and strangely it displays nothing.. – Guliup Apr 27 '20 at 13:01\Index{Bla}- for example, if you add ```\newpage bla \newpage bla\chapter{Test3}
\numsubpara{title3} \Index{Bla}
\chapter{Test4}
\numsubpara{title4} \Index{Bla} ``` to your document, you can see that even with the
– LaTeX Ninja Apr 27 '20 at 13:19\newpages, you still get the value 4, not 5 which is the current latest page\newcounter{NewCounter} \makeatletter \newcommand{\Indextest}[1]{\imki@wrindexentry{MyIndex}{#1}{\theNewCounter}} \makeatother \makeindex[name=MyIndex]before\begin{document}and this after your\printindex: ```\stepcounter{NewCounter}\chapter{xx}\Indextest{xx} \arabic{NewCounter}\stepcounter{NewCounter}\chapter{xx}\Indextest{xx} \arabic{NewCounter}
\printindex[MyIndex]``` - seems to be working to me (although not sure if it's the desired behaviour)
– LaTeX Ninja Apr 27 '20 at 13:41columns:\makeindex[name=MyIndex, columns=2, options= -s tablealphab.ist]– Guliup Apr 27 '20 at 14:12memoirprovides its own methods for the packages you mentioned. – Peter Wilson Apr 27 '20 at 18:05