# Problem with chinese in lualatexja (bad argument #1 to 'open')?

I'm trying the example from How to use Chinese with lualatex? (TexLive 2014, updated to frozen):

\documentclass{article}
\usepackage{luatexja-fontspec}
\setmainjfont{FandolSong}
\begin{document}

\end{document}


I try to compile this with lualatex test.tex - but cannot, as it fails with:

...
(/media/texlive/2014/texmf-dist/tex/luatex/luatexja/ltj-rmlgbm.lua)
! LuaTeX error ...xlive/2014/texmf-dist/tex/luatex/luatexja/ltj-rmlgbm.lua:90: b
ad argument #1 to 'open' (string expected, got nil).
l.172 }

?
(/media/texlive/2014/texmf-dist/tex/luatex/luatexja/ltj-base.sty)
! LuaTeX error [\directlua]:1: attempt to index field 'stack' (a nil value).
l.249   }
%
?
(/media/texlive/2014/texmf-dist/tex/luatex/luatexja/ltj-latex.sty
(/media/texlive/2014/texmf-dist/tex/luatex/luatexja/patches/lltjfont
.sty (/media/texlive/2014/texmf-dist/tex/latex/ms/everysel.sty)
ABD: EverySelectfont initializing macros)
...


What am I missing?

• I get no error from the test document. Can you add \listfiles and show the result? – egreg May 7 '15 at 23:03

I think it is a bug of luaotfload. You can update to TeX Live 2015 (in a few days) and the problem should have been fixed.

Well, I think I got it. First, I added a print line to texmf-dist/tex/luatex/luatexja/ltj-rmlgbm.lua:90:

   local function open_cmap_file(name, inc, cid_dec, mke)
print("open_cmap_file: name " .. name) -- added
fh = io.open(kpse.find_file(name, 'cmap files'), "r")
....


... and realized it prints out: open_cmap_file: name UniJIS2004-UTF32-H. So I looked up:

\$ tlmgr search --global --file UniJIS2004
...
texworks:


... so I installed adobemapping with: tlmgr install adobemapping.

Now with this, compilation fails with:

luaotfload | db : Reload initiated (formats: otf,ttf,ttc,dfont); reason: "Font IPAExMincho not found.".
! Font \JY3/mc/m/n/10=IPAExMincho:jfm=ujis at 9.62219pt not loadable: metric dat
relax
l.34 \kanjiencoding{JY3}\selectfont


... so I have a font problem now. I'm on Ubuntu 11.04, and have no idea which specifically Chinese fonts I'd have. Via texdoc luatexja, I realized the default for this package is indeed \def\ltj@stdmcfont{IPAExMincho} - but also, that one could include a luatexja.cfg file in the same directory as the .tex file; these contents are recommended in the manual:

\def\ltj@stdmcfont{psft:Ryumin-Light}
\def\ltj@stdgtfont{psft:GothicBBB-Medium}


... and with this - and without a \setmainjfont statement - the example compiles, although it seems some characters may be missing.

I had worked with simsun.ttc font before, so I wanted to try it. Note, if the font name is simsun.ttc, and it is not installed system-wide, but merely present (even as a symlink) in the same directory as the .tex file, then it can not be read in with a \setmainjfont{SimSun}, only with \setmainjfont{simsun}. However, for my particular version of simsun.ttc, I get this compile error:

luaotfload | db : Reload initiated (formats: otf,ttf,ttc,dfont); reason:
-cache/generic/fonts/otf/simsun.luc)(compiling luc: /home/user/.texlive
2014/texmf-var/luatex-cache/generic/fonts/otf/simsun.luc)(save: /media/
texlive/2014/texmf-var/luatex-cache/generic/fonts/otf/simsun.lua)(save: /media
/texlive/2014/texmf-var/luatex-cache/generic/fonts/otf/simsun.luc)
...
LaTeX Font Warning: Font shape JY3/simsun(0)/bx/n' undefined
(Font)              using JY3/simsun(0)/m/n' instead on input line 8.

[1{/media/texlive/2014/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./testb.aux)
...
</media/texlive/2014/texmf-dist/fonts/opentype/public/lm/lmroman10-re

So, even if I had no problem with this font with pdflatex/{CJKutf8}, here simsun.ttc fails with Invalid TTC index number. Wish I knew a fix for this (maybe it's this bug: [NTG-context] Latest beta stops loading some ttc fonts)...
Then I found SimSun.ttf somewhere for download; removed simsun.ttc from the directory, and downloaded SimSun.ttf in the same directory (as the .tex file). Then I used \setmainjfont{SimSun} in the code instead -- and the example finally compiled, and all characters were apparently present in the PDF.