New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LaTeX: fix footnote marks for multiple references #10191
Conversation
I used this project to make tests: |
I am converting this to draft because in some circumstances (in particular for Sphinx own doc) the latex aux file never stabilizes and latexmk ends with an error:
I have not investigated yet, but the simple explanation coming to mind could be that in case a footmark is on page N and footnote on page N+1, the footmark will be printed as Maybe the explanation is otherwise... anyhow, not knowing if I can solve this soon, I converted this to draft. |
I don't know if it can be solved, but as a workaround, I'd provide a setting to disable the The "safe" thing would be to ensure that the footnote mark, with or without page, always takes the same width, which doesn't seem easy. Maybe add the page above/below the footnote mark? Anyway, it is still possible to have simple documents end up in an infinite loop (https://tex.stackexchange.com/a/79699). |
@Jellby Thanks for the nice ideas! Currently the immediate fix is that I remove the enhanced footnote marks only in those cases where they did not exist earlier, i.e. in the case of the |
Page detection left to apply as was case before this PR, i.e. only for the \sphinxfootnotemark mark-up, which means either in combination with footnotetext environment, or for multiply referred-to footnotes and the extra footnote marks additional to the initial one. This is to avoid a problem with each LaTeX pass in certain circumstances modifying the aux file, and latexmk consequently complaining. refs: sphinx-doc#10191 (comment)
@Jellby I have taken a conservative approach and kept the focus on fixing #10188. The behaviour of footnote marks regarding to checking page numbers will be as formerly, i.e. will happen for multiply referred-to footnotes only for additional references beyond initial ones, or will happen for footnotes which due to problematic context were rendered using Extra PRs for master could add new features such as a toggle to activate or deactivate page number indicators in footnote marks... |
Shouldn't there be a comma between multiple footnotes? I get it with my patch and 4.4.0 (at least in my target document), but not with this PR. e.g.
|
@Jellby strange, LaTeX does not put commas, and Sphinx neither, in case of successive |
Yeah, I was a bit puzzled, I didn't really know where the comma came from, but I was glad to see it. I think it may be the |
ah yes, it is the |
@Jellby The cause of the infelicity with |
index 7df49b145..6c289ca8d 100644
--- a/sphinx/texinputs/sphinxpackagefootnote.sty
+++ b/sphinx/texinputs/sphinxpackagefootnote.sty
@@ -398,7 +398,16 @@
}%
\protected\def\sphinxfootref#1{% #1 always is explicit number in Sphinx
\spx@opt@BeforeFootnote
- \refstepcounter{sphinxfootnotemark}\label{footnotemark.\thesphinxfootnotemark}%
+ % temporary workaround for memoir very fragile test of successive footnote marks
+ \@ifclassloaded{memoir}
+ {\ifdim\lastkern=\multiplefootnotemarker\relax
+ \refstepcounter{sphinxfootnotemark}\label{footnotemark.\thesphinxfootnotemark}%
+ \m@mmf@prepare
+ \else
+ \refstepcounter{sphinxfootnotemark}\label{footnotemark.\thesphinxfootnotemark}%
+ \fi
+ }
+ {\refstepcounter{sphinxfootnotemark}\label{footnotemark.\thesphinxfootnotemark}}%
\let\spx@saved@makefnmark\@makefnmark
\ltx@ifundefined{r@\thesphinxscope.footnote.#1}%
{\gdef\@thefnmark{?}}% on first LaTeX run is kind of thing which re-establishes memoir compatibility but when I get time I will try to think of something better and also I need to check if memoir behaviour is always same or possibly modified by options etc... edit: finally I opted for a somewhat different way in latest commit. I hesitated taking this opportunity to add to Sphinx the memoir feature of separating by commas successive footnote marks, but preferred to keep minimal changes. |
Fix sphinx-doc#10188 Footnotes in some LaTeX environments (tables, fulllineitems for object descriptions) are gathered and appear after the environment, causing the footnote to possibly appear on a page later than some of the footnote marks referring it. With this commit, the footnote mark compares page numbers and incorporates the destination page number if it turns out to be distinct from the page where it stands.
Page detection left to apply as was case before this PR, i.e. only for the \sphinxfootnotemark mark-up, which means either in combination with footnotetext environment, or for multiply referred-to footnotes and the extra footnote marks additional to the initial one. This is to avoid a problem with each LaTeX pass in certain circumstances modifying the aux file, and latexmk consequently complaining. refs: sphinx-doc#10191 (comment)
The signature may contain an auto-generated footnote, which now always sets a label (formerly this happened only for multiply referred-to footnotes so the problem did not arise).
cb73d16
to
0b22f5b
Compare
Rebased on 5.x, tests pass I propose to merge this... |
Page detection left to apply as was case before this PR, i.e. only for the \sphinxfootnotemark mark-up, which means either in combination with footnotetext environment, or for multiply referred-to footnotes and the extra footnote marks additional to the initial one. This is to avoid a problem with each LaTeX pass in certain circumstances modifying the aux file, and latexmk consequently complaining. refs: sphinx-doc#10191 (comment)
Fix #10188
Footnotes in some LaTeX environments (tables, fulllineitems for object
descriptions) are gathered and appear after the environment, causing the
footnote to possibly appear on a page later than some of the footnote
marks referring it.
With this commit, the footnote mark compares page numbers and
incorporates the destination page number if it turns out to be distinct
from the page where it stands.
Feature or Bugfix
both Feature andBugfixRelates
This is bugfix of #10188,
but at same time it solves some other issues with footnotes. For example footnotes in a long table extending over more than one page will now indicate the page number where footnote text is located, and everything is hyperlinked.(edit: this was already the case)Contrarily to what I said at #10175 (comment), this commit so far does not modify the syntax of the latex
\sphinxfootnotemark
. However it does modify some internals of Sphinx latex handling of footnotes, simplifying the mark-up via the removal of explicit\phantomsection
and\label
which are now inserted internally to latex macro expansion. Also it removes\sphinxstepexplicit
which was introduced at #8832, as the usage of\sphinxstepscope
at each file input via #10169 appears to ensure correct behaviour for explicitly numbered or named footnotes which are multiply referred-to.edit: footnote marks compare page numbers of location of mark and location of footnote text, in those cases:
footnotetext
environment and separated mark (or marks)This PR does not modify this situation, because an attempt to extend this to all cases caused a problem #10191 (comment)
so this PR is only bugfix of #10188, although it includes changes, currently partially commented out, which can possibly be built upon in future.