Ticket #40341

Strange ruby position with SourceHanSansJP when JFM is set to prop

Open Date: 2020-04-21 09:11 Last Update: 2020-05-17 10:54

Reporter:
Owner:
(None)
Type:
Status:
Closed
Component:
(None)
MileStone:
(None)
Priority:
5 - Medium
Severity:
5 - Medium
Resolution:
Fixed
File:
None

Details

Comment out the line "YokoFeatures={JFM=prop}," and the ruby will be placed correctly. This behavior is not inspected in the default font. The bug seems to have been introduced since texlive 2020.

Here are the correct output and incorrect output:

https://i.loli.net/2020/04/21/8ylSbJMIVAcHTDL.png https://i.loli.net/2020/04/21/5LOxbIFU6vWYmnr.png

% !TeX program = LuaLaTeX
% !TeX encoding = UTF-8

\documentclass{article}

\usepackage{luatexja}
\usepackage{luatexja-ruby}
\usepackage[no-math]{luatexja-fontspec}
\usepackage[a5paper]{geometry}

\defaultjfontfeatures{
  YokoFeatures={JFM=prop},
  Script=CJK
}

\setmainjfont{SourceHanSansJP}[
  UprightFont=*-Normal,
  BoldFont=*-Medium,
  Language=Japanese
]

\title{Test}

\begin{document}

\maketitle

\begin{abstract}
 \ruby{明日}{あした}
\end{abstract}

 \ruby{明日}{あした}
\end{document}

Ticket History (3/9 Histories)

2020-04-21 09:11 Updated by: taroxd
  • New Ticket "Strange ruby position with SourceHanSansJP when JFM is set to prop" created
2020-04-21 09:39 Updated by: taroxd
Comment

By the way, default JFM and SourceHanSansJP will result in strange kerning when two-em-dashes are used.

https://i.loli.net/2020/04/21/WEhDqLP8JxR2kzj.png

% !TeX program = LuaLaTeX
% !TeX encoding = UTF-8

\documentclass{article}

\usepackage{luatexja}
\usepackage{luatexja-ruby}
\usepackage[no-math]{luatexja-fontspec}

\defaultjfontfeatures{
  Script=CJK
}

\setmainjfont{SourceHanSansJP}[
  UprightFont=*-Normal,
  BoldFont=*-Medium,
  Language=Japanese
]

\title{Test}

\begin{document}

\maketitle

 \ruby{明日}{あした}——明日
\end{document}
(Edited, 2020-04-21 09:54 Updated by: taroxd)
2020-04-21 10:12 Updated by: h7k
Comment

Usually, dimensions which are specified by a JFM and actual glyph dimensions differs. For example, "明" in SourceHanSansJP-Normal 10pt has only 7.92pt in height and 0.81pt in depth, but the default JFM requests 8.8pt in height and 1.2pt in depth.

To cope with the difference, LuaTeX-ja sometimes adds \norule (invisible rule), or packs the character into another box. But the JFM "prop" does not specify any dimensions, so "明日" with this JFM takes less vertical space than it with the default JFM.

\documentclass{article}
\usepackage{luatexja-fontspec}

\setsansfont{SourceHanSansJP-Normal}[Script=CJK, Language=Japanese]
\setmainjfont{SourceHanSansJP-Normal}[Script=CJK, Language=Japanese]
  % Note that Japanese fonts are scaled by 0.962216 by default

