问题
There is some inconsistent behaviour of text references in bookdown with URLs containing special characters such as :
or _
. Here are some demonstrations:
---
output: bookdown::pdf_book
---
(ref:good) [This Works](https://commons.wikimedia.org/wiki)
(ref:good)
(ref:bad) [This Does Not](https://commons.wikimedia.org/wiki/File:Linear_visible_spectrum.svg)
(ref:bad)
The link will work normally [like here](https://commons.wikimedia.org/wiki/File:Linear_visible_spectrum.svg)
Is there a way to get text references to work if they contain special characters?
This behaviour was flagged in this question here, but the symbols were not directly identified as the key issues within the question. I wanted to make a focussed thread on SO before raising it as a potential issue on GitHub.
回答1:
The problem was not caused by special characters but the fact that the link was too long, so the line in LaTeX was wrapped by Pandoc by default:
(ref:bad)
\href{https://commons.wikimedia.org/wiki/File:Linear_visible_spectrum.svg}{This Does Not}
It should be considered as a bug of bookdown, but there is a workaround:
output:
bookdown::pdf_book:
pandoc_args: [--wrap=none]
来源:https://stackoverflow.com/questions/50098235/bookdown-text-references-not-working-if-url-contains-special-characters