5
\documentclass{article}
\usepackage{fontspec}
    \setmainfont{DejaVu Serif}
    \setsansfont{DejaVu Sans}
    \setmonofont{DejaVu Sans Mono}
\begin{document}
Hello World!

\textsf{Hello World!}

\texttt{Hello World!}
\end{document}

compiled with XeLaTeX gives me this:

XeLaTeX output

Copying the output with SumatraPDF even shows regular space characters between the letters and a line break between the words:

Hello World!
Hello World!
H e l l o
W o r l d !

(Copying it with Adobe Reader XI Win, however, yields three identical lines.)

This problem doesn't occur with LuaLaTeX:

LuaLaTeX output

The OCR-layer-text for LuaLaTeX is flawless as well, using either PDF viewer.

I assume this is a XeTeX bug? Can I circumvent it somehow?

I'm using MiKTeX 2.9, and version 2.33 of the DejaVu fonts, which I think came preinstalled with Windows (7), at least I can't recall manually installing these fonts. This version seems to be the current version, at any rate.

P.S.: If someone can recommend another monospaced font for code that a) goes well with Linux Libertine and b) contains lowercase Greek letters, that'd be helpful, too. But that just as an aside :).

doncherry
  • 54,637
  • I have no problem on my Mac. – egreg Nov 28 '12 at 20:59
  • No problem here either (TeX Live on Linux). – خالد حسني Nov 28 '12 at 22:03
  • A friend compiled my MWE on his MiKTeX 2.9 system and got the same result as I, so it might be MiKTeX-specific behavior? (Wouldn't surprise me for that kind of issue, intuitively.) – doncherry Nov 28 '12 at 22:20
  • 2
    I confirm the behavior with MiKTeX. It seems it is MiKTeX specific. –  Nov 28 '12 at 22:41
  • I have no problem with MikTeX 2.9, Win 7 but fresh downloads from the SF page of DeJaVu project. – percusse Nov 28 '12 at 23:50
  • Gah, the problem seems to be exactly the same as in \setmainfont{Linux Libertine O} uses pfb files instead of otf/ -- every MiKTeX user with the dejavu package installed should get that behavior. I'm kinda busy right now, but I'll post some more details towards the weekend. – doncherry Nov 29 '12 at 00:54
  • Perhaps something for the MiKTeX Bug Tracker. – Speravir Nov 29 '12 at 03:04
  • I’m confused: I have the package dejavu installed in MiKTeX with both the Truetype and Type1 font files and I have the fonts in C:\Windows\Fonts. But I don’t get this behaviour, what is confirmed by several users! BTW I can’t tell from the log file, which font files are used without one fact: It’s only Truetype. – Speravir Nov 29 '12 at 04:56
  • @Speravir Strage. What happens if you remove DejaVuSansMono.ttf from C:\Windows\Fonts? (In order to do this, I usually have to move the file somewhere else with cmd run as admin.) Have you ever changed anything in your localfonts2.conf (or related files)? – doncherry Nov 29 '12 at 05:10
  • @doncherry: That’s what I later thought of myself: See the order in localfonts.conf. Here on my computer the Windows fonts folder is read in first, then the Type1 fonts folders (first local, then MiKTeX’ own), after that the MiKTeX opentype folder, and last of all the MiKTeX truetype folder! – Speravir Nov 29 '12 at 18:50
  • @doncherry It gets even weirder: Tried out now with temporary disabled files in Windows fonts folder, but no change! BTW I‘ve never modified localfonts2.conf. But perhaps I need to delete some font cache first? – Speravir Nov 29 '12 at 19:14
  • @Speravir I never needed to deal with font cache. Does my answer solve the issue on your machine? Perhaps you can add some info for single-user mode? (Sorry about the late response!) – doncherry Dec 21 '12 at 22:28

2 Answers2

2

Have you tried specifying the fonts in more detail? I've tested the following in MiKTeX 2.9 without a problem.

\documentclass{article}
\usepackage{fontspec}
\defaultfontfeatures{
    Extension      = .ttf ,
    Ligatures      = TeX ,
    UprightFont    = * ,
    ItalicFont     = *-Oblique ,
    BoldFont       = *-Bold ,
    BoldItalicFont = *-BoldOblique
}
\setmainfont[ItalicFont = *-Italic, BoldItalicFont = *-BoldItalic]{DejaVuSerif}
\setsansfont{DejaVuSans}
\setmonofont{DejaVuSansMono}

\begin{document}
Hello World!

\textsf{Hello World!}

\texttt{Hello World!}
\end{document}

You do need to have the dejavu package installed.

Silke
  • 10,511
  • Silke, when the package dejavu not is installed, the font files will anyway only be found in the Windows fonts folder. The problem arises, when the package is installed, and perhaps no DejaVu font files in the Windows folder are existent. – Speravir Nov 29 '12 at 19:13
  • Thanks! This works indeed, but I accepted my own answer because it solves the problem globally. (Also, sorry for the late response, I was pretty tied up the past weeks.) – doncherry Dec 21 '12 at 22:21
2

The problem turned out to be more or less the same as in \setmainfont{Linux Libertine O} uses pfb files instead of otf: XeLaTeX didn't even use the Windows fonts, but the ones in the texmf tree (which for some reason seem to be flawed). The solution is the same as for the other question: Tell MiKTeX not to use those.

Here's how to do that:

Open your localfonts2.conf file. You may have several versions of this file in different places; the one that works for me is in C:\Users\doncherry\AppData\Roaming\MiKTeX\2.9\fontconfig\config (“Admin” MiKTeX installation). The file should look like this:

<?xml version="1.0"?>
<fontconfig>
  <selectfont>
    <rejectfont>
      <glob>C:/Program Files (x86)/MiKTeX 2.9/fonts/type1/public/dejavu/*</glob>
    </rejectfont>
  </selectfont>
</fontconfig>

With this configuration, everything works for me. According to Khaled Hosny, this specification will not be necessary anymore in the future, perhaps in MiKTeX 3.0.


Update:

While not using the Type1 fonts makes the problem go away, the Type 1 fonts still were buggy somehow. I contacted the author of the dejavu package; he identified the problem (too big Em Size) and said it would be fixed in a future version of the package.

doncherry
  • 54,637