Bookdown text references not working if URL contains special characters

[亡魂溺海] 提交于 2019-12-08 07:52:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!