2

Packages I am loading:

\usepackage{unicode-math}
\usepackage{ucharclasses}
\usepackage{textcomp}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{tikz}
\usepackage{xpatch}
\usepackage{imakeidx}
\usepackage{xltxtra}
\setmainfont{TeX Gyre Schola}
\setmathfont{TeX Gyre Schola Math}
\setmathfont{TeX Gyre Termes Math}
\setmathfont{Latin Modern Math}
\setmathfont{TeX Gyre Bonum Math}
\setmathfont{TeX Gyre Pagella Math}

\usepackage{geometry} \geometry{% twoside ,bindingoffset=1cm ,top=1.5cm ,bottom=0.5cm ,left=0.9cm ,right=0.6cm ,asymmetric }

%% Leave me LAST! \usepackage{hyperref} \hypersetup{ colorlinks, citecolor=black, filecolor=black, linkcolor=blue, urlcolor=black }

My setting: I download some data from the web which contains html-formatted chunks (e.g. give me £12 and 1 ≤ x! etc.), then I pass this through pandoc to convert the same chunk in latex. I place those latex chunks inside my latex template and run xelatex on it. Just to be clear: the template is mine, pandoc only converts some chunks of html to latex, it does not produce the whole latex document.

The html's £ are converted by pandoc to unicode chars which xelatex can deal with (I would prefered to have them all as tex-math symbols as i am really annoyed with littering my source documents with unicode except "foreign" languages).

The problem with above setting is that unicode chars like ≤ (U+2264), and | (U+2502) are not found by xelatex. I have managed to load different fonts (as per Missing character: There is no ℕ in font cmss10! , my packages are shown at the beginning of this post) and now xelatex recognises most of these unicode chars except | (U+2502). I get:

Missing character: There is no │ (U+2502) in font TeX Gyre Schola/OT:script=lat
n;language=dflt;mapping=tex-text;!

Update: The above problem has been solved thanks to the comments I got. But I have now same problem with different character. Here is the script:

\documentclass[12pt,a4paper]{book}
%\usepackage{fontspec}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Schola}
\setmathfont{TeX Gyre Schola Math}

\usepackage{newunicodechar} %\newunicodechar{^^^^1D45A}{a} % this does not recognise hex

\begin{document} this -1 should read $m-1$ \end{document}

m is not rendered with this error in log:

Missing character: There is no  (U+1D45A) in font TeX Gyre Schola/OT:script=la

But that font is there.

Update: this has now been solved (thanks @David Carlisle):

Is there a font which supports this char?

Update: this has now been solved, Yes use albatross!!!! (which is great, thanks @Ulrike Fischer):

Is there a place where I can enter the unicode char and find a tex font which supports it?

bliako
  • 187
  • 1
  • 10
  • 3
    you can use on the command line albatross: albatross U+2502 will output a list of fonts on your system. see e.g. https://tex.stackexchange.com/a/627471/2388. Side remark: xltxtra is mostly obsolete and textcomp is in the kernel now. – Ulrike Fischer Sep 29 '22 at 10:32
  • 1
    2502 is a box drawing character, are you sure you want that, and not | (U+007C) or ∣ (U+2223) – David Carlisle Sep 29 '22 at 10:36
  • 1
    don't use \usepackage{textcomp} with xelatex (or even with pdflatex with current releases) avoid \usepackage{xltxtra} as well, just use \usepackage{fontspec} – David Carlisle Sep 29 '22 at 10:37
  • 1
    \setmathfont{TeX Gyre Schola Math} \setmathfont{TeX Gyre Termes Math} \setmathfont{Latin Modern Math} \setmathfont{TeX Gyre Bonum Math} \setmathfont{TeX Gyre Pagella Math} all these are resetting everything, only the last one is having any effect – David Carlisle Sep 29 '22 at 10:39
  • 1
    as your text font is TeX Gyre Schola you should probably have \setmathfont{TeX Gyre Schola Math} not \setmathfont{TeX Gyre Pagella Math} – David Carlisle Sep 29 '22 at 10:42
  • this does not recognise hex you have invalid syntax, ^^^^ requires lowercase hex, you could also use \newunicodechar{}{m} – David Carlisle Sep 29 '22 at 16:06
  • I have deleted my previous comment that \newunicodechar{}{m} did not work, I stupidly missed \usepackage{newunicodechar}. So it DOES work. But this doesnt (so as not pollute my document with all these unicodes): \newunicodechar{^^^^1d454}{a} – bliako Sep 29 '22 at 16:46
  • 1
    @bliako If the code is five hex digit long, you need five ^. – egreg Sep 29 '22 at 21:07
  • @egreg +!!!! At some stage I was giving it three ^. – bliako Sep 30 '22 at 07:19

