1

I was using soul to underline text. It works until I tried to underline some CJK text.

When I have

\def \mytest {测试test very long text blah blah blah ...}
\ul\mytest

in the document, it complains: Package soul Error: Reconstruction failed.

I also tried \CJKunderline. But it does not auto-wrap for this long text.

jiewuza
  • 275
  • There is https://ctan.org/pkg/soulutf8, which might help (I didn't test). Do you use pdfLaTeX, LuaLaTeX or XeLaTeX? But as always: Underlining is hard in TeX and soul as well as ulem have restrictions in what their underlining macros can accept as input. It may well be that neither can accept CJK characters without exploding. You already know about Paul Isambert's LuaLaTeX underlining code that should work here (again I didn't test), but of course requires LuaLaTeX (https://tex.stackexchange.com/q/435962/35864). – moewe Nov 27 '18 at 07:21
  • I tried soulutf8, with XeLaTeX. And It does not help. But thank you for your suggestion. – jiewuza Nov 28 '18 at 09:53

1 Answers1

1

Run the document with xelatex or lualatex:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Noto Sans CJK JP}
\usepackage{soul}
\begin{document}
\def \mytest {测试test very long text blah blah blah ...}
\ul\mytest
\end{document}

enter image description here

  • I have \usepackage{xeCJK} after \usepackage{fontspec}, and the same complain remains. – jiewuza Nov 28 '18 at 09:51
  • I checked the document of xeCJK. It uses fontspec inside. I doubt soul is not compatible with xeCJK. – jiewuza Nov 28 '18 at 10:12
  • yes, seems so. It is the way how xeCJK redefines character setting –  Nov 28 '18 at 10:23
  • Well, I guess I cannot get rid of xeCJK. I use it to set font. – jiewuza Nov 28 '18 at 10:48
  • fontsetting can also be done with fontspec. But I am not an CJK expert ... –  Nov 28 '18 at 11:15
  • Yes, but xeCJK provides \setCJKmainfont, \setCJKfamilyfont etc. I can set/change font for CJK text only. I don't if fontspec can and how to do it. – jiewuza Nov 28 '18 at 13:49
  • You can define a font family, eg \newfontfamily\NotoJP{Noto Sans CJK JP} and using this font with {\Noto .... some text ....} –  Nov 28 '18 at 19:52
  • Yes. But I can set main font for CJK and non-CJK independently with xeCJK. As CJK and non-CJK text are likely mixed together in a document, I have to change font for them now and then without xeCJK. It seems not a good way. – jiewuza Nov 29 '18 at 09:30