10

I have trouble setting monospaced font to Source Han Code JP font using \setmonofont. I tried the following code just the same as when I usually use fontspec package.

% file name: example01.tex
\documentclass{article}
\usepackage{fontspec}
\setmonofont[
    UprightFont = Source Han Code JP L,
    BoldFont = Source Han Code JP N
]{Source Han Code JP}
\begin{document}
\texttt{This is Source Han Code JP L.}\par
\texttt{\textbf{This is Source Han Code JP N.}}
\end{document}

Running lualatex example01.tex throws an error:

!LuaTeX error (file /Users/〈UserName〉/Library/Fonts/SourceHanCodeJP.ttc): sfnt:
 table not found...
 ==> Fatal error occurred, no output PDF file produced!

I also tried assigning font by its PostScript name or file name (with Path= and Extension= options like this), only to fail. The latter one gave ! fontspec error: "font-not-found".

How should I modify the code in order to use Source Han Code JP with LuaLaTeX? Is it relevant to this issue, that Source Han Code JP includes non-Latin (or more specifically, CJK) characters?

Note: I am using MacTeX-2015 and OS X Yosemite 10.10.3.


What I have confirmed so far

Using TrueType Collection fonts

Edit: I found this section was meaningless because Source Han Code JP is an OpenType Collection font, not a TrueType Collection font although its extension is .ttc. See Introducing & Building OpenType Collections (OTCs) if you are unfamiliar with OTC. As a matter of fact, there seems to be very few fonts adopting this format.

I first thought the cause of this error lies in using font installed by .ttc file. This is because I heard that we cannot embed Hiragino fonts (one of the Japanese fonts and installed by .ttc) into PDF in the conventional way on El Capitan. Then I tested Optima.ttc and Palatino.ttc with this code:

% file name: example02.tex
\documentclass{article}
\usepackage{fontspec}
\setmainfont[
    UprightFont = Palatino-Roman, % assigned by PostScript name
    BoldFont = Palatino Bold
]{Palatino}
\setsansfont[
    UprightFont = Optima Regular,
    BoldFont = Optima Bold
]{Optima}
\begin{document}
    This is Palatino.\par
    \textsf{This is Optima Regular.}
\end{document}

However, lualatex example02.tex worked quite well.

Optima and Palatino

Using OpenType Format fonts (on Windows 7)

I wondered whether sourcehancodejp-***.otf (*** is each weight) is available with LuaLaTeX and tried compiling example01.tex on my Windows where Source Han Code JPs are installed using .otf files. It worked with the following warnings which I think are negligible in this case.

LuaTeX warning (file c:/Windows/fonts/sourcehancodejp-normal.otf): Charset data possibly broken (num_glyphs too high)
LuaTeX warning (file c:/Windows/fonts/sourcehancodejp-light.otf): Charset data possibly broken (num_glyphs too high)

Black list that LuaLaTeX has

Before posting this question, I did several searches for solution and found these threads:

So, I looked into /usr/local/texlive/2015/texmf-dist/tex/luatex/luaotfload/luaotfload-blacklist.cnf. The content is as follows and SourceHanCodeJP.ttc is not written there.

spltfgbd.ttf
spltfgbi.ttf
spltfgit.ttf
spltfgrg.ttf

XeTeX

Unlike LuaLaTeX, example01.tex is compilable with XeLaTeX. It gives the desired PDF with no error.

XeLaTeX

Font name in Japanese

When we use Mac in Japanese, the font name for Source Han Code JP becomes 源ノ角ゴシック Code JP (see my comment about the name).

en-name

jp-name

I tried using this Japanese name.

% file name: example03.tex
\documentclass[a4paper]{article}
\usepackage{fontspec}
\setmonofont[
    UprightFont = 源ノ角ゴシック Code JP L,
    BoldFont = 源ノ角ゴシック Code JP N
]{Source Han Code JP}
\begin{document}
\texttt{This is Source Han Code JP L (in Japanese, 源ノ角ゴシック Code JP L).}\par
\texttt{\textbf{This is Source Han Code JP N (in Japanese, 源ノ角ゴシック Code JP N).}}
\end{document}

This code is also compilable with XeLaTeX but not with LuaLaTeX. Here is the output of xelatex example03.tex.

Japanese


Recent movement

After El Capitan's release, some Japanese TeX developers are striving to make OTC fonts available with LuaTeX and they seem to be successful.

Here are what I did today:

  1. get luaotfload from here,
  2. put necessary files in /usr/local/texlive/texmf-local/tex/luatex/luaotfload and /usr/local/texlive/texmf-local/scripts/luaotfload,
  3. run mktexlsr
  4. build patched LuaTeX, and
  5. replace the conventional luatex and luajittex in /usr/local/texlive/2015/bin/x86_64-darwin/ with the generated ones (also backup the original by adding -bak suffix).

Then, I tried to compile the following file but still get the same error as lualatex example01.tex.

\documentclass{ltjsarticle}
\usepackage{fontspec}
\usepackage{luatexja-fontspec}
\setmonofont{Source Han Code JP}
\begin{document}
\ttfamily test
\end{document}

Is there something wrong in my procedure? Note that I have not updated my Mac to El Capitan yet.

Merzong
  • 589
  • 5
  • 11

2 Answers2

6

It is only since in April 2015 that xdvipdfmx can embed OpenType Collection fonts into PDF correctly. https://www.tug.org/pipermail/tex-live/2015-April/036628.html However, this improvement has not been applied to LuaTeX, even in the latest TeX Live 2015.

Now Apple's new OS X 10.11 El Capitan has been released, and Japanese fonts (such as Hiragino) are merged into OpenType Collection (OTC) format (though the extension is .ttc, confusingly). Many LaTeX users in Japan are now facing troubles in typesetting Japanese documents due to this change, so there is a high demand for handling OTC fonts. To solve this problem, Hironori KITAGAWA, the developer of LuaTeX-ja (Japanese typesetting system on LuaTeX), is now kindly looking into this problem. When the patch is accepted by LuaTeX developers, LuaTeX will be able to embed OpenType Collection fonts into PDF, as well as xdvipdfmx does.

Update: LuaTeX beta-0.81.0 is now released! This version of LuaTeX can handle OpenType Collection fonts. See r5330 for detail. However, it seems that there is some kind of inconsistency between latest LuaTeX and luaotfload.

Sample LuaLaTeX source:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{SourceHanCodeJP-Regular}
\begin{document}
これは源ノ角ゴシックCode JP Rです。
\end{document}
  • Thank you for providing up-to-date information (actually, I was also keeping an eye on Japanese TeX community because I thought merging Hiragino fonts into OTC format is a crucial problem for Japanese OS X users). I have done sudo tlmgr update --self --all just now after the procedure like I edited the question yesterday, but still get the error sfnt: table not found.... Also, my LuaTeX doesn't seem to be of version 0.81.0: it says This is LuaTeX, Version beta-0.80.1 (TeX Live 2016/dev) (rev 5328). – Merzong Oct 08 '15 at 07:31
  • You should get at least r5330 of LuaTeX (r5330 is in experimental branch, not trunk): svn checkout -r 5330 --username anonsvn https://foundry.supelec.fr/svn/luatex/trunk will obtain LuaTeX-0.80.1 with OTC patch. – Hironobu YAMASHITA Oct 08 '15 at 08:49
  • And LuaTeX r5336 says "sync trunk with experimental"... – Hironobu YAMASHITA Oct 08 '15 at 08:54
  • Yes, I exactly did svn checkout -r 5330 --username anonsvn https://foundry.supelec.fr/svn/luatex/trunk, but LuaTeX says rev 5328. It seems starnge... – Merzong Oct 08 '15 at 15:59
  • Please check if the sources you've downloaded already have the modification in r5330. If not, patching it manually will fix them. – Hironobu YAMASHITA Oct 08 '15 at 16:07
  • Some modifications were not applied to my download sources although after the download svn said Checked out revision 5330.. I manually download those six files and replace them, but LuaTeX still says rev 5328. – Merzong Oct 08 '15 at 16:49
  • What LuaTeX says about "rev" does not matter, when you patched manually. – Hironobu YAMASHITA Oct 08 '15 at 17:08
  • I see, and now it worked properly. With ltjsarticle class, however, we encounter the same error as this question, and we need to load expl3 package first. Thank you so much for your help. – Merzong Oct 08 '15 at 23:38
  • I'm happy to hear about your successful result. Yes, I also know that ltjsarticle is now facing another problem due to some incompatible change in other dependent packages. Anyway, LuaTeX itself works fine. – Hironobu YAMASHITA Oct 09 '15 at 03:21
5

I have no problem with lualatex from up-to-date TL 2015 (I used "..." for some Japanese characters which the editor of SX doesn't allow.)

\documentclass[a4paper]{article}
\usepackage{fontspec}
\setmonofont[
    BoldFont = Source Han Code JP B,
    Scale=0.9
]{Source Han Code JP L}
\setmainfont{Source Han Sans Regular}
\begin{document}
This is Source Han Sans (のインストールが...)

\ttfamily
This is Source Han Code JP L (のインストールが...)

\bfseries
This is Source Han Code JP L (のインストールが...)
\end{document}

enter image description here

  • Really? Compiling your example with lualatex gave me the same error as lualatex example01.tex. Of course, TeX Live 2015 has been updated just now. I don't know what further information about my environment I should provide. – Merzong Aug 11 '15 at 14:47
  • In which directory did you saved the otf fonts? –  Aug 11 '15 at 15:47
  • In /Users/〈UserName〉/Library/Fonts/SourceHanCodeJP.ttc as the error message says. I double-clicked the downloaded SourceHanCodeJP.ttc to install it following this instruction. – Merzong Aug 11 '15 at 16:12
  • I used the OpenType versions of the font: *.otf –  Aug 11 '15 at 16:13
  • I re-installed the font using .otfs. Then I get an error: ! fontspec error: "font-not-found" ! ! The font "Source Han Code JP L" cannot be found. However, changing Source Han Code JP L to SourceHanCodeJP-Light (PostScript name) make it compilable. I'm quite confused how it works. – Merzong Aug 11 '15 at 16:44
  • then your directory isn't searched by luatex. Run in a terminal luaotfload-tool --list=. Then you'll see which fonts are found. –  Aug 11 '15 at 17:00
  • Running that code, I see <none> SourceHanCodeJP *** 1.004;PS 1.004;hotconv 1.0.83;makeotf.lib2.5.63406 for each weight. And I can use other fonts positioning in the same directory. – Merzong Aug 11 '15 at 17:10
  • Installing via SourceHanCodeJP.ttc, I can also see the lines <none> SourceHanCodeJP *** 1.004;PS 1.004;hotconv 1.0.83;makeotf.lib2.5.63406. Whether the codes are compilable differs however. – Merzong Aug 11 '15 at 17:15
  • ok, then try to use the PostScript name of the font, which often works in difference to the family name. –  Aug 11 '15 at 17:26
  • OK, I'll do so. By the way, could you try installing using SourceHanCodeJP.ttc, which requires OS X 10.8+? I want to know whether this problem about OTC font is characteristic to me or not. – Merzong Aug 11 '15 at 17:39
  • I do not have OSX running –  Aug 11 '15 at 19:13