1 Answers1

4

The TeX Gyre Math fonts you are using do have U+2502

enter image description here

\documentclass{article}
\usepackage{unicode-math}
% only if you need it \usepackage{ucharclasses}
% not with xetex \usepackage{textcomp}
% avoid, better to just use fontspc, already included by unicode-math \usepackage{xltxtra}
\setmainfont{TeX Gyre Schola}
\setmathfont{TeX Gyre Schola Math}
% this over-writes the prevous setting \setmathfont{TeX Gyre Termes Math}
% this over-writes the prevous setting \setmathfont{Latin Modern Math}
% this over-writes the prevous setting \setmathfont{TeX Gyre Bonum Math}
% this over-writes the prevous setting \setmathfont{TeX Gyre Pagella Math}

\begin{document}

abc $x\mid y$ $x ^^^^2502 y$ [^^^^2502] [|]

\end{document}

U+2502 is a box drawing character which really has no place in text and should probably just be replaced with | but the text used above produces

Missing character: There is no │ (U+2502) in font TeX Gyre Schola/OT:script=lat
n;language=dflt;mapping=tex-text;!

If you can not fix the source not to use it, you could remap it using character classes,or more simply with newunicodechar:

enter image description here

\documentclass{article}
\usepackage{unicode-math}
% only if you need it \usepackage{ucharclasses}
% not with xetex \usepackage{textcomp}
% avoid, better to just use fontspc, already included by unicode-math \usepackage{xltxtra}
\setmainfont{TeX Gyre Schola}
\setmathfont{TeX Gyre Schola Math}
% this over-writes the prevous setting \setmathfont{TeX Gyre Termes Math}
% this over-writes the prevous setting \setmathfont{Latin Modern Math}
% this over-writes the prevous setting \setmathfont{TeX Gyre Bonum Math}
% this over-writes the prevous setting \setmathfont{TeX Gyre Pagella Math}

\usepackage{newunicodechar} \newunicodechar{^^^^2502}{|}

\begin{document}

abc $x\mid y$ $x ^^^^2502 y$ [^^^^2502] [|]

\end{document}

David Carlisle
  • 757,742
  • Thank you for this which fixed the problem. However now a new problem arose: Missing character: There is no (U+1D45A) in font [lmroman10-regular]:mapping= but albatross told me that TeX Gyre Schola Math must have it. My source has \usepackage{unicode-math}\setmathfont{TeX Gyre Schola Math}. And also \newunicodechar{^^^^1D45A}{m} fails with Text line contains an invalid character. I have updated my original post above to include the minimum script to reproduce. Thanks again. – bliako Sep 29 '22 at 15:52
  • 1
    all math fonts will have it but why are you setting a math italic m in latin moder text ? ad why use TeX Gyre Schola Math with latin moder (your example here used TeX Gyre Schola for text. @bliako – David Carlisle Sep 29 '22 at 15:57
  • 1
    You have not updated the question @bliako – David Carlisle Sep 29 '22 at 15:59
  • just now! thanks. I have no control over the source. The source is supposed to be html but there are interspersed unicode characters like this fancy m. I can filter the source but there will be no end to this. People using a word processor to produce html or even email client will always pollute with this unicodes that said software is happy to provide. I am puzzled as to why my minimal script does not work but also \newunicodechar seems to break with U+1D45A – bliako Sep 29 '22 at 16:03