Automatically add a custom url on my bibliography, based on local url rewriting

I search a solution to automatically add a custom url on my bibliography, based on local url rewritting.

For example, i have a biblatex entry into library.lib with local pdf url like this :

@phdthesis{Stonedahl2011a,
author = {Stonedahl, Forrest J.},
file = {:home/srey/TRAVAUX/THESE/REPOSITORY\_PDF/RANGE/Stonedahl\_2011\_Genetic Algorithms for the Exploration of Parameter Spaces in Agent-Based Models.pdf:pdf},
number = {December},
pages = {394},
school = {Evanston, Illinois},
title = {{Genetic Algorithms for the Exploration of Parameter Spaces in Agent-Based Models}},
year = {2011}
}


The latex file :

\documentclass[a4paper, 12pt,twoside, openright]{memoir}
\usepackage{polyglossia}
\setdefaultlanguage{french}
\usepackage{fontspec}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[autostyle=true,french=guillemets,maxlevel=3]{csquotes}
\usepackage{xparse}
\usepackage{graphicx}
\usepackage[protrusion=true]{microtype}
\sidecapmargin{outer}
\setsidecappos{t}

\usepackage[backend=biber,backref=true, natbib=true, isbn=false, doi=false, url=false, style=authoryear,maxcitenames=1, maxbibnames=999, sorting=nyt, refsection=chapter, hyperref]{biblatex}

\begin{document}

\chapterstyle{bringhurst}

My blabla text with citation. \autocite{Stonedahl2011a}

\printbibliography

\end{document}


How can i add a custom url to my bibliography to download paper from a custom source and how can i translate automatically this url into biblatex file

home/srey/TRAVAUX/THESE/REPOSITORY\_PDF/RANGE/Stonedahl\_2011\_Genetic Algorithms for the Exploration of Parameter Spaces in Agent-Based Models.pdf transform

into

http://mycustomserver.com/Stonedahl_2011_Genetic Algorithms for the Exploration of Parameter Spaces in Agent-Based Models.pdf

• Just one thing I noticed: file is a verbatim field it is therefore counter-productive to escape underscores via \_. – moewe Mar 20 '14 at 0:26
• Ho :/ But the bibtex i use is an automatic file from mendeley ... thanks for notice, i search an answer for that. – reyman64 Mar 20 '14 at 8:10

When biblatex is used with biber as backend, it is possible to use \DeclareSourcemap to perform on the fly manipulation of the fields.

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=file]
\step[fieldset=url, origfieldval]
\step[fieldsource=url,
match=\regexp{:home/srey/TRAVAUX/THESE/REPOSITORY_PDF/RANGE/(.+):pdf},
replace={http://www.example.com/$1}] } } }  The first two steps are meant to copy the value of the field file to the field url, the last step is to replace the path in file with the appropriate url. When \regexp is used, normal regexp grouping and replacements are possible. The biblatex manual describes such operations in details in section 4.5.2. Here is the outcome (changing the url option to show the outcome of the substitution). • Hi thanks, I have some problem with the regex, it doesn't work on my bib, i search why .. Other question, is it possible to replace this ugly url by a text like "@download" ? – reyman64 Mar 20 '14 at 8:54 • @reyman64 Since your are escaping underscores (which should not be done in verbatim fields such as file), you also need a \step[fieldsource=url, match=\regexp{\\_}, replace=\regexp{_}], add that line directly after \step[fieldset=url, origfieldval] before \step[fieldsource=url, match=\regexp{:home/srey/TRAVAUX/THESE/REPOSITORY_PDF/RANGE/(.+):pdf}, replace={http://www.example.com/$1}]. – moewe Mar 20 '14 at 9:11
• For the second part of the question you have to modify how url is typeset bu biblatex. A possibility is \DeclareFieldFormat{url}{\href{#1}{Download}} – Guido Mar 20 '14 at 9:17
• @guido Another problem, it seems if there is also an url into bib file, it take in priority the url and not the pdf :/ How can i remove the url in this case ? – reyman64 Mar 20 '14 at 9:34
• @reyman64 Try \map[overwrite]{ instead of \map{. For @download see It there a way to make URL link in bibliography as one word Link? – moewe Mar 20 '14 at 9:41