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.
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:
- using Hoefler Text font under lualatex and MacOSX
- How to properly install and use a new font with LuaLaTeX?
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.
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).
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
.
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:
- get
luaotfload
from here, - put necessary files in
/usr/local/texlive/texmf-local/tex/luatex/luaotfload
and/usr/local/texlive/texmf-local/scripts/luaotfload
, - run
mktexlsr
- build patched LuaTeX, and
- replace the conventional
luatex
andluajittex
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.