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.

0

2 Answers 2

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}
9
  • 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
    Commented Oct 8, 2015 at 7: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. Commented Oct 8, 2015 at 8:49
  • And LuaTeX r5336 says "sync trunk with experimental"... Commented Oct 8, 2015 at 8: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
    Commented Oct 8, 2015 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. Commented Oct 8, 2015 at 16:07
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

11
  • 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
    Commented Aug 11, 2015 at 14:47
  • In which directory did you saved the otf fonts?
    – user2478
    Commented Aug 11, 2015 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
    Commented Aug 11, 2015 at 16:12
  • I used the OpenType versions of the font: *.otf
    – user2478
    Commented Aug 11, 2015 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
    Commented Aug 11, 2015 at 16:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .