【发布时间】:2019-07-16 14:20:11
【问题描述】:
我想在通过 pyLaTeX 生成的文档中添加带有超链接的文本。在 LaTeX 中,这将通过以下方式执行:
\href{http://www.sharelatex.com}{Something Linky}
我找到了包含 Marker 对象和 Hyperref 对象的 labelref documentation,但我似乎无法让它工作。
from pylatex import Document, Hyperref
doc = Document()
doc.append("Example text a link should go ")
# i was hoping the hyperlink would work like i'm showing below
doc.append(Hyperref("https://jeltef.github.io/PyLaTeX", "here"))
doc.generate_pdf("Example_document", clean_tex=True)
运行以下代码会生成一个没有错误的 pdf 文档。 image of the document produced
虽然我希望“这里”这个词是一个超链接,并以蓝色显示。
【问题讨论】:
-
你实际得到的输出是什么?或错误消息(如果有)?
-
我没有收到任何错误,但是生成了文档,因为我错误地使用了 Hyperref 对象,所以没有创建超链接。
-
运行您的代码,它将
\hyperref[https://jeltef.github.io/PyLaTeX]{here}输出到Example_document.tex。该行试图引用 label,而不是 URL。它还在documentation you linked 中提到该类旨在引用标签/引用参数。看起来这个包不能像你想要的那样自动引用 URL。 -
啊,真令人失望。感谢您的观看!