URL Wrapping (especially in the Bibliography Section)

Jan 20, 2016 at 7:21 PM
I would first like to say that we absolutely love Madoko and wanted to compliment you on the creation of such a fine tool. Thank you for generously making it available as open-source software. We are enjoying using it.

One issue that we have had with using Madoko out of the box to create PDFs is with the wrapping of URL links, especially for papers in a two-column format. Is there any way to address that within Madoko or is this a TeX/LaTeX limitation?

Kind regards.
Jan 21, 2016 at 12:03 PM
This can indeed be an issue. As it seems <http://long-url.com> in madoko becomes \href{http://long-url.com}{http://long-url.com} in the compiled tex document. This is correct of course, but latex simply has no way to handle long urls by default.

My suggestion would be to use \url{http://long-url.com} in latex for <http://long-url.com> in madoko and load the hyperref package in latex (which itself loads the url package) which would result in some automatic line-breaking. This could be further refined by adding \PassOptionsToPackage{hyphens}{url} in the Tex Header if needed or additionally load the breakurl package which can enforce a line break at any point in a url.

I guess this is sth. daan has to look into and decide how to handle. :)
Jan 21, 2016 at 2:40 PM
Thank you for the ideas; they were very helpful.

I am able to handle literal URLs within paragraphs in the document now using:
Lorum ipsum [http://someveryvery.incrediblylongandannoying.com/urlforsomeresource/ontheweb.html]{ tex-cmd:"\url" } dolar.
However, I haven't been able to get URLs in the automatically generated bibliography to wrap. However, using your advice, if I just go into the raw generated tex file, I can change the \href to a \url and that seems to allow it to wrap.

Thank you for the help.
Jan 21, 2016 at 4:39 PM
Hi all,

Apologies for not replying earlier -- been having a cold :-(

The tex-cmd:"\url" will be a good work around for now; for the url's in the bibliography, you can use a replacement rule to do the same trick:
bibitem {
  replace: "/\[(https?:\/\/[^\]]+)\]\(\1\)/[\1](\1){.bibitemurl}/g";
.bibitemurl {
A bit involved but it is just a workaround for now :-) I agree with beingalink that this should be fixed in a nicer way -- for one, we could indeed just generate a \url command whenever the link matches the display text and pass the hyphens option too. Another option is to handle this on the Madoko side and inserting &shy; characters after any character that we consider a good break, like \ or -. Perhaps it is best to leave it to the LaTeX url package though??
Jan 21, 2016 at 5:38 PM
Oh, cold sux. Hope you're well now.

URL handling isn't straight forward imho. To test what I said in my previous post, I used a link generated by a url prolonger (yes, that exists). The generated link was constructed in a way that there was none of the "good-break-characters" in it so the normal method I described failed and the result was quite unpleasant. In that case a force-break would have been necessary as it only the breakurl package could have done as far as I know.

In my opinion a madoko solution would be preferable if we agree that a line break must be enforced if the alternative would be a line overflow. I would certainly prefer such a behavior but I'm not sure if that is consensus. Thanks for looking into it!
Jan 21, 2016 at 6:10 PM
Slowly getting better :-)

Thanks for trying out the super long url -- I guess that this url consists of just many long alphabetic characters that even the url package will not break.
I guess Madoko could insert various break points for the Latex output with \- at obvious break points but also breaks with a higher penalty after each regular character. That way, Latex would prefer to break at an obvious break point but would still break up long words inside a url if necessary. I'll give it a try -- first need to read up on break penalties again in the tex by topic book :-)
Jan 21, 2016 at 6:15 PM
Thank you, that's a great workaround.
Jan 21, 2016 at 6:46 PM
Just wanted to let you know that the bibitem replacement rule worked great for everything except for one URL which had a tilde (~) in it. I replaced the tilde with "%7e" in my bibtex file and then everything went fine.

Thanks again to both for your quick and helpful assistance!
Jan 21, 2016 at 7:17 PM
Good to hear!
Right, the solution above is just a workaround -- in general it does not work reliably because Madoko will do more translation on the 'url' text to display correctly while the url it self is untouched -- you will see this with funny characters like ~ or * for example. Anyway, once I get to implementing the proper line breaking solution you will not need the workaround anymore :-)