1

This question is related to this one: XeLaTeX - special unicode characters

I've got the same problem of missing unicode characters in my PDF when generated with XeLaTeX.

I used the following example code:

\documentclass[varwidth]{standalone}

\usepackage{fontspec}
\setmainfont{Linux Libertine}
\usepackage{listings}

\begin{document}
    These characters are working - +ľščťžýáí˝¨˘˛˙´°'

    These aren't - ├ └

    \begin{lstlisting}
        Listing: ├ └
    \end{lstlisting}
\end{document}

I tried different fonts with the same results. I've checked in my LibreOffice Writer that the missing characters are included within the given font.

The output file: enter image description here

My OS is Linux (Manjaro) and I run XeLaTeX via the terminal.

Does someone got an idea what the underlying problem is?

Solutions:

The problem is indeed that the font is not suited for the characters I would like to have.

One solution by Marijn is shown below utilizing a package for such missing characters.

Another way is depicted in this blog post where a fallback font is implemented: https://blog.michael.franzl.name/2014/12/10/xelatex-unicode-font-fallback-unsupported-characters/ Repost of the working example code:

\documentclass[]{book}

\usepackage{fontspec}
\setmainfont{Junicode}
\newfontfamily\myregularfont{Junicode}
\newfontfamily\mychinesefont{IPAexMincho}

\usepackage[CJK]{ucharclasses}
\setTransitionsForCJK{\mychinesefont}{\myregularfont}

\begin{document}
Latin text. Chinese text: 紫薇北斗星  Modern greek: Διαμ πριμα εσθ ατ, κυο πχιλωσοπηια Ancient greek: Μῆνιν ἄειδε, θεά, Πηληϊάδεω Ἀχιλῆος. And regular latin text.
\end{document}
  • 2
    Linux Libertine lacks those characters. – egreg Oct 17 at 11:46
  • But why are those characters are displayed in my libreoffice writer? – JTS Oct 17 at 11:49
  • Because the OS provides fallback fonts; this is not available with XeTeX or LuaTeX which are for typography, so fine control is needed. – egreg Oct 17 at 11:54
  • Okay, I see. So thank you very much for your answers and I will try to find a find which will work. – JTS Oct 17 at 12:22
1

The package pmboxdraw contains definitions for such characters, which are drawn as lines. In pdfLaTeX this works directly, if you use the characters in the main text. Inside lstlisting you need to define such characters separately in lstset, see How to use extended ASCII characters in the lstlisting environment?. For more characters see the pmboxdraw manual which contains macros for around 140 characters.

MWE for pdfLaTeX:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{pmboxdraw}

\begin{document}

    These aren't - ├ └

\lstset{literate={┐}{\textSFiii}1%
  {└}{\textSFii}1%
  {┴}{\textSFvii}1%
  {┬}{\textSFvi}1%
  {├}{\textSFviii}{1}%
  {─}{\textSFx}1%
  {│}{\textSFxi}1%
  {┼}{\textSFv}1,}

    \begin{lstlisting}
        Listing: ├ └
    \end{lstlisting}
\end{document}

Result:

enter image description here

For XeLaTeX it is a bit more difficult, because fontspec prevents pmboxdraw to process the characters. However, you can set them individually with \newunicodechar to use the pmboxdraw macros, similar to the listings solution.

\documentclass{article}

\usepackage{fontspec}
\setmainfont{Linux Libertine O}

\usepackage{listings}
\usepackage{pmboxdraw}
\usepackage{newunicodechar}
\newunicodechar{└}{\textSFii}
\newunicodechar{┴}{\textSFvii}
\newunicodechar{┬}{\textSFvi}
\newunicodechar{├}{\textSFviii}
\newunicodechar{─}{\textSFx}
\newunicodechar{┼}{\textSFv}
\newunicodechar{│}{\textSFxi}

\begin{document}
    These characters are working - +ľščťžýáí˝¨˘˛˙´°'

    These aren't - ├ └

\lstset{literate={┐}{\textSFiii}1%
  {└}{\textSFii}1%
  {┴}{\textSFvii}1%
  {┬}{\textSFvi}1%
  {├}{\textSFviii}{1}%
  {─}{\textSFx}1%
  {│}{\textSFxi}1%
  {┼}{\textSFv}1,}

    \begin{lstlisting}
        Listing: ├ └
    \end{lstlisting}
\end{document}

Result:

enter image description here

  • Thanks a lot for this solution Marijn. For me it's not the best way, cause I now got even more characters which are not working. But anyway, the solution is very interesting. – JTS Oct 18 at 8:47
  • @JTS that is strange, which characters do not work anymore? – Marijn Oct 18 at 12:08
  • Sorry, I've not included them into my question but I also want to have these characters in my document: 1F57F: 🕿, 1F4E7: 📧, 23F7: ⏷, 25BC: ▼, 1F83B: 🠻, 1F847: 🡇. If I'm not mistaken, these are not included in pmboxdraw but included in the font Symbola. – JTS Oct 21 at 7:57
  • @JTS you can use ucharclasses as in your own edit to your question for both the box drawing commands and for the symbols, defining fonts that contain them (e.g., Liberation Sans for box drawing, Symbola for the symbols). They have Unicode block names that you can look up at, e.g., en.wikipedia.org/wiki/Unicode_block. Note that your codes do not seem fully accurate, for example the phone icon is U+260E. Does that answer your question? By the way, please don't edit solutions into the question, but post an additional answer and leave the question as it was. – Marijn Oct 21 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.