tabularray icon indicating copy to clipboard operation
tabularray copied to clipboard

Some font will cause line break in -

Open note286 opened this issue 2 years ago • 5 comments

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.

\documentclass{article}
\usepackage{xeCJK}
% \usepackage{fontspec}
\setmainfont{TeX Gyre Termes}
% \setmainfont{Latin Modern Roman}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{colspec={l},hlines,vlines}
W-ADAPT\cite{test}   \\
W{-}ADAPT\cite{test} \\
\end{tblr}
\begin{tabular}{|l|}
\hline
W-ADAPT\cite{test}   \\
\hline
W{-}ADAPT\cite{test} \\
\hline
\end{tabular}
\end{document}

image

If I change \setmainfont{TeX Gyre Termes} to \setmainfont{Latin Modern Roman}. All is normal.

image

But if I change it to \usepackage{fontspec} and \setmainfont{TeX Gyre Termes} without using xeCJK.

image

note286 avatar Mar 05 '23 08:03 note286

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.

lvjr avatar Mar 05 '23 10:03 lvjr

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.

note286 avatar Mar 05 '23 10:03 note286

Sorry, I can't answer these questions. Only people familiar with XeTeX source code could answer them (and fix this bug).

lvjr avatar Mar 05 '23 10:03 lvjr

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.

note286 avatar Mar 05 '23 10:03 note286

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.

jcrippen avatar May 17 '23 22:05 jcrippen