Sphinx cross-reference in LaTeX - latex

I have the following reference identified in file A:
.. _my-label:
and I reference it in file B :
this is a reference to file A :ref:`my-label`
This generates a cross-reference as expected when outputting HTML. However, when outputting LaTeX, it does not and I have the classical warning:
LaTeX Warning: Hyper reference `my-label:my-label' on page XX undefined on input line YY.
Is there a LaTeX trick like double compilation or something similar that I am not doing correctly?

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.

Related

Atom keybindings and the LaTeX package

I want to change the keybinding for building in LaTeX from the default ctrl-alt-b to cmd-b. Settings suggests I copy paste
'atom-text-editor[data-grammar~='latex']':
'cmd-b': 'latex:build'
into the keymap.cson file but upon saving it I get the error message
[stdin]:20:34: error: unexpected latex
'atom-text-editor[data-grammar~='latex']':
^^^^^
Since the whole expression is inside a pair of single quotes, you need to use different quotes around latex:
"atom-text-editor[data-grammar~='latex']":
or
'atom-text-editor[data-grammar~="latex"]':
Also note, that you will likely run into a conflict with existing keybindings. The keybinding-resolver package is a great helper to find conflicting keybindings.

Doxygen COMPACT_LATEX seems to generate incorrect Latex

I am trying to generate Latex output from Doxygen (1.8.9.1) on Windows 7 with DoxyWizard. My code is a small Python class and I just want the few pages that describe the class and its members or methods. Doxygen and Latex work fine but generate lots of empty or nearly empty pages (save a tree!).
When I set COMPACT_LATEX=YES then the first line of refman.tex becomes \documentclass[twoside]{article} . When I run the Make.bat (which in turn runs the Makefile), the Latex processing halts with:
! Undefined control sequence.
l.132 \backmatter
This is telling me that the article class is not expecting the usual front/back matter that would go in a book. With COMPACT_LATEX=NO, the first line is \documentclass[twoside]{book} and of course it runs fine but generates those extra pages.
Is there a way to suppress the backmatter in the Latex output when running with COMPACT_LATEX=NO ?
Perhaps this is a bug in Doxygen?
Thanks
--Louis

How do I find the location of a Doxygen latex error?

My question is similar to this one.
Doxygen is outputing a warning while trying to generate docs for HTML:
warning: reached end of file while inside a f$ block!
The command that should end the block seems to be missing!
I understand what this means, but I have lots of LaTeX in this particular document. Unfortunately, the line number of the error is just the last line in the file, and Doxygen doesn't output the the \f$ that opened the math mode.
Is there a way to get Doxygen to output this, rather than me having to scour the file for a missing or malformed \f$? Something that might produce more verbose errors?
Before I finished typing this question, I found the offending line by browsing the generated HTML and looking for a function in that file that didn't get documented. That at least gave me enough of a hint for where to start looking. Still it would be great if there was a more concrete answer to this.
When generating for Latex with Doxygen, it is indeed not obvious to spot errors. One solution is to get down into the latex generated folder, and try these steps:
Run generated makefile ($ make), and look for pdflatex compiler output,
If it fails, load the file refman.tex into some Latex IDE (say, Texstudio or equivalent) and try to compile from there.
If still unable to locate error, you can run manually pdflatex with option halt-on-error:
($ pdflatex -halt-on-error refman.tex). This way, it will stop immediately at the error location.

extra "file://" prefix generated by pdflatex using hyperref package in macro

The LaTeX hyperref package confuses me in several ways. Here's my particular problem.
In my document, the command
\footnote{
\url{http://www.boston.com/news/science/articles/2010/04/25/new_atlas_shows_the_state_of_nature_as_well_as_the_nature_of_states/}
}
works just fine - pdflatex generates just the valid link.
But the commands
\newcommand{\webref}[1]{\footnote{\url{#1}}}
\webref{http://www.boston.com/news/science/articles/2010/04/25/new_atlas_shows_the_state_of_nature_as_well_as_the_nature_of_states/
}
generates the link
file:///C|/eb/qrbook/%20http://www.boston.com/news/science/articles/2010/04/25/new_atlas_shows_the_state_of_nature_as_well_as_the_nature_of_states/
Can someone tell me where the extra "file://..." comes from, and how to get rid of it?
Wild guess: Are you sure you're not introducing any extraneous spaces anywhere? I can reproduce the behaviour if I introduce a linebreak just before #1. (Pro tip: Put a % just after the last character in multi-line commands, so LaTeX doesn't process the newline.)

Odd Bibtex behaviour in a Latex document

I added a line "\cite{test}" as a test to my working Latex document. When I compiled the bibtex "!bibtex name_of_my_file, I got the expected error:
Warning--I didn't find a database entry for "test"
Then, I removed the line and compiled the bibtex again, hoping to have a working Latex file again. However, the same error occurs, even with a fresh shell. I cannot understand the behaviour. What is the logic? How can I get my Latex document working again?
[Updated Info]
The problem dissapeared as unexpectedly as it emerged. I have no idea why but it works now. Do you know the reason for the odd behaviour?
I think you are tripping over the multi-pass nature of LaTex plus Bibtex. If you look at Step 3 in this discussion, you'll see the following:
The first run (through latex)
generates an auxiliary file,
paper.aux, containing information
about citations (and other types of
references), the bibliography style
used, and the name of the bibtex
database. The second run (through
bibtex) uses the information in the
auxiliary file, along with the data
contained in the bibtex database, to
create a file paper.bbl. This file
contains a thebibliography environment
with \bibitem entries formatted
according to the bibliography style
specified.
So, what I think is happening is that your name_of_my_file.aux file still contains your placeholder \cite{test}. If you remove the auxiliary file, you should be able to start over with:
latex name_of_my_file
bibtex name_of_my_file
latex name_of_my_file
latex name_of_my_file
[Update based on additional info]: The problem was that you had a .aux file with your \cite{} still embedded. The second time that you ran latex, you overrode the old file with the new. That's why the complete set of steps includes an initial latex call, a bibtex call and two follow-up latex calls. Think of it as a multi-pass compiler and it might be more intuitive.
You could have a look at latexmk, which will take care of the fix point compilation for you.
Anyway, you should be able to build the document (pdflatex blah.tex), even if you're missing a bibliography item. The corresponding references will just appear as question marks in the PDF.
Rerun latex to regenerate the aux file.
Have a look at this discussion for pointers to a bit more information. Basically, you may have taken your citation out of the .tex file, but it still exists in one of the derived files (aux, bbl, whatever...)
Check if your bib file has the extension .bib and not .tex.
If it is .tex, just change it to .bib and that should do it.
Once I changed it accidentally to tex, by adding some references, and saving it with the "save as" option, without specifying the bib extension. That's how it can happen all of a sudden.
delete all your .aux and temporal files, re run with latex and then bibtex and then latex twice.

Resources