我想添加一个带有超链接的文本到通过pyLaTeX生成的文档中。在LaTeX中,这将通过以下方法执行:
\href{http://www.sharelatex.com}{Something Linky}
我已经找到了包含标记对象和Hyperref对象的标签参考文献,但是我似乎无法让它工作。
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文档,而不会出现错误。所产生文件的图像
而我所期望的是“这里”这个词是一个超链接,并以蓝色显示。
发布于 2019-09-30 14:15:07
我就是这样做的。我创建了一个类,它为您提供了所需的超链接功能。在GitHub上也有一个问题,我也是这么做的。https://github.com/JelteF/PyLaTeX/issues/264
from pylatex import Document, Hyperref, Package
from pylatex.utils import escape_latex, NoEscape
def hyperlink(url,text):
text = escape_latex(text)
return NoEscape(r'\href{' + url + '}{' + text + '}')
doc = Document()
doc.packages.append(Package('hyperref'))
doc.append("Example text a link should go ")
# i was hoping the hyperlink would work like i'm showing below
doc.append(hyperlink("https://jeltef.github.io/PyLaTeX", "here"))
doc.generate_pdf("Example_document", clean_tex=True)https://stackoverflow.com/questions/57059457
复制相似问题