Unicode character ✔ (U+2714) not set up for use with LaTeX error while building with pdfTeX

pdftexunicodeutf8

For the test case:

\documentclass{article}
\usepackage{ifxetex}
\ifxetex
    \usepackage{polyglossia}
    \setdefaultlanguage{english}
    \defaultfontfeatures{Ligatures={TeX}}
    \setmainfont[BoldFont=cmunbx.otf, ItalicFont=cmunti.otf, BoldItalicFont=cmunbi.otf]{cmunrm.otf}
    \setsansfont{CMU Sans Serif}
    \setmonofont{CMU Typewriter Text}
\else
    \usepackage[T1]{fontenc}
    \usepackage{textcomp}
    \usepackage[utf8]{inputenc}
\fi

\begin{document}
\section{Main}
Euro (€): ^^e2^^82^^ac\par
Heavy Check Mark (U+2714): ^^e2^^9c^^94\par
% ✔
\end{document}

got error:

Unicode character ✔ (U+2714) not set up for use with LaTeX. Heavy Check Mark (U+2714): ^^e2^^9c^^94

while building with PDFLaTeX.

There are lot of similar issues here, but even solution from the closest one (Unicode characters in pdflatex output using hexcode without UTF-8 input) didn't work. How to fix it?

No such error while building with XeLaTeX (though it draws characters incorrectly, so suggestions how to fix it are also appreciated).

Best Answer

Hoping to have a file that compiles with both XeLaTeX and pdflatex is, I'm afraid, generally hopeless.

In any case, XeLaTeX doesn't accept input such as ^^e2^^82^^ac; actually it does, but the result is not what you seem to expect.

You can set up replacements for missing symbols. I also redefine the Euro symbol for pdflatex, because the one you get with European Modern is “funny”.

\documentclass{article}

% general packages
\usepackage{iftex}
\usepackage{newunicodechar}

% specific packages
\iftutex
  % XeLaTeX or LuaLaTeX
  \usepackage{polyglossia}
\else
  % pdflatex
  \usepackage[T1]{fontenc}
  \usepackage{pifont,eurosym}
\fi

% settings

\iftutex
  % XeLaTeX or LuaLaTeX
  \setdefaultlanguage{english}
  %\defaultfontfeatures{Ligatures={TeX}}
  \setmainfont{cmun}[
    Extension=.otf,
    UprightFont=*rm,
    BoldFont=*bx,
    ItalicFont=*ti,
    BoldItalicFont=*bi
  ]
  \setsansfont{CMU Sans Serif}
  \setmonofont{CMU Typewriter Text}
  \newfontface{\extrasymbols}{FreeSerif}[Extension=.otf]
  \newunicodechar{✔}{{\extrasymbols ✔}}
\else
    %\usepackage{textcomp}
    %\usepackage[utf8]{inputenc}
    \newunicodechar{✔}{\ding{52}}
    \newunicodechar{€}{\euro}
\fi

\begin{document}

Euro (U+20AC): €

Heavy Check Mark (U+2714): ✔

\end{document}

Output with XeLaTeX

enter image description here

Output with pdflatex

enter image description here