How to avoid heading's link showing "Page x" in footnote's number

37 views
Skip to first unread message

Nhut Nguyen

unread,
May 13, 2024, 7:31:21 PMMay 13
to sphinx-users
Hi everyone,

I use Sphinx to generate PDFs for my book. If a heading contains a link like this illustration and I want it to appear in the footnote, some will show "Page x," like below. It does not always happen. Just some headings have. 
 
How can I prevent the "Page 5" in this footnote number from appearing? I want only "2", not "Page 5, 2".     sphinx.PNG
It might be a bug. But any workaround is sufficient.

Thanks
Nhut Nguyen

Steevie

unread,
May 14, 2024, 11:07:14 AMMay 14
to sphinx...@googlegroups.com
On Mon, 13 May 2024 13:57:45 -0700 (PDT), Nhut Nguyen wrote:

> Hi everyone,
>
> I use Sphinx to generate PDFs for my book. If a *heading* contains a
> *link*
> like this illustration and I want it to appear in the footnote, some
> will show "Page x," like below. It does not always happen. Just *some
> headings* have.
>
> *How can I prevent the "Page 5" in this footnote number from appearing?
> I want only "2", not "Page 5, 2". * [image: sphinx.PNG]
> It might be a bug. But any workaround is sufficient.
Can you share a minimum example that shows the behaviour?

Having said that, what about putting the link(s) not in the heading but
for example in an admonition or in some custom role (that you can
customise in latex) right below the title?

S.


jfbu

unread,
May 14, 2024, 12:39:14 PMMay 14
to sphinx...@googlegroups.com
Hi everyone,

Some minimal example would help indeed and also knowing if you use
`make latexpdf` to build the PDF output, or some other build
system which may not do as many pdflatex runs as necessary in all
circumstances (this was the case in the past with RTD, not sure
now).

Sphinx has some built-in mechanism to insert "Page N, " if the
footnote is not on same page, and in your example it looks as
if the footnote is on same page so the "Page N, " should not be there,
this is why I wondered if enough many runs are made.

Incorporating this to conf.py should fix your problem:

```
latex_elements = {
"preamble": r'\renewcommand\sphinxthefootnotemark[2]{#1}',
}
```

If you feel this is a bug, please try to produce a small example
and open a ticket at https://github.com/sphinx-doc/sphinx/

Something gets wrong in the "same page" detection mechanism.
At least with a ticket we can document is as a limitation in case
we decide we can't fix it.

JF B.

Nguyen Thanh Nhut

unread,
May 14, 2024, 5:24:01 PMMay 14
to sphinx...@googlegroups.com
Thanks, JF B.
The \renewcommand\sphinxthefootnotemark[2]{#1} really helps.🙏

Here is the code that produced the issue:
-------------------
# Container With Most Water
% Medium
## [Problem statement](https://leetcode.com/problems/container-with-most-water/)

You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `i-th` line are `(i, 0)` and `(i, height[i])`.

-------------------------
After running "sphinx -T -b latex", I ran "latexmk -r latexmkrc -pdf -f -dvi- -ps- " only once to build the pdf. 

(I do not know how to build many runs this way. It seems I have to delete the pdf folder to rebuild for many runs.)

I might prepare a small example to open a bug.
Best regards

/Nhut

--
You received this message because you are subscribed to a topic in the Google Groups "sphinx-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sphinx-users/HctkGQYk6sI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sphinx-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/v20434%24tor%241%40ciao.gmane.io.

jfbu

unread,
May 15, 2024, 5:51:39 PMMay 15
to sphinx...@googlegroups.com
Le 14/05/2024 à 23:04, Nguyen Thanh Nhut a écrit :
> Thanks, JF B.
> *The \renewcommand\sphinxthefootnotemark[2]{#1} really helps.🙏*
>
> Here is the code that produced the issue:
> -------------------
> # Container With Most Water
> % Medium
> ## [Problem statement](
> https://leetcode.com/problems/container-with-most-water/)
>
> You are given an integer array `height` of length `n`. There are `n`
> vertical lines drawn such that the two endpoints of the `i-th` line are
> `(i, 0)` and `(i, height[i])`.
>
> -------------------------
> After running "sphinx -T -b latex", I ran "latexmk -r latexmkrc -pdf -f
> -dvi- -ps- " only once to build the pdf.
>
> (I do not know how to build *many runs *this way. It seems I have to delete
> the pdf folder to rebuild for many runs.)

latexmk is fine, it is supposed to run enough many times the pdflatex binary
(or lualatex, xelatex, uplatex for Japanese documents)

>
> I might prepare a small example to open a bug.

Ok, I could reproduce. I realized you must have been using

``latex_show_urls = 'footnote'``

I used an index.rst with

```
.. toctree::

index1
index2
```

and index1.rst being

```

CHAPITRE
========

Test [1]_
---------

.. [1] note de bas de page

```

whereas index2.md is the contents in markdown you provided.

I also added ``extensions = ['myst_parser']`` to conf.py

I see now the problem on Page 3 with the url as footnote.
Running additional `pdflatex` on the tex file does not change things.

Ok I investigated a bit but the Sphinx LaTeX code for footnotes
was written quite a few years back, it does look as if there is
a bug (inside file sphinxpackagefootnote.sty in the definition
of macro \sphinxfootref, it looks as if the code \sphinx@xdef@thefnmark{#1}
is not executed at the correct time, if I move it to after the
\refstepcounter that is two lines below, so to be executed
only when \@makefnmark is, it seems problem goes away in your MWE).


I will need to wait for having some free time to understand again what
all these complex LaTeX code are supposed to do;
as it stands it does look something has always been wrong there...

so if you have time to make the issue report, that would be much
appreciated; if not I will do it myself once I get the some time
to investigate this problem. There seems to be some commented
out code in the file, which located the \refstepcounter elsewhere
but was abandoned due to https://github.com/sphinx-doc/sphinx/pull/10191#issuecomment-1038807448 which was in February 2022, I would have said more like
5 years ago, but I must have aged a lot since 2022 ;-)

Best,

Jean-François B.

jfbu

unread,
May 17, 2024, 4:56:54 AMMay 17
to sphinx...@googlegroups.com
Le 15/05/2024 à 23:51, jfbu a écrit :
> I will need to wait for having some free time to understand again what
> all these complex LaTeX code are supposed to do;
> as it stands it does look something has always been wrong there...
>

I got some time

> so if you have time to make the issue report, that would be much
> appreciated; if not I will do it myself once I get the some time

I will do it

> to investigate this problem.

There where two commits (both merged into 5.0.0 as part of PR#10191),
the initial one was ok,
but the second commit made a change due to some issue with "memoir" class
(not used by Sphinx by default)
and this change caused the order of some things to get wrong.
Testing was insufficient, and the things was buggy since.

Thanks for raising this, to get fixed in next release,
Best,
Jean-François B.



Reply all
Reply to author
Forward
0 new messages