Skip to content
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

Figure captions with citations fail in building PDF #307

Closed
astonzhang opened this issue Aug 1, 2022 · 1 comment
Closed

Figure captions with citations fail in building PDF #307

astonzhang opened this issue Aug 1, 2022 · 1 comment

Comments

@astonzhang
Copy link

Describe the bug

Figure captions with citations fail in building PDF. Here is an example (note that :citet: is an alias of :cite:t:):

Input ipynb:
Screen Shot 2022-08-01 at 11 59 48 AM

Output tex:
bad

When compiling PDF from this tex, the following error shows up:

Screen Shot 2022-08-01 at 11 56 21 AM

How to Reproduce

$ git clone -b sphinx-latex https://github.com/d2l-ai/d2l-en.git
$ cd d2l-en
$ vi static/post_latex/main.py # Comment out my hack https://github.com/d2l-ai/d2l-en/blob/sphinx-latex/static/post_latex/main.py#L141
$ pip install d2lbook
$ d2lbook build pdf  # The output pdf should be at _build/pdf

Expected behavior

As a hack for this issue, I post-process this tex file. So the processed tex has a \protect and becomes:
good

Then the output PDF is:
Screen Shot 2022-08-01 at 11 56 32 AM

Your project

https://github.com/d2l-ai/d2l-en/ and https://github.com/d2l-ai/d2l-book

Screenshots

No response

OS

Linux

Python version

3.8

Sphinx version

5.1.1

@mcmtroffaes
Copy link
Owner

Thanks for the detailed report, and apologies for the late reply - I've been on vacation. Using \protect is indeed the correct solution, and it would be possible to patch sphinxcontrib-bibtex so it always outputs \protect\hyperlink{...}. However I'm wary of any implications of using \protect everywhere for these hyperlinks - I don't understand enough about the robust/fragile system to know whether or not it will break something.

I'll close this as a duplicate of #276 - there you can find one idea for a solution (using the etoolbox package), but so far it doesn't work. Feel free to chime in there if you have further ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants