1

I am trying to use XeLaTeX to use Devanagari (and Tibetan) script directly in my code. It seems that for some reason, XeLaTeX is not able to recognize the Devanagari characters I put into the .tex file. The problem seems to be something to do with the set up on my system, as others are able to compile the same or similar .tex files with good results. When I compile, however, I just get question marks instead of Devanagari characters. Here is a simple MWE that gives me a row of question marks. "Nakula" is a Devanagari font installed on my system (Mac OS Yosemite):

\documentclass{article}

\usepackage{fontspec}

\begin{document}

\setmainfont{Nakula}

शारदा शारदाम्भोजवदना वदनाम्बुजे।
सर्वदा सर्वदास्माकं संनिधिं संनिधिं क्रियात्।।

\end{document} 

Here is an excerpt from the transcript of the compilation, which seems to suggest somehow the font is not being accessed properly. I am certain that normally Nakula does work in this way with XeLaTeX, as I have seen examples others have made using it:

.................................................
. fontspec info: "no-scripts"
. 
. Font Nakula does not contain any OpenType `Script' information.
.................................................
\g__fontspec_family_Nakula_int=\count121
.................................................
. fontspec info: "no-font-shape"
. 
. Could not resolve font Nakula/BI (it probably doesn't exist).
.................................................
.................................................
. fontspec info: "no-font-shape"
. 
. Could not resolve font Nakula/B (it probably doesn't exist).
.................................................
.................................................
. fontspec info: "no-font-shape"
. 
. Could not resolve font Nakula/I (it probably doesn't exist).
.................................................
.................................................
. fontspec info: "defining-font"
. 
. Font family 'Nakula(0)' created for font 'Nakula' with options
. [Ligatures=TeX].
. 
. This font family consists of the following shapes:
. 
. * 'normal' with NFSS spec.:
. <->"Nakula/OT:mapping=tex-text;"
. 
. * 'small caps' with NFSS spec.:
. 
. and font adjustment code:
. 
.................................................
 [1

]
Paul
  • 417
  • If you are using Windows, is Nakulaan open type format, not ttf? XeLaTeX needs the opentype version of the font installed (otf) instead of ttf. – Mobius Pizza Mar 13 '15 at 15:55
  • Yes, it is the open type version, and I am using a Mac. I have tried many different open type Devanagari fonts, all with the same results. They all output question marks in their respective Roman scripts. – Paul Mar 13 '15 at 15:59
  • xelatex can handle .ttf and .otf-Fonts. I had no problems (on windows) with the ttf-version linked by Benjamin. I couldn't find an otf version and so can't test it. The warnings above regarding missing bold and italic versions are normal and harmless (the font doesn't have them). Add \XeTeXtracingfonts=1 to your document and then check the log for the exact font file used. – Ulrike Fischer Mar 13 '15 at 16:13
  • @UlrikeFischer It's the same problem the OP described here: http://tex.stackexchange.com/q/231997/27635 and here: http://tex.stackexchange.com/q/229492/27635. And this one is a dup, too. – karlkoeller Mar 13 '15 at 16:30
  • 3
    you have asked the same question many times. Are you sure you are saving the file in UTF-8. It's utf8 by the time it is posted to this web site but that isn't the same thing. – David Carlisle Mar 13 '15 at 21:12
  • Yes, I have asked this question (or a question similar to it) before, but no-one was able to solve the real problem. I think now you and Khaled (below) have finally gotten to it, though. I am using TeXShop on my Mac so I assumed it would automatically save the file in the correct format, but it seems somehow it isn't. When I look at the preview of the file in the Finder, there are question marks in place of the Devanagari script. This maybe points to this solution. If TeXShop is not saving it as a UTF-8 file, how do I do this? – Paul Mar 14 '15 at 04:41
  • @Paul Late now, but in case other people come here. The default file encoding for TeXShop is MacRoman. For an existing file you can change the encoding by using the Save-As menu (hold the option key and the choose Save-As from the file menu). In the save dialogue box there is a pulldown menu for Encoding. For new files you can add % !TEX encoding = UTF-8 Unicode to the file (use the Encoding item in the Macros menu). You can also set the default encoding in the TeXShop preferences. (Restart TeXShop for it to take effect.) – Alan Munn Jun 29 '16 at 23:08

1 Answers1

4

You need to tell fontspec about the script you want to use:

\setmainfont[Script=Devanagari]{Nakula}

This get rid if the first warning (though it probably does not have any visual effect because newer versions of XeTeX will try to guess the script from the text used if no explicit script is given).

The rest of the warnings are because this is a single style font (there is no italic or bold).

But the question marks issue does not seem to be related to XeTeX itself, I think your editor is changing the text encoding or something similar giving XeTeX garbage input.

  • Thank you, I think this must be the problem, now I just need to know how to send the correct input to XeTeX. I assumed that my editor, TeXShop, was doing this. – Paul Mar 14 '15 at 04:42
  • P.S. Specifying the script doesn't help; as you say, if it could recognize it at all it would recognize it automatically. It has something to do with the text my editor is feeding XeTeX, although I can't imagine how there could be a problem with that. – Paul Mar 14 '15 at 08:25
  • @Paul: Make sure your editor is set to UTF-8 encoding by default, some editors default to Latin-1 or some other similar encoding. – خالد حسني Mar 14 '15 at 21:29
  • Ah! Thank you! This was the problem, now it is working. – Paul Mar 15 '15 at 06:04