lvjr / tabularray

Typeset tabulars and arrays with LaTeX3
https://ctan.org/pkg/tabularray
247 stars 22 forks source link

Some font will cause line break in - #377

Open note286 opened 1 year ago

note286 commented 1 year ago

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

lvjr commented 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.

note286 commented 1 year ago

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.

lvjr commented 1 year ago

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

note286 commented 1 year ago

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.

jcrippen commented 1 year ago

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.