4

Basically, I have a bibtex field like this, where bibtex concatenation with # is used with a bibtex string variable:

@String {mylink = "http://tex.stackexchange.com"}
...
note = "At link " # mylink,

Now, I'd like to wrap that in a \url, so I tried:

note = "At link \url{" # mylink # "}",

... and when processing with biblatex+biber, it seems that the presence of braces makes the parameter mylink to not be replaced.

Reading through texdoc url, I learned that \url there actually has another call form \url|...| where instead of braces, I could use pipes as "argument delimiters" - and indeed this is expanded properly by biblatex+biber:

note = "At link \url|" # mylink # "|",

... but unfortunately, hyperref's \url command does not support this syntax with the pipes - and url's \url typesets only plain text (not clickable links in PDF).

So, is there any way to have \url|...| be "understood" as url's \url (that is the pipes represent argument delimiters) - but executed as hyperref's \url? (with clickable links and all)?

Here is a MWE that shows just the \url aspect (without the bibliography):

\documentclass{article}
\usepackage[showframe]{geometry}
% \PassOptionsToPackage{hyphens}{url}
\usepackage[hyphens]{url}
\let\origurl\url % same as \HyOrg@url (from hyperref)
\usepackage[breaklinks]{hyperref}
\hyphenation{some-folder-with-a-very-long-name}% doesn't work
% \hyphenation{http://testing.org/firstlevelsubdirectory/some-folder-with-a-very-long-name/2008010817502377777777/}% '! Not a letter.' for the ':'

% cannot use \hyphenation to break urls; so make it break link at each letter!
% https://tex.stackexchange.com/questions/3033/forcing-linebreaks-in-url
\let\origUrlBreaks\UrlBreaks
\makeatletter
\g@addto@macro{\UrlBreaks}{\UrlOrds}
\let\oldUrlBreaks\UrlBreaks
\g@addto@macro{\UrlBreaks}{%
  \do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j%
  \do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t%
  \do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D%
  \do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N%
  \do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X%
  \do\Y\do\Z}
\makeatother
\let\newUrlBreaks\UrlBreaks

% copy of "\Url@y read arguments delimited like |...|, passing to \Url@z" from hyperref.sty; nowork - makes \end{document} be skipped!
\makeatletter
\def\turl#1{\catcode`{11 \catcode`}11\obeyspaces\obeylines
  \def\@tempa##1#1{\url{##1}}\@tempa}
\makeatother

\begin{document}

\section{Section 1}
Testing this URL here: \url{http://testing.org/firstlevelsubdirectory/somefolderwithaverylongname/2008010817502377777777/}

Testing this URL here: \origurl|http://testing.org/firstlevelsubdirectory/somefolderwithaverylongname/2008010817502377777777/|

Testing this URL here: \url|http://testing.org/firstlevelsubdirectory/somefolderwithaverylongname/2008010817502377777777/|

% Testing this URL here: \turl|http://testing.org/firstlevelsubdirectory/somefolderwithaverylongname/2008010817502377777777/| % nowork - makes \end{document} be skipped!

\end{document}

Output:

test.png

I'd like to simply write \url|...|, and have the link output/typeset as on the first line in this MWE (while for now, I have to write \origurl|...|, and it outputs as on the second line - without a link area).

sdaau
  • 17,079

0 Answers0