jupyter-book icon indicating copy to clipboard operation
jupyter-book copied to clipboard

Not able to generate the whole book using latexpdf

Open marianaiv opened this issue 2 years ago • 14 comments

Describe the bug

context I'm trying to build a pdf using latex by running

jupyter-book build mybookname/ --builder pdflatex

expectation I expected a pdf of the whole book

bug But I'm getting only the first two sections of the first chapter. Here is what I get when building, it appears to have problems with cross-references? I'm not sure.

Latexmk: Summary of warnings from last run of *latex:
  Latex failed to resolve 6 reference(s)
Latexmk: ====List of undefined refs and citations:
  Reference `capitulos/marco-teorico/reconstruccion-jets:jets' on page 3 undefined on input line 210
  Reference `capitulos/marco-teorico/mas-alla-del-ms:bsm' on page 3 undefined on input line 210
  Reference `capitulos/marco-teorico/aprendizaje-automatico:ml' on page 3 undefined on input line 210
  Reference `capitulos/marco-teorico/reproducibilidad:rpd' on page 3 undefined on input line 210
  Reference `capitulos/marco-teorico/reconstruccion-jets:jets-desarrollo' on page 9 undefined on input line 364
  Reference `capitulos/marco-teorico/reconstruccion-jets:jets-qcd' on page 9 undefined on input line 367
Latexmk: Errors, so I did not complete making targets
Collected error summary (may duplicate other messages):
  pdflatex: Command for 'pdflatex' gave return code 1
      Refer to 'python.log' for details
Latexmk: If appropriate, the -f option can be used to get latexmk
  to try to force complete processing.
Reverting Windows console CPs to (in,out) = (850,850)
C:\texlive\2022\bin\win32\runscript.tlu:915: command failed with exit code 12:
perl.exe c:\texlive\2022\texmf-dist\scripts\latexmk\latexmk.pl -pdf -dvi- -ps-  python.tex

I uploaded all I get in the console here problem This is a problem for people trying to get a latex pdf from their books.

Reproduce the bug

  1. Clone https://github.com/marianaiv/tesis_grado_UCV/tree/marco-teorico to your computer
  2. Go to the file. From the command line would be
cd path_where_cloned/tesis_grado_UCV
  1. Build the pdf using
jupyter-book build tesis --builder latexpdf

List your environment

>jupyter-book --version
Jupyter Book      : 0.12.2
External ToC      : 0.2.4
MyST-Parser       : 0.15.2
MyST-NB           : 0.13.2
Sphinx Book Theme : 0.1.10
Jupyter-Cache     : 0.4.3
NbClient          : 0.5.4
  • Python 3.7.4
  • Windows 10
  • TeX 3.141592653 (TeX Live 2022), kpathsea version 6.3.4

marianaiv avatar Apr 20 '22 23:04 marianaiv

cc @mmcky and @AakashGfude who are the latex wizards here :-)

choldgraf avatar Apr 21 '22 12:04 choldgraf

I see Runaway argument? in your log output that you skipped interactively?

Every time I got Runaway argument? in the past few days, it was always the first symptom of something broken.

Look for any missing closing braces, for example by selectively commenting out sections until you found the source..

michaelosthege avatar Apr 21 '22 13:04 michaelosthege

I see Runaway argument? in your log output that you skipped interactively?

Every time I got Runaway argument? in the past few days, it was always the first symptom of something broken.

Look for any missing closing braces, for example by selectively commenting out sections until you found the source..

Could it be the .bib file? Or it is something in the book?

marianaiv avatar Apr 21 '22 14:04 marianaiv

Ok, so I tried debugging it by section since I get ! Argument of \Hy@tempa has an extra } and Runaway argument? a bunch of times. The first thing of the chapter and the first section build nicely. However, the second section is where I start getting those errors and they go away if I delete the images (on that section at least). I don't understand why because I have an image in the first section and don't seem to have problems with it. Also, the second section is the last section I get on the pdf, so I'm not sure those errors are preventing the building.

marianaiv avatar Apr 21 '22 19:04 marianaiv

I found the problem! So I'm making citations on the figures. If I delete them, the build works fine. Should I make another issue or just change the title? Is there a workaround for this?

marianaiv avatar Apr 25 '22 04:04 marianaiv

@marianaiv nice detective work. Can you post a snippet of the citations and figures syntax?

mmcky avatar Apr 25 '22 04:04 mmcky

@mmcky For all the images I have something like this

```{figure} path/to/image.png
---
width: 150px
name: label-figure
---
Some text. Figure from {cite}`randomkey`.
```

marianaiv avatar Apr 25 '22 13:04 marianaiv

@marianaiv I tried to add a citation to one of my figure captions and ran into the same problem. An error asking for interactive input during the build.

! Argument of \Hy@tempa has an extra }.
<inserted text>
                \par
l.665 ...:id25}{20}{]} in the figure description.}

The resulting PDF has the citation in the caption. , but a broken figure layout the page after.

michaelosthege avatar Apr 25 '22 15:04 michaelosthege

@michaelosthege Since you were able to build it I checked again. I think is breaking when I cite and also add {numref}`label` to the same caption. Very specific and I think I can just delete those references. Thank you for the help!

As far as I'm concerned this issue can be closed. Maybe a warning should be added to the book about this?

marianaiv avatar Apr 25 '22 16:04 marianaiv

thanks @marianaiv this is really helpful. I will keep this open and add some test cases around citations in figure captions and try and get this supported in the medium term.

mmcky avatar Apr 26 '22 00:04 mmcky

@marianaiv @mmcky just swaw by accident that the issue described here is a known issue with sphinxcontrib-bibtex: https://sphinxcontrib-bibtex.readthedocs.io/en/latest/usage.html#latex-backend-fails-with-citations-in-figure-captions

Discussion in https://github.com/mcmtroffaes/sphinxcontrib-bibtex/issues/276

michaelosthege avatar May 08 '22 17:05 michaelosthege

Thanks for linking the issues @michaelosthege

mmcky avatar May 09 '22 03:05 mmcky

Just ran into this one too, specifically for the captions in the {glue:figure} case.

The fix at https://github.com/mcmtroffaes/sphinxcontrib-bibtex/issues/276#issuecomment-1102154800 worked for me (thanks @michaelosthege for pointing in that direction!), i.e. adding the following to the preamble (via my _config.yml):

sphinx:
  config:
      preamble: |+
		% Fix citations in figure captions, from https://github.com/mcmtroffaes/sphinxcontrib-bibtex/issues/276#issuecomment-1102154800
        \usepackage{etoolbox}
        \AtBeginEnvironment{figure}{\pretocmd{\hyperlink}{\protect}{}{}}  

Citations in captions then seem to work without triggering latex build issues.

(I also tested the fix at https://sphinxcontrib-bibtex.readthedocs.io/en/latest/usage.html#latex-backend-fails-with-citations-in-figure-captions, but that didn't work for me (maybe a Sphinx version thing).)

> jupyter-book --version
Jupyter Book      : 0.13.1
External ToC      : 0.2.4
MyST-Parser       : 0.15.2
MyST-NB           : 0.13.2
Sphinx Book Theme : 0.3.3
Jupyter-Cache     : 0.4.3
NbClient          : 0.5.4

Sphinx 4.5.0 Python 3.9.7

phockett avatar Nov 29 '22 21:11 phockett

probably can be closed as a duplicate of #1621 & #1584

casperdcl avatar Oct 07 '23 21:10 casperdcl