1

The following code with compiles with a warning on Windows 10 using LuaLatex although produces a readable document.

\documentclass{article}
\usepackage{babel}
\babelprovide[main, import]{thai}
\babelfont{rm}{FreeSerif}
\begin{document}
    สวัสดี
\end{document}

Warning:

font2.tex|| Package fontspec Warning: Language 'Thai' not available for font 'FreeSerif' with script 'Thai'.

The following triggers an extra warning and produces a document with the Thai text missing altogether.

\documentclass{article}
\usepackage[english,thai]{babel}
\babelprovide[import]{thai}
\babelfont{rm}{FreeSerif}
\begin{document}
Hello.

\begin{otherlanguage}{thai}
    สวัสดี
\end{otherlanguage}
\end{document}

Warnings:

font_problem.tex|| Package fontspec Warning: Language 'Thai' not available for font 'FreeSerif' with script 'Thai'.
font_problem.tex|| LaTeX Font Warning: Font shape `LTH/FreeSerif(0)/m/n' undefined using `LTH/norasi/m/n' instead on input line 3.

What is causing this and how can I solve it? FreeSerif does include Thai glyphs and the first code is taken straight from the Latex WikiBooks's example.

2
  • A font can have Thai glyphs, but not necessarily have the correct Thai “Script” and/or Thai “Language” setup. So this could be a font bug (or something else). May 9, 2020 at 2:44
  • @RuixiZhang I doubt that's the case, for FreeSerif is widely used in examples, including in Babel's own documentation. When I tried this demo from Overleaf, I got a warning not just for Thai, but also for Russian and French. Even switching to Google's Noto font doesn't help.
    – bongbang
    May 9, 2020 at 3:02

3 Answers 3

2

You must change the preamble slightly:

\documentclass{article}
\usepackage[english]{babel}
\babelprovide[import, main]{thai} % Remove main if the main language is english
\babelfont{rm}{FreeSerif}
\begin{document}
Hello.

\begin{otherlanguage}{thai}
    สวัสดี
\end{otherlanguage}
\end{document}

enter image description here

As to the warnings, they are usually harmless and are not errors. They are explained in the manual and also in Avoid fontspec warning with babel.

3
  • Thank you, but wouldn't that make Thai the main language? English is the main language in my document.
    – bongbang
    May 9, 2020 at 6:34
  • @bongbang In your original post thai was the last option when loading babel, so I assumed it was the main language. If it's not, just remove main. May 9, 2020 at 6:49
  • I now see that I actually misread the manual. Thank you. Putting the main language last is so counter-intuitive to me that my brain automatically "fixed" it.
    – bongbang
    May 9, 2020 at 7:05
1

Javier Bezos solved your problem, but for a bit more of an explanation.

The babel package is great, but you just ran into one of its biggest problems. You loaded

\usepackage[english,thai]{babel}

When you passed the thai option, babel loaded a file called thai.ldf. It tries to load an 8-bit font and does not work with Unicode. The dead giveaway is that you got an error message

LaTeX Font Warning: Font shape `LTH/FreeSerif(0)/m/n' undefined using `LTH/norasi/m/n' instead [...]

LTH is an 8-bit Local THai encoding. Any time XeLaTeX or LuaLaTeX try to use an encoding other than TU, some package thinks it’s still in 8-bit world.

The example that worked did this instead:

\usepackage{babel}
\babelprovide[main, import]{thai}

This loads a definition of Thai that works in LuaLaTeX and XeLaTeX.

So, use \babelprovide to load languages, then? I thought so for a while. Here’s the problem. Javier Bezos, who maintains babel, tells me that’s wrong. You’ll notice he fixed this with

\usepackage[english]{babel}
\babelprovide[import, main]{thai} % Remove main if the main language is english

As of 2020, you’re supposed to load some languages as package options to babel. Others only work with \babelprovide[import].

Which way to load which language is not well-documented. I originally wrote, but deleted, a list of the clues you do get in the documentation about which to use, but the takeaway was: you need to figure it out by trial and error.

5
0

The code below gets around the error and renders properly. Although the thread that Javier Bezos references provides clues as to what was wrong and could potentially go wrong, I still don't understand of all the things I've tried that seem to make sense in light of the information therein, only this solution works.

\documentclass{article}
\usepackage{babel}
\babelprovide[import, language=Default, main]{english}
\babelprovide[import, language=Default]{thai}
\babelfont{rm}{FreeSerif}

\begin{document}
Hello.

\begin{otherlanguage}{thai}
    สวัสดี
\end{otherlanguage}
\end{document}

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.