4

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).

4
  • 3
    the ^^e2^^82^^ac form will never work in xetex so you can remove the xetex testing in the preamble as that branch can not work. (or keep the xetex branch and delete these ^^ forms) Dec 17, 2021 at 22:05
  • @DavidCarlisle I'm still under impression of egreg's answer below, and among other things it make me doubt, whether need XeLaTeX at all. used PDFLaTeX for intermediate pdf builds and XeLaTeX for final. but it looks like recent LaTeX progress towards Unicode support and other things gradually erases the boundaries between them. is there any comparison available of PDFLaTeX Vs. XeLaTeX features, after LaTeX3 be released? Dec 17, 2021 at 23:08
  • 1
    there will not be a latex3, and pdflatex will never have support for unicode fonts pdflatex has some support for unicode input, mapping the utf-8 sequences to suitable tex macros but it is still fundamentally an 8 bit system. Dec 18, 2021 at 0:35
  • under LaTeX3 I meant (latex-project.org/latex3), whatever it is. but thank you for clarification. Dec 18, 2021 at 6:06

1 Answer 1

4

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

2
  • thank you for solution. additionally it revealed mess in the testcase, need to be fixed in the original file. was inputenc disabled because it has conflicts with pifont / other packages / settings, or just that it is unused in this particular case? the same question about Ligatures={TeX}. Dec 18, 2021 at 8:17
  • 1
    @AlexShevchenko With an up-to-date LaTeX, doing\usepackage{textcomp}, \usepackage[utf8]{inputenc} and setting Ligatures=TeX is no longer needed (albeit harmless).
    – egreg
    Dec 18, 2021 at 9:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .