2

I need to mention that a concept is explained in paragraph x in page y.

Here, I have an example which shows paragraph number for me in a wrong way. It shows paragraph 1 no matter which paragraph of the page the target is.

Linux is explained in page 3, paragraph 1 at here.

\documentclass{article}

\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}

\newcommand{\mylink}[1]{{\hypersetup{hidelinks=true}page \pageref{#1}, paragraph \ref{#1}} at \hyperlink{#1}{here}}
\newcommand{\mytarget}[1]{\hypertarget{#1}{\label{#1}}}


\title{Your Paper}

\begin{document}

\section{Introduction}

Linux is explained in \mylink{linux}.

\lipsum[1-13]

\mytarget{linux}
This is a paragraph about Linux.

\lipsum[1-2]

\end{document}
6
  • This code in overleaf: overleaf.com/10121092jwnvtgnbhxcb#/37338338
    – ar2015
    Jun 26, 2017 at 8:42
  • 2
    You are still in the first section… You need to add some sections/subsections to advance your counter. ref also does not count paragraphs in text blocks but refers to the surrounding section/subsection. You change the numbering scheme to count down to \paragraph (With a number code as (chapter).section.subsection.paragraph.(subparagraph)) but you still have to put in the block header (\section{<name>}) yourself.
    – Huang_d
    Jun 26, 2017 at 9:20
  • you need to add a command \mypar or \startpar at the start of each paragraph that step a counter myparcounter.
    – touhami
    Jun 26, 2017 at 11:59
  • @Huang_d, I do not understand what you mean. Could you please edit the overleaf code?
    – ar2015
    Jun 26, 2017 at 12:52
  • @touhami, it is a good idea but a bit impractical.
    – ar2015
    Jun 26, 2017 at 12:53

1 Answer 1

4

I added a new counter (parno) which is incremented by \everypar. Note that \everypar gets redefined and may need to be renewed frequently.

Also, \label refers to the last counter incremented by \refstepcounter and should therefore be closer to the start of the paragraph than any equation or other counter incrementing command.

\documentclass{article}

\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}

\newcounter{parno}[page]
\renewcommand{\theparno}{page \thepage, paragraph \arabic{parno}}

\title{Your Paper}

\begin{document}

\section{Introduction}
\everypar{\refstepcounter{parno}}

Linux is explained in \ref{linux}.

\lipsum[1-13]

\leavevmode\label{linux}%
This is a paragraph about Linux. 

\lipsum[1-2]

\end{document}
2
  • Is there some way for the counter to include a partial paragraph at the start of a page? That is, if there is part of a paragraph that runs from the previous page to the current (i.e., the current page does not start with a fresh paragraph), the partial paragraph is counted as the first paragraph of the current page?
    – tvk
    Jul 28, 2020 at 19:54
  • @FangJing - Try \afterpage{\ifvoid\AP@partial \else \stepcounter\parno \fi} (one page only). Actually, you will need another macro for the test to loop it and \makatletter. Jul 28, 2020 at 20:42

You must log in to answer this question.

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