%\tracingonline1\showboxbreadth10000 \showboxdepth10000
\begin{document}
% as ALchars
\setbox0\hbox{\sffamily \ltjalchar`明}%
\typeout{(\the\ht0:\the\dp0)}% ==> (7.92pt:0.81pt)

% as JAchars; default JFM (ujis)
\setbox0\hbox{明}%
\typeout{(\the\ht0:\the\dp0)}% ==> (8.46753pt:1.15466pt)
%\showbox0
% ==> \hbox(8.46753+1.15466)x9.6222, direction TLT
%     .\whatsit4=[]
%     .\norule(8.46753+1.15466)x0.0
%     .\JY3/SourceHanSansJP-Normal(1)/m/n/10 明

% as JAchars; JFM=prop
\addjfontfeatures{YokoFeatures={JFM=prop}}
\setbox0\hbox{明}%
\typeout{(\the\ht0:\the\dp0)}% ==> (7.62077pt:0.7794pt)
%\showbox0
% ==> \hbox(7.62077+0.7794)x9.6222, direction TLT
%     .\whatsit4=[]
%     .\JY3/SourceHanSansJP-Normal(2)/m/n/10 明

\end{document}

Perhaps saving the following file as jfm-propw.lua, and specifying "JFM=propw" should resolve the issue.

luatexja.jfont.define_jfm {
   dir = 'yoko',
   zw = 1.0, zh = 1.0,

   [0] = {
      align = 'left', left = 0.0, down = 0.0,
      -- width = 'prop', height = 'prop', depth = 'prop', italic=0.0, <= jfm-prop.lua
      width = 'prop', height = 0.88, depth = 0.12, italic=0.0,
   }
}

This behavior is not inspected in the default font.

luatexja-fontspec does not execute \setmainjfont etc. automatically.

2020-04-21 10:21 Updated by: h7k
Comment

By the way, default JFM and SourceHanSansJP will result in strange kerning when two-em-dashes are used.

It seems that two em-dashes makes a ligature, which is assigned to U+F0554 by LuaTeX. Because this codepoint belongs to a Private Use Area, we cannot specify its width in JFM. I'll think another approach.

2020-04-21 10:38 Updated by: taroxd
Comment

Thanks.

luatexja.jfont.define_jfm {
   dir = 'yoko',
   zw = 1.0, zh = 1.0,

   [0] = {
      align = 'left', left = 0.0, down = 0.0,
      -- width = 'prop', height = 'prop', depth = 'prop', italic=0.0, <= jfm-prop.lua
      width = 'prop', height = 0.88, depth = 0.12, italic=0.0,
   }
}

That's exactly how I workaround this issue so far. I just replaced the contents of jfm-prop.lua with that, but I do not think that is an elegant solution. Will this JFM file be added to luatexja in the future? Adding this file to my own environment is not a satisfatory way because some of these documents are open-sourced, while adding this file to each document seems inconvenient.

Also, I wonder why I did not encounter this issue prior to texlive 2019?

(Edited, 2020-04-21 12:34 Updated by: taroxd)
2020-04-24 07:28 Updated by: h7k
Comment

Will this JFM file be added to luatexja in the future?

Yes, as jfm-prop.lua (old) and jfm-propw.lua (as above comment).

It seems that two em-dashes makes a ligature, which is assigned to U+F0554 by LuaTeX.

Oh, I confused a horizontal bar (U+2015, ―) and an em-dash (U+2014, ―).

  • A ligature from two horizontal bars (U+2015) is exactly two full-width wide, and typesetting it with the commit 8eea96e should be fine.
  • A em-dash is considered as a JAchar by default LuaTeX-ja (because it is included in JIS X 0208, a basic Japanese character set). If you want to use em-dash (not horizontal bar), it would be better to configure it as an ALchar, by \ltjdefcharrange{4}{`—} (em-dash only) or other methods.
2020-04-24 08:19 Updated by: None
Comment

If I configure with \ltjdefcharrange{4}{—} , then the two em dashes do not have the same width as two characters do. Actually I am using luatexja in a Chinese document (with SourceHanSansCN of course) , and that is why I use U+2014 instead of U+2015.

% !TeX program = LuaLaTeX
% !TeX encoding = UTF-8

\documentclass{article}

\usepackage{luatexja}
\usepackage{luatexja-ruby}
\usepackage[no-math]{luatexja-fontspec}

\defaultjfontfeatures{
  YokoFeatures={JFM=prop},
  Script=CJK
}

\setmainjfont{SourceHanSansJP}[
  UprightFont=*-Normal,
  BoldFont=*-Medium,
  Language=Japanese
]

\title{Test}

\begin{document}

\maketitle

文字二つの幅です。(JAChar)

——ダッシュの幅です。(JAChar)

\ltjdefcharrange{4}{`—}
——ダッシュの幅です。(ALChar)
\end{document}
2020-04-24 18:18 Updated by: h7k
Comment

Oh, I see. I added new character classes for U+2014, U+2E3A (two-em dash), U+2E3B (three-em dash). So commit 1a54137 should fix the issue, I hope.

2020-05-17 10:54 Updated by: h7k
  • Resolution Update from None to Fixed
  • Status Update from Open to Closed
Comment

I uploaded new version (20200517.0) to CTAN, so I close this ticket.

Attachment File List

No attachments

Edit

You are not logged in. I you are not logged in, your comment will be treated as an anonymous post. » Login