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

Hyperlink to a URL #264

Open
BaronBonet opened this issue Jul 17, 2019 · 1 comment
Open

Hyperlink to a URL #264

BaronBonet opened this issue Jul 17, 2019 · 1 comment

Comments

@BaronBonet
Copy link

I would like to add a text with a hyperlink to my document being generated via pyLaTeX. In LaTeX this would be performed by using:

\href{http://www.sharelatex.com}{Something Linky}

I have found the labelref documentation containing the Marker object as well as the Hyperref Object but i cannot seem to get it working.

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)

Running the following code produces the a pdf document without errors. image of the document produced

While what i would expect is that the word "here" is a hyperlink and shown in blue.

Is this possible?

@jeffheaton
Copy link

jeffheaton commented Sep 30, 2019

I do not believe that is supported, see here: https://stackoverflow.com/questions/57059457/python-pylatex-hyperlink-to-a-url

I added a complete example at the above StackOverflow.

This is the method that I used to support it. First, define a hyperlink class:

def hyperlink(url,text):
    text = escape_latex(text)
    return NoEscape(r'\href{' + url + '}{' + text + '}')

Then I just do this:

document.append(hyperlink("http://www.jeffheaton.com", "My Site"))

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