Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Mendeley allows you to emphasise Latin names in article or report titles using HTML notation like so:

A treatise on the ecology of <I>Rattus rattus</I>

Using biblatex, the tags are passed on "verbatim" and of course LaTeX doesn't understand them. I would like to replace all <I> with \emph{ and all </I> with }.

I have tried using \DeclareSourceMap as follows:

\DeclareSourcemap{ 
    \maps[datatype=bibtex]{
      \map{
           \step[fieldsource=title, match={<I>}, replace={\emph{}]
            \step[fieldsource=title,match={</I>},replace={}}]
          }
    }      
}

But of course LaTeX chokes as the extra { and } confuse it.

How should I escape the braces for this to work?

share|improve this question

1 Answer 1

up vote 7 down vote accepted

I found that the problem was more with getting Biber to accept what look like XML tags than it was with dealing with the \emph, which can be done by wrapping them in a \regexp, with escapes. In the end I resorted to specifying the < and > by character number.

Anyway, this seems to work.

\DeclareSourcemap{ 
    \maps[datatype=bibtex]{
      \map{
           \step[fieldsource=title,
                 match=\regexp{\x3cI\x3e},
                 replace=\regexp{\\emph\{}]
           \step[fieldsource=title,
                 match=\regexp{\x3c/I\x3e},
                 replace=\regexp{\}}]
          }
    }      
}

Of course, as any fule kno, parsing HTML with regular expressions is not guaranteed to be robust.

Full MWE

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{ratty,
  author = {Mouse, Michael},
  title  = {A Treatise on <I>rattus rattus</I>},
  publisher = {Rodent Publishers},
  date = {2012},
}
\end{filecontents}
\usepackage[style=authoryear,backend=biber]{biblatex}
\DeclareSourcemap{ 
    \maps[datatype=bibtex]{
      \map{
           \step[fieldsource=title, match=\regexp{\x3cI\x3e}, replace=\regexp{\\emph\{}]
           \step[fieldsource=title, match=\regexp{\x3c/I\x3e}, replace=\regexp{\}}]
          }
    }      
}
\addbibresource{\jobname.bib}
\begin{document}

\nocite{*}

\printbibliography

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.