[Tex/LaTex] Vector fonts with UTF-8 support

font-encodingsfonts

In fact the situation I find myself in is a bit more complicated than the question might suggest. I need to typeset a document with various accented characters and would like some hyphenation support for that. I know I need T1 font encoding for that. Unfortunately, then I have to use a bitmap font by default, which is quite ugly… Can I force Computer Modern with T1 or is there no way around? In the latter case, which vector fonts would you suggest? I am only marginally interested in XeTeX or LuaTeX solutions.

Best Answer

I strongly suggest Latin Modern fonts instead of CM. See the post: Latin Modern vs cm-super?

If you also want to have UTF8 encoding mapping in the pdf file (for copy-pasting and accessibility) you can add some line to your preamble assuming you are using pdfTeX (pdfLaTeX).

The minimal code below I have prepared for another post show you how to do this:

\documentclass[]{article}

%PdfTeX settings for a correct UTF 8 Mapping
%------------------------------------------------------
\usepackage{ifpdf}
\ifpdf    \input{glyphtounicode.tex}    %Part of modern distribution
      %%%\input{glyphtounicode-cmr.tex}     %Additionnal glyph: You must grab it from pdfx package
      \pdfgentounicode=1
\else  %Place here the settings for other compilator
\fi


%Encoding + cmap (to get proper UTF8 mapping)
%------------------------------------------------------
\usepackage{cmap}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}


%NB: CHANGE lmodern AND fourier TO SEE THE PROBLEM OF MISSING UNICODE CHARACTERS
%     You can see this on Acrobat Pro with acessibility checking or simply by copy-pasting the content.
%     Of course copy paste is not perfect in both case but it is better with lmodern
%------------------------------------------------------
\usepackage{lmodern}
%%\usepackage{fourier}


%AMS Math + UTF8 mapping of ams symbols
%------------------------------------------------------
\usepackage{amsmath} 
\usepackage{amssymb} % I load it after Fourier else I have more incorrect utf8 mapping (with \geqslant for example)
%Correct UTF8 mapping for ams fonts
\ifdefined\pdffontattr% \ifdefined is part of the e-TeX extension, which is part of any modern LaTeX compiler. 
    \immediate\pdfobj stream file {umsa.cmap}
    {\usefont{U}{msa}{m}{n}\pdffontattr\font{/ToUnicode \the\pdflastobj\space 0 R}}
    \immediate\pdfobj stream file {umsb.cmap}
    {\usefont{U}{msb}{m}{n}\pdffontattr\font{/ToUnicode \the\pdflastobj\space 0 R}}
\fi


%Start document
%------------------------------------------------------
\begin{document}

All these examples work fine with Latin Modern but not with Fourier Font (and Palatino and maybe others).

\bigskip
Issue with mapsto : ${\mathcal F} : \boldsymbol{\eta} \in {\mathbb{R}}^{np}\ \mapsto {\mathcal F}\left(\boldsymbol{\eta} \right)\in \mathbb{R}$

\bigskip
Issue with sqrt : $\sqrt{X}$

\bigskip
Issue with parenthesis : $X \geqslant \left(\frac{1}{2}\right)^2$

\bigskip
Issue with sum : $\sum_{n=0}^\infty X^n$

\end{document}
Related Question