1

This question has a follow-up question, namely: "Change letter-spacing / tracking for punctuation marks (luatexja-fontspec)".

Imagine you are working in LuaLaTeX, and you want to use Chinese texts (often featuring long series of characters without spaces) to break across lines, so that the end-user can actually still read them. How would you do this?

According to an answer to the OP "How to use Chinese with lualatex?", one can simply use:

\usepackage{luatexja-fontspec}

However. This seems to overrule the use of a user-specified font, as would normally be customized by:

\setmainfont{...}

So my question is, in LuaLaTeX, how to both be able to:

  • specify a custom font for the whole document,
  • let the Chinese text line-break so as to make it readable?

MWE (to be compiled with LuaLaTeX)

\documentclass[a4paper, fontsize=30pt]{scrreprt}

\usepackage{fontspec}
\setmainfont{HanWangKaiMediumChuIn_wp010-08}

\begin{document}

勞碌奔波、勉強應付。《京本通俗小說.錯斬崔寧》:「光陰迅速,大娘子在家巴巴結結,將近一年,父親見他守不過,便叫家裡老王去接他來。」也作「巴巴急急」、「巴巴劫劫」、「波波劫劫」、「劫劫巴巴」、「劫劫波波」、「結結巴巴」。

\end{document}

  • Note: This MWE uses a custom font, namely HanWangKaiMediumChuIn_wp010-08.ttf, so one needs to to download it and install it in case one wishes to use the same.

P.S.: According to the luatexja-package documentation, changing the default fonts should be possible (e.g. using \def\ltj@stdmcfont{psft:...}), but I have not been able to do so. Perhaps this option is restricted to fonts which are part of the luatexja-package?


P.P.S: \usepackage{seqsplit} (see e.g. this answer to the OP "Automatic line breaking of long lines of text?") also doesn't seem to work for Chinese text.

O0123
  • 1,773
  • Please provide a compilable answer for potential answer writers to play with. Also, which non-default font would you like to use? – Mico Oct 01 '17 at 06:32
  • 1
    @Mico Let me make a MWE then. I would like to use the font HanWangKaiMediumChuIn_wp010-08.ttf, so one needs to to download it in case one wishes to use the same. – O0123 Oct 01 '17 at 06:35
  • And, just for clarification: The title of your posting refers to Chinese characters, whereas the luatexja package is set to deal with Japanese text. Japanese texts, almost invariably, contain a mixture of kanjis (Chinese characters) and hiragana and katakana glyphs. Are you looking for a solution that deals exclusively with Chinese glyphs/characters, or will it be a mixture of kanji and kana glyphs? – Mico Oct 01 '17 at 06:37
  • My particular purpose is to come up with a solution for Chinese characters only. I have just mentioned the luatexja package as per the mentioned answer to another OP, in which it was (simplistically) argued that: "the tools designed for Chinese and Japanese usually work the same." – O0123 Oct 01 '17 at 06:39
  • @Mico Added a MWE now. – O0123 Oct 01 '17 at 06:42
  • Just out of curiosity: Since you mention the luatexja-fontspec package in your write-up, is there a reason for loading fontspec instead (and for not using \setmainjfont)? (See also page 11 of the package's user guide.) – Mico Oct 01 '17 at 06:58
  • @Mico If you find a way to use the font HanWangKaiMediumChuIn_wp010-08 without loading fontspec then that's fine for me. – O0123 Oct 01 '17 at 07:07
  • 1
    \usepackage{luatexja-fontspec}\setmainjfont{Microsoft YaHei} as suggested by @Mico works fine for me (at least I get line breaks, but I have no idea if they are sensible). – Ulrike Fischer Oct 01 '17 at 10:08
  • @UlrikeFischer That works great. Thanks a lot. If you could provide an answer I will accept. If you use the font from the OP, you will notice that the tracking (inter-letter-spacing) needs to be enlarged. Only, I don't know how to do so. Could you help? – O0123 Oct 01 '17 at 10:12

1 Answers1

1

I don't have your font. But with another one \setmainjfont works fine. The spacing between the glyph can be extended with \ltjsetparameter{kanjiskip=...} (see 4.2 kanjiskip and xkanjiskip in the documentation):

\documentclass[a4paper, fontsize=30pt]{scrreprt}
\usepackage{luatexja-fontspec}
\setmainjfont{Microsoft YaHei}

\begin{document}
勞碌奔波、勉強應付。《京本通俗小說.錯斬崔寧》:「光陰迅速,大娘子在家巴巴結結,將近一年,父親見他守不過,便叫家裡老王去接他來。」也作「巴巴急急」、「巴巴劫劫」、「波波劫劫」、「劫劫巴巴」、「劫劫波波」、「結結巴巴」。


\ltjsetparameter{kanjiskip=20pt}
勞碌奔波、勉強應付。《京本通俗小說.錯斬崔寧》:「光陰迅速,大娘子在家巴巴結結,將近一年,父親見他守不過,便叫家裡老王去接他來。」也作「巴巴急急」、「巴巴劫劫」、「波波劫劫」、「劫劫巴巴」、「劫劫波波」、「結結巴巴」。

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • However, it does not increase the inter-spacing of punctuation marks. Any solution there? Perhaps I could make a manual list of the necessary punctuation marks and thus automatically increase the spacing around them? – O0123 Oct 02 '17 at 01:36
  • Additionally, using your solution, the ability to switch fonts mid-document using \newfontfamily\myfont{...} seems to have been lost, but that is of course easily fixed by adding a j to end up with \newjfontfamily\myfont{...}. – O0123 Oct 02 '17 at 02:13
  • But a big problem remains, which is the spacing around punctuation marks, which is currently unaffected by your change in tracking. One can clearly notice this by using a large value, e.g. \ltjsetparameter{kanjiskip=100pt}. I have asked a follow-up question here. – O0123 Oct 02 '17 at 02:58