latex-lineno / lineno

lineno – Line numbers on paragraphs
Other
11 stars 2 forks source link

Cross referencing with lineno + xr package with pagewise option #9

Closed Koushikphy closed 10 months ago

Koushikphy commented 11 months ago

I want to refer to a line no/page no to a different document. The lineno package can refer to a line/page number and the xr package can cross reference between multiple documents.

Here is my sample document:

doc1.tex


\documentclass[11pt]{article}
\usepackage[pagewise]{lineno}

\linenumbers
\begin{document}

hi there

\newpage

\linelabel{test} hi there page 2

Reference in doc1 line \ref{test} page \pageref{test}

\end{document}

doc2.tex

\documentclass[11pt]{article}
\usepackage[pagewise]{lineno}
\linenumbers
\usepackage{xr}
\externaldocument{doc1}

\begin{document}
Reference in doc2 line \ref{test} page \pageref{test}
\end{document}

In doc1 it genertates

Reference in doc1 line 1 page 2

In doc2 it genertates

Reference in doc1 line 2 page 2

So, it seems like when used through the xr package it does not consider the pagewise option. How do I properly refer the labels in doc2 so that it generates proper page and line number considering the pagewise option

kwwette commented 11 months ago

@Koushikphy It looks like lineno does a test that the referenced line number exists in the current document. This test then fails when using xr.

To disable the test, I added \def\testNumberedPage{} after importing lineno, and I get Reference in doc2 line 1 page 2 in doc2.pdf. So this seems to fix your issue.

Koushikphy commented 11 months ago

Okay If I modify the as per the following:
doc1.tex

\documentclass[11pt]{article}
\usepackage[pagewise]{lineno}

\linenumbers
\begin{document}

    hi there

    hello there

    hello there

    \newpage

    test 1

    \linelabel{test} hi there page 2

    Reference in doc1 line \ref{test} page \pageref{test}

\end{document}

and doc2.tex

\documentclass[11pt]{article}
\usepackage[pagewise]{lineno}
\linenumbers
\usepackage{xr}
\externaldocument{doc1}

\def\testNumberedPage{}

\begin{document}
    Reference in doc2 line \ref{test} page \pageref{test}
\end{document}

In doc1 it genertates

Reference in doc1 line 2 page 2

In doc2 it genertates

Reference in doc2 line 4 page 2

They are still not same and in the doc2 the number start from 0 now instead of 1

kwwette commented 11 months ago

@Koushikphy I'm afraid I don't have the time to look into this further, but the above might help you get started debugging this. If you're able to find the problem I'd be happy to accept a PR provided that existing lineno behaviour is preserved.