Open note286 opened 1 year ago
It is a XeTeX bug (see #16), and LuaTeX produces correct result with the same example:
\documentclass{article}
\usepackage{fontspec}
\setmainfont{TeX Gyre Termes}
\parindent=0pt
\begin{document}
\def\mytext{W-ADAPT[?]}
\setbox0=\hbox{\mytext}
\setbox2=\vbox{\hsize=\wd0 \mytext} \box2
\setbox2=\vbox{\hsize=\wd0 \raggedright \mytext} \box2
\setbox2=\vbox{\hsize=\wd0 \centering \mytext} \box2
\setbox2=\vbox{\hsize=\wd0 \raggedleft \mytext} \box2
\end{document}
But it seems the workaround in #16 doesn't work for this case.
Thank you for your answer, I have a certain understanding of it. But I am still curious why there are differences between different fonts? What factors of different fonts lead to this situation? I stumbled upon this issue by chance, and when I tried modifying some characters, the problem disappeared, which is really puzzling.
Sorry, I can't answer these questions. Only people familiar with XeTeX source code could answer them (and fix this bug).
I have found a solution in https://tex.stackexchange.com/a/600042/238422, and I can deal with this problem again. Thank you very much for your answer.
A hack I came up with was to wrap cells in an mbox
. For example this style specification
row{1} = {font=\itshape, cmd=\mbox}
causes every cell on row 1 to be wrapped in an mbox, thus suppressing hyphen breaking for any hyphens on row 1. Alternatively, cmd = \exhyphenpenalty10000
also works, at least until the bug is fixed.
If using
xeCJK
and\setmainfont{TeX Gyre Termes}
,{-}
is right, but-
will cause breakline. I found some in #257 and #145, but the situation is not quite the same.If I change
\setmainfont{TeX Gyre Termes}
to\setmainfont{Latin Modern Roman}
. All is normal.But if I change it to
\usepackage{fontspec}
and\setmainfont{TeX Gyre Termes}
without usingxeCJK
.