[Tex/LaTex] ucs and biblatex incompatibility (mathletters and utf-8)

biblatexincompatibilityunicode

I have a document that I was writing with UTF-8 chars using TexStudio, MikTex (x64) and pdflatex. All updated and running on Window 7 SP1 x64.

Then I decided to start using biblatex citations and now I have an incompatibility problem.

The error is

Package biblatex Error: Incompatible package 'ucs'. \begin{document}

And here is the code

\documentclass[]{article}
\usepackage[mathletters]{ucs} % this package seems to conflict
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc} % the x seems to be a problem
\usepackage[backend=bibtex]{biblatex}
\addbibresource{Library.bib}

\title{MyTitle}
\author{Me}

\begin{document}

    \maketitle

    \section{MySection}

    \paragraph{MyParagraph}
    Accènt
    λ lamba
    \cite{some_cit}

    \printbibliography

\end{document}

This is a small example. In my full document I have lots of Greek letters, and some of them are in titles. Putting them all into math formulas would be a problem.
What should I do? to make the 2 live together? Should I use another package for citations?

Best Answer

You can abuse the infrastructure of ucs; here's a set of tricks that read the files you need in the ucs distribution, but under utf8 which is compatible with biblatex.

\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\input{binhex}
\makeatletter
\def\uc@dclc#1#2#3{%
  \ifnum\pdfstrcmp{#2}{mathletters}=\z@
    \begingroup\edef\x{\endgroup
      \noexpand\DeclareUnicodeCharacter{\hex{#1}}}\x{#3}%
  \fi
}
\input{uni-3.def}
\def\uc@dclc#1#2#3{%
  \ifnum\pdfstrcmp{#2}{default}=\z@
    \begingroup\edef\x{\endgroup
      \noexpand\DeclareUnicodeCharacter{\hex{#1}}}\x{#3}%
  \fi
}
\input{uni-34.def}
\makeatother


\begin{document}
\title{MyTitle}
\author{Me}

\maketitle

\section{MySection about ∞}

Accènt λ lambda ∞ 

$λ$ lambda $∞$ 


\end{document}

enter image description here

A different strategy is using unicode-math-table.tex:

\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\makeatletter
\newcommand\UnicodeMathSymbol[4]{%
  \ifnum#1>"9F
    \expandafter\DeclareUnicodeCharacter\expandafter{\@gobble#1}{\ensuremath{#2}}%
  \fi
}
\input{unicode-math-table}
\@for\next:={% you're probably using text Greek letters
  alpha,beta,gamma,delta,epsilon,zeta,eta,theta,%
  iota,kappa,lambda,mu,nu,xi,pi,rho,sigma,tau,%
  upsilon,phi,chi,psi,omega,Gamma,Delta,Theta,%
  Lambda,Xi,Pi,Sigma,Upsilon,Phi,Psi,Omega}\do{%
    \expandafter\let\csname up\next\expandafter\endcsname\csname\next\endcsname
}

\makeatother

\begin{document}
\title{MyTitle}
\author{Me}

\maketitle

\section{MySection about ∞}

Accènt
λ lambda ∞ 

$λ$ lambda $∞$ 


\end{document}

The entries in unicode-math-table are of the form

\UnicodeMathSymbol{"0221E}{\infty}{\mathord}{infinity}

so we remap this to

\DeclareUnicodeCharacter{0221E}{\ensuremath{\infty}}

(I used \ensuremath because you want it, but I'd personally avoid it). For the Greek letters, \upalpha and so on are used, so I remap also those commands to the usual ones.