Why do my PDF footnotes start with number 43?

103 views
Skip to first unread message

Erin Kelly

unread,
Feb 28, 2018, 7:07:59 PM2/28/18
to sphinx-users
I have a document with intersphinx cross-references. I just switched from inline URL references to footnote URL references for PDF. Everything works fine, but for some reason the first footnote is number 43! 

The numbering increases from there, so my document contains footnotes numbered 43 through 118. 

I would prefer to start at 1! 

Is there some way to change that? What could be causing it? I didn't find anything online about this problem. 

I'm running Sphinx 1.6.6 and using make latexpdf to build. 


Komiya Takeshi

unread,
Mar 2, 2018, 11:07:12 AM3/2/18
to sphinx...@googlegroups.com
Hi,

At present, latex_show_urls creates auto-numbered footnotes (ex.
[#]_). So their number starts after explicitly numbered footnotes (ex.
[1]_).
I guess your document already has 42 explicitly numbered footnotes.

Agreed. I also feel this is ugly. Please file a proposal.

Thanks,
Takeshi KOMIYA

2018-03-01 2:33 GMT+09:00 'Erin Kelly' via sphinx-users
<sphinx...@googlegroups.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "sphinx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sphinx-users...@googlegroups.com.
> To post to this group, send email to sphinx...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sphinx-users.
> For more options, visit https://groups.google.com/d/optout.

Erin Kelly

unread,
Mar 7, 2018, 6:19:43 PM3/7/18
to sphinx-users
Thanks. 

I did not use any other footnotes, but maybe LaTeX is using a footnote counter for something else during the build. (The numbers sometimes vary slightly from build to build.) 

I will look at the log and see if I can tell what's incrementing the count. 

Komiya Takeshi

unread,
Mar 8, 2018, 6:07:33 AM3/8/18
to sphinx...@googlegroups.com
Hi,

Sphinx assigns footnote numbers for latex_show_urls on generating LaTeX source.
So I suppose this is an issue of Sphinx, not LaTeX.

For example, the following example is converted to next one.

```
footnote example
================

`Sphinx <http://www.sphinx-doc.org/>`_ [1]_ [2]_ [#]_

.. [1] footnote
.. [2] footnote
.. [#] footnote
```

```
\sphinxhref{http://www.sphinx-doc.org/}{Sphinx}%
\begin{footnote}[3]\sphinxAtStartFootnote
\sphinxnolinkurl{http://www.sphinx-doc.org/}
%
\end{footnote} %
\begin{footnote}[1]\sphinxAtStartFootnote
footnote
%
\end{footnote} %
\begin{footnote}[2]\sphinxAtStartFootnote
footnote
%
\end{footnote} %
\begin{footnote}[4]\sphinxAtStartFootnote
footnote
%
\end{footnote}
```

Erin Kelly

unread,
Mar 21, 2018, 6:53:54 PM3/21/18
to sphinx-users
I realize there was a mistake in the reply I just sent, which has not yet been published.

The chapters that didn't have a gap between footnote numbers actually did not include a first-level heading. When I fixed that, the two sections became one chapter (one h1 and one subhead) and there was a skip in numbers before and after the chapter. 

Erin Kelly

unread,
Mar 21, 2018, 6:53:54 PM3/21/18
to sphinx-users
I have not been able to find a reason for this. Is there a log of what Sphinx is doing when it assigns footnote numbers? 

After I updated to Sphinx 1.7.1, I noticed an additional symptom - it not only skips numbers in the beginning, but also skips numbers between most chapters. That is, Ch.1 includes footnotes numbered 32-36, then Ch. 2 starts at footnote 51 and goes to 65. 

There is one place in my document where it doesn't skip numbers between chapters - Ch. 4 has footnotes 104-105 and Ch. 5 has footnotes 106-107. Then Ch. 6 has 123-126 so it's back to skipping numbers. Ch. 4 and Ch. 5 do not have any subheads - they only have one level per chapter. 

If I get a chance to mock up a project I will see if I can test that question about subheadings being related to the footnote numbering issue; I can't share my actual files publicly and they're a bit complicated. 

I do get error messages about _all_ of the footnotes when I build - including the ones that don't show up in the document - but I think that the error messages are not related to this problem. (Similar to this case: https://tex.stackexchange.com/questions/16268/ ) So it seems that the document thinks there's a footnote 1, it just doesn't appear in the final document. 

pdfTeX warning (dest): name{Hfootnote.3} has been referenced but does not exist
, replaced by a fixed one

pdfTeX warning (dest): name{Hfootnote.2} has been referenced but does not exist
, replaced by a fixed one

pdfTeX warning (dest): name{Hfootnote.1} has been referenced but does not exist
, replaced by a fixed one

I looked at the strategies mentioned in this thread https://github.com/sphinx-doc/sphinx/issues/3652 for forcing numbers to restart at each chapter, but I didn't get any of them to work. Resetting the numbers at the beginning of each chapter would be an acceptable workaround. 


jfbu

unread,
Mar 22, 2018, 5:43:44 AM3/22/18
to sphinx...@googlegroups.com
> --

I noticed now I have a PDF document produced with Sphinx 1.6.6
which displays similar problem, but more benign, the first footnote
being numbered 2 not 1.

The footnote number is hard-coded in LaTeX file

\begin{footnote}[2]
...
\end{footnote}

So the bug isn't in the Sphinx latex styles or classes, but
it is at time of the creation of the tex file for processing
later by pdflatex.

I will give a look, thanks for reporting. Can you please open
issue on github?

Jean-François

jfbu

unread,
Mar 22, 2018, 6:27:18 AM3/22/18
to sphinx...@googlegroups.com
ah ok, sorry in my case the minimal example looks like this

==============
FOOTNOTE ISSUE
==============

GOAL
====

A reference `Python3`_

.. _Python3: https://docs.python.org/3/tutorial/index.html


DOC
===

An explicit footnote [1]_

.. [1] Hello


and in conf.py latex_show_urls = 'footnote'

Then what happens is that in "GOAL" chapter, the created footnote
is numbered 2.

This is caused by explicit footnote later in source.

In my original document the explicit footnote numbered [1] was
on page 123, at start of Eigth chapter...

I am not sure your case is same category as this example.

Please try to produce a minimal project showing problem.

In the example above using

DOC
===

An explicit footnote [#]_

.. [#] Hello

fixes the problem. The first footnote will indeed use "1" and
the second "2".

Jean-François


jfbu

unread,
Mar 22, 2018, 6:52:48 AM3/22/18
to sphinx...@googlegroups.com
and this was already explained by Takeshi ....

footnote example
================

`Sphinx <http://www.sphinx-doc.org/>`_ [1]_ [2]_ [#]_

.. [1] footnote
.. [2] footnote
.. [#] footnote

This is exact same mechanism as in my example (sorry @tk0miya
for not reading your post :-( )

The [1]_ footnote can be arbitrarily
far in project source hence causes surprising effect on
footnotes far earlier if latex_show_urls = 'footnote'.

Is your problem of this type ?

It is possible to hack latex-sphinx to re-number
footnotes consecutively, but this is not completely
easy, the reason footnotes are numbered by LaTeX writer
and not by pdflatex is because of tables or captions
or similar complicated LaTeX things

Jean-François


Erin Kelly

unread,
Mar 22, 2018, 10:56:46 PM3/22/18
to sphinx-users
I was able to recreate this in an example project. 

It seems that all I need is to have a rst_prolog substitution with a URL, and set the LaTeX output to format those as footnotes. 

This example shows a numbering gap before the first chapter and also between the two chapters. 
footnote_debug.zip

jfbu

unread,
Mar 23, 2018, 4:03:34 AM3/23/18
to sphinx...@googlegroups.com
Hi,
> --


thanks a lot for attached small project,

turns out at

https://github.com/sphinx-doc/sphinx/issues/3652#issuecomment-303195583

there is a possible work-around at pdflatex level, it instructs
pdflatex to ignore the Sphinx hardcoded footnote numbers and
to number them itself. This also means they are numbered per
chapter in the final pdf (for docclass 'manual'), which
are sections in your sources.

Concrectely in your test-case this means using

```
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

'releasename': ' ',

# Additional stuff for the LaTeX preamble.
'preamble': r'''
\makeatletter
\def\FNH@footnoteenv@i[#1]{\FNH@footnoteenv}
\def\FNH@footnotetextenv@i[#1]{\FNH@footnotetextenv}
\def\sphinxfootnotemark [#1]%
{\ifx\thepage\relax\else\protect\spx@opt@BeforeFootnote
\protect\footnotemark\fi}%
\makeatother
''',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}
```

as I pointed out in link above, this may not be fully robust
(there is a reason why Sphinx numbers itself the footnotes,
but obviously this goes bad in your use case)

Could you please open an issue at https://github.com/sphinx-doc/sphinx/issues,
attaching your zip ?

Hope the above helps,

Jean-François

Erin Kelly

unread,
Mar 26, 2018, 9:34:02 PM3/26/18
to sphinx-users
Thank you, Jean-François!


The workaround is working well for me. (I actually slightly prefer having the footnote numbering restart at each chapter.) 
Reply all
Reply to author
Forward
0 new messages