I encountered the same issue. HTML compiled without errors for me, but LaTeX compilation did throw the hyperref
errors you described. It seems to me that, for some obscure reason, Sphinx does not create the labels that hyperref
tries to reference.
I came up with the following solution: since I do not know how to include the missing labels, I will just make it so that LaTeX does not look for them anymore. In detail, I am doing this by overwriting the \hyperref
command.
I included the following code in my conf.py
file:
latex_elements = {
'preamble': r'''
\renewcommand{\hyperref}[2][]{#2}
'''
}
This includes the \renewcommand{...
in the preamble of the LaTeX document created by Sphinx. It will overwrite the \hyperref
command so that it won't try to insert a link, but just print the link text.
Obviously, with this solution, the reference that caused the errors will not appear as hyperlinks in your PDF document, but at least it is compiling without errors.
Note
What I described worked perfectly fine for my use case, however, it is described in the Hyperref manual that the \hyperref
command can be invoked in two different ways (\hyperref{URL}{category}{name}{text}
and \hyperref[label]{text}
). I am only overwriting the second one, as that seems to be the one that Sphinx is using for cross references. However, not accounting for the first one when overwriting the command might lead to issues in some cases.