I want to show line number in index entry, like this question showing-line-number-in-glossaries. The Test Code below
\documentclass{report}
\usepackage{xcolor}
%%%%%%%%LINE NUMBER
\usepackage[running]{lineno} %[switch,columnwise,pagewise]
\renewcommand\thelinenumber{{\arabic{linenumber}}}
\renewcommand\linenumberfont{\color{red}}
\modulolinenumbers[1]
\usepackage[centering,top=4cm,bottom=4cm,left=4cm,right=4cm,headsep=0.5cm,footskip=0cm,columnsep=50pt]{geometry}
\setlength\linenumbersep{0.29cm}
\setlength{\linenumberwidth}{4mm}
\usepackage{etoolbox}
\preto{\sffamily}{\resetlinenumber}%resetting line num to 1 per page
\usepackage[pagestyles]{titlesec}
\newpagestyle{mapage}{%
\sethead[][\sffamily\bfseries\textcolor{blue}{\thepage}][]
{}{\sffamily\bfseries\textcolor{blue}{\thepage}}{}%odd head
\setfoot[][][]%even foot
{}{}{}
}
\newcommand{\llabel}[1]{\hypertarget{llineno:#1}{\linelabel{#1}\labelcolumnline{#1}}}
\newcommand{\lref}[1]{\hyperlink{llineno:#1}{\ref*{#1}}}
\newcommand{\lpageref}[1]{\hyperlink{llineno:#1}{\pageref*{#1}}}
% https://tex.stackexchange.com/questions/516140/columnwise-line-numbering-in-a-two-column-environment-with-multicol
% \setlength{\columnsep}{1cm}
\newlength{\midpage}
\setlength{\midpage}{.5\paperwidth}
\usepackage{zref-savepos}
\newcommand\labelcolumnline[1]{%
\hypertarget{llineno:#1}{\zsavepos{#1}%
\linelabel{#1}}%
}
\newcommand\refcolumnline[1]{%
\ifnum\number\zposx{#1}>\number\midpage\relax \textbf{R}\else \textbf{L}\fi%
\hyperlink{llineno:#1}{\ref{#1}}%
}
%%%%%%%%
\newcommand{\pclref}[1]{[\textit{P\lpageref{#1}/\refcolumnline{#1}}]}
\usepackage[hidelinks,colorlinks=false,breaklinks=true,urlcolor=red]{hyperref}
\usepackage{imakeidx}
\usepackage{blindtext}
\makeindex[name=lineno,title={Index with Line Number}]
%%%%%%DEFINE LINE NUMBER INDEX
\newcommand{\lindex}[1]{\textcolor{blue}{\textbf{\textit{#1}}}\index[lineno]{#1| \textbf{L\thelinenumber}-P}}%% ?????????
\pagestyle{mapage}
\begin{document}
\twocolumn
\linenumbers
\textbf{TEST Left}\llabel{TEST1}
LONDON, Sept 5 (Reuters) - Liz Truss will become Britain's next prime minister after winning a leadership race for the governing \lindex{Conservative Party} on Monday, vowing to press ahead with promised tax cuts and action to tackle a deepening energy and cost of living crisis.Register now for \lindex{FREE} unlimited access to Reuters.com
Truss beats ex-finance minister Sunak to be new PM
Boris Johnson to formally step down on Tuesday
New leader faces cost of living, energy price crisis
LONDON, Sept 5 (Reuters) - Liz Truss will become Britain's next prime minister after winning a leadership race for the governing Conservative Party on Monday, vowing to press ahead with promised tax cuts and action to tackle a deepening energy and cost of living crisis.
After weeks of an often bad-tempered and divisive leadership contest, Truss, currently the foreign minister and the favourite to win, beat former finance minister Rishi Sunak in a vote of Conservative Party members, winning by 81,326 votes to 60,399.
Advertisement · Scroll to continue
"I will deliver a bold plan to cut taxes and grow our economy," Truss said after the result was announced. "I will deliver on the energy crisis, dealing with people's energy bills, but also dealing with the long-term issues we have on energy supply." read more
Truss takes over as the country faces a crunch on household finances, industrial unrest, a recession and war in Europe, where Britain has been a leading backer of Ukraine. She appeared to rule out another national election before 2024, when she promised to deliver a great victory for her party.
After weeks of an often bad-tempered and divisive leadership contest, Truss, currently the foreign minister and the favourite to win, beat former finance minister Rishi Sunak in a vote of Conservative Party members, winning by 81,326 votes to 60,399.
\textbf{TEST Right}
\llabel{TEST2}
LONDON, Sept 5 (Reuters) - Liz Truss will become Britain's next prime minister after winning a leadership race for the governing Conservative Party on Monday, vowing to press ahead with promised tax cuts and action to tackle a deepening energy and cost of living crisis.
After weeks of an often bad-tempered and divisive leadership contest, Truss, currently the foreign minister and the favourite to win, beat former finance minister \lindex{Rishi Sunak} in a vote of Conservative Party members, winning by 81,326 votes to 60,399.Register now for FREE unlimited access to Reuters.com
Summary
Truss beats ex-finance minister Sunak to be new PM
\lindex{Boris Johnson} to formally step down on Tuesday
New leader faces cost of living, energy price crisis
LONDON, Sept 5 (Reuters) - Liz Truss will become Britain's next prime minister after winning a leadership race for the governing Conservative Party on Monday, vowing to press ahead with promised tax cuts and action to tackle a deepening energy and cost of living crisis.
After weeks of an often bad-tempered and divisive leadership contest, Truss, currently the foreign minister and the favourite to win, beat former finance minister Rishi Sunak in a vote of Conservative Party members, winning by 81,326 votes to 60,399.
Advertisement · Scroll to continue
"I will deliver a bold plan to cut taxes and grow our economy," Truss said after the result was announced. "I will deliver on the energy crisis, dealing with people's energy bills, but also dealing with the long-term issues we have on energy supply." read more
Truss takes over as the country faces a crunch on \lindex{household} finances, industrial unrest, a recession and war in Europe, where Britain has been a leading backer of Ukraine. She appeared to rule out another national election before 2024, when she promised to deliver a great victory for her party.\llabel{TEST3}
\pclref{TEST1} in Page \lpageref{TEST1} Left Line \lref{TEST1}
\pclref{TEST2} in Page \lpageref{TEST2} Right Line \lref{TEST2}
\pclref{TEST3} in Page \lpageref{TEST3} Left Line \lref{TEST3}
\onecolumn
\nolinenumbers
\printindex[lineno]
\end{document}
Then the output is wrong line info, how to get index entry page style like P7/L16 or P7/R17?
TKS!
update 20220906
Referring to @Cicada's notes, I reset line number per page by \usepackage{etoolbox}\preto{\sffamily}{\resetlinenumber}
, and introduce lineno package with running tag. Then the line number in index shows nearly right, but not right.
The line number outputted is the first line's number of the paragraph where the entry appears:
So WHY it so weird?
\thelinenumber
is what the manual calls the "real" or "hidden" (unique) line number; the pagewise line number for display is a calculated offset which looks like it leads to an unexpandable macro (\getpagewiselinenumber
) - so not usable to write to index, and it looks like theswitch
option is confusing the\getrefcounter
fromrefcount
package (as another solution) because it is running too early from 2nd run on to pick up any info. Options: (a) have running numbers; (b) calc your own offset for page/col-wise numbers; (c) useglossaries
in index mode as per linked question; ...lineno.sty
line 933 says: "% The line numbering is controlled via ~\par~.", which begins to make sense, since lines can be adjusted and re-set multiple times (via penalties etc) when inside a paragraph, I understand.\ref
s can be output (when suitably expanded), but that means no duplicates.