Skip to content

URLs in a['href'] should be escaped for LaTeX - #67

Closed
hperl wants to merge 1 commit into
gettalong:masterfrom
hperl:patch-1
Closed

hperl wants to merge 1 commit into
gettalong:masterfrom
hperl:patch-1

Conversation

@hperl

@hperl hperl commented Jul 16, 2013

Copy link
Copy Markdown
Contributor

An URL such as in a a['href'] can contain URL escape codes, which all start with a %. The LaTeX-converter should escape all % to \% using escape(), or otherwise the unescaped % will be treated like a comment in LaTeX, corrupting the file.

This pull request fixes this by calling escape() on the URL.

@ghost ghost assigned gettalong Jul 29, 2013
@gettalong

Copy link
Copy Markdown
Owner

Thanks!

@gettalong gettalong closed this Aug 21, 2013
@mkamensky

Copy link
Copy Markdown

I think this is actually wrong, escaping breaks for instance urls with a tilde in them. The hyperref manual says that " The special characters # and ̃ do not need to be escaped in any way.". Unfortunately, it does not say anything about other characters...

@gettalong

Copy link
Copy Markdown
Owner

@mkamensky Thanks for your comment - do you have any test cases for this?

@mkamensky

Copy link
Copy Markdown

Yes, this comes from my real life example:

echo '<https://www.math.bgu.ac.il/~amyekut/teaching/2016-17/der-cats-III/course_page.html>' | ruby -rkramdown -e 'puts Kramdown::Document.new(ARGF.read).to_latex'

It produces

\href{https://www.math.bgu.ac.il/\ensuremath{\sim}amyekut/teaching/2016-17/der-cats-III/course\_page.html}{https://www.math.bgu.ac.il/\ensuremath{\sim}amyekut/teaching/2016-17/der-cats-III/course\_page.html}

which does not compile. Thanks!

@gettalong

Copy link
Copy Markdown
Owner

@mkamensky Sorry for the long delay...

I have tested this now with #, % and ~: Seems to work fine without escaping. As you mentioned, the hyperref package doesn't say much about escaping but I found this answer on StackExchange.

Therefore I have changed the code to just escape the percent sign and nothing else. Seems to do what it should so far.

Will be in the next release!

gettalong added a commit that referenced this pull request Sep 8, 2017
Pull request #67 changed the code to use the escape() method. However,
this does more than it should, breaking the URLs.

By just escaping the percent sign this code should work in all
cases and environments now (fingers crossed).
@mkamensky

Copy link
Copy Markdown

@gettalong Thanks!

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

Successfully merging this pull request may close these issues.

3 participants