# LuaTeX error: “Unable to read environment locale:exit now.”

This is the output from LaTeX (MWE is at the end of this post):

Running LaTeX' onluatex_test' with lualatex --jobname=luatex_test -file-line-error -interaction=nonstopmode "\input" luatex_test.tex'' Unable to read environment locale:exit now.

If I set TeX engine to be latex instead of lualatex in Emacs (I use version 25.1 (9.0)), it completes compilation. Also, the compilation completes if I call lualatex from the terminal.

Running locale in Emacs's shell gives:

LANG="en_DE.UTF-8" LC_COLLATE="C" LC_CTYPE="C" LC_MESSAGES="C" LC_MONETARY="C" LC_NUMERIC="C" LC_TIME="C" LC_ALL=

My MWE:

\documentclass{article}
\begin{document}
Test compilation with luatex.
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-engine: luatex
%%% TeX-master: t
%%% End:


Which variable in Emacs do I need to customize?

• I removed emacs tag as it happens if you run it directly in the shell, you could set LANG to be en_US.UTF-8 – David Carlisle Jun 10 '17 at 19:07
• – David Carlisle Jun 10 '17 at 20:22

I can confirm the same using cygwin texlive 2017 it is enough to set

export LANG="en_DE.UTF-8"

lualatex testfile


to get

Unable to read environment locale:exit now.


You should raise this on the luatex list, or I could, although en_DE seems like a strange locale. German English?

Setting LANG to (say) en_US makes it work again.

It has been confirmed in the thread on the luatex list starting at

http://tug.org/pipermail/luatex/2017-June/006576.html

that it is by design that luatex quits on unknown locale, although they may try to make the error message a bit more helpful.

en_DE seems a strange value, depending on your operating system you may be able to use

locale -a


to list all the known values.

On my system

locale -a | grep en_


lists 37 en_ variants, but en_DE is not one of them.

So I would not fix this in the emacs editor setup but rather set your locale to something other than en_DE in your shell.

• How do I set it in Emacs? I have found current-language-enivronment, but it is already English. – honey_badger Jun 10 '17 at 20:52
• @ted_kingdom M-x setenv I guess. – David Carlisle Jun 10 '17 at 21:01
• @ted_kingdom - Try adding something like this %%% eval: (setenv "LANG" "de_DE.UTF-8") in your .tex file in Local Variables: and reopen the file. – Arash Esbati Jun 10 '17 at 21:03
• @DavidCarlisle, en_DE means that in my system preferences I have Germany set as a region. Interestingly, on my other laptop where it says Sweden I do not have a problem with locale being en_SE. However, changing Germany to Sweden doesn't do the trick. – honey_badger Jun 11 '17 at 10:00
• @DavidCarlisle, Even if I set export LANG="en_US" I get error. Should I set any other variable as well? – Royi May 26 '18 at 23:28

Changing the locale in my shell configuration file did not solve the problem. I found the reason here: locale when launching Emacs.app on OS X.

What did solve the problem was either adding %%% eval: (setenv "LANG" "de_DE.UTF-8") to my source file, as suggested in the comments, or adding this line to .emacs file: (setenv "LANG" "en_US.UTF-8").

On my system, I have the en_DK.utf8 locale set (except for LC_TIME, which is apparently set to da_DK.utf8). I also ran into this error.

Other answers here insinuate that it is the "weird" form of the chosen locale -- ie. there is really no such thing as danish/german english -- that is the cause of the problem. That is not correct, because in my case changing en_DK to en_GB did not help the problem.

Rather the issue is that one of the set locales is not installed. In my case, it was actually the da_DK.utf8 locale that wasn't installed! You can check which locales are currently set with locale and list installed ones with locale -a. Install missing locales by running

sudo locale-gen da_DK.utf8
sudo update-locale


As described in this link. Lualatex will work then work fine, even with "weird" locales like en_DK, provided that it is installed.