lvjr / tabularray

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

ltugboat class breaks tabularray alignment #348

Open CarLaTeX opened 1 year ago

CarLaTeX commented 1 year ago

This MWE works:

\documentclass[twocolumn]{article}
\usepackage{tabularray}

\begin{document}
\begin{tblr}{colspec={Q[r,t]Q[c,m]Q[l,b]}, hlines}
{The baseline is\\ at the top\\ (right aligned)} & 
{The baseline is\\ in the middle\\ (centered)} & 
{The baseline is\\ at the bottom\\ (left aligned)}\\ 
\end{tblr}
\end{document}

image1

If I change article into ltugboat, the first horizontal alignment is wrong:

\documentclass[final]{ltugboat} 
\usepackage{tabularray}

\begin{document}
\begin{tblr}{colspec={Q[r,t]Q[c,m]Q[l,b]}, hlines}
{The baseline is\\ at the top\\ (right aligned)} & 
{The baseline is\\ in the middle\\ (centered)} & 
{The baseline is\\ at the bottom\\ (left aligned)}\\ 
\end{tblr}
\end{document}

image2

Asked also on TopAnswers TeX: https://topanswers.xyz/tex?q=2217

samcarter commented 1 year ago

The problem seems to be that ltugboat.cls redefines \raggedright etc.

If one uses the original definitions from source2e, the alignment seems to work:

\documentclass[final]{ltugboat} 

\usepackage{tabularray}

\makeatletter
\RenewDocumentCommand\TblrAlignRight{}{%
\let\\\@centercr
  \rightskip\z@skip\leftskip\@flushglue
  \finalhyphendemerits=\z@
  \parindent\z@\parfillskip\z@skip}
\makeatother

\begin{document}
\begin{tblr}{colspec={Q[r,t]Q[c,m]Q[l,b]}, hlines}
{The baseline is\\ at the top\\ (right aligned)} & 
{The baseline is\\ in the middle\\ (centered)} & 
{The baseline is\\ at the bottom\\ (left aligned)}\\ 
\end{tblr}
\end{document}
Screenshot 2023-01-06 at 12 58 27
CarLaTeX commented 1 year ago

So it's a problem with the ltugboat class? Should I report to its maintainers?

samcarter commented 1 year ago

So it's a problem with the ltugboat class? Should I report to its maintainers?

Not sure, maybe tabularray just can't trust \raggedleft etc. to be defined the way it thinks they are?

FrankMittelbach commented 1 year ago

The two definitions of \raggedright in the format and in the TUB class are different but that's acceptable for a class to make changes here. All that \raggedright specifies is that a certain area of text should be set in ragged style but what that precisely means, eg with or without indentation etc is up to the class. So I would say it is an issue with tabuarray making the assumption that \raggedright is exactly as in the format.

lvjr commented 1 year ago

@FrankMittelbach It is easy to fix this in tabularray. But I am confused about when a package should or should not follow the changes (by a class, another package or a user) to public macros provided by LaTeX format.

For \raggedleft and its friends, we can see a traditional tabular is also affected by the changes in tugboat class, because we use >{\raggedleft\arraybackslash} to make right alignment for multiline cells.

As another example, if a package uses \emph, but other packages may modify the definition of it, should the package copy the original definition of \emph?

To me it is a little strange that a package should copy many definitions (which may contain lots of @ in them) of public macros provided by LaTeX format.

muzimuzhi commented 1 year ago

For \raggedleft and its friends, we can see a traditional tabular is also affected by the changes in tugboat class, because we use >{\raggedleft\arraybackslash} to make right alignment for multiline cells.

I can't get this. It seems \makecell used in a traditional tabular env behaves the same with latex2e or ltugboat \raggedleft. Did I miss sth?

\documentclass{article}
\usepackage{fvextra} % to use inline verb in macro argument
\usepackage{makecell}

\begin{document}
\let\raggedleftOrig=\raggedleft
\def\test{%
  \ifx\raggedleftOrig\raggedleft
    \EscVerb{article.cls \\raggedleft }
  \else
    \EscVerb{ltugboat.cls \\raggedleft}
  \fi
  \quad
  \begin{tabular}{|l|>{\raggedleft\arraybackslash}p{2cm}|}
    \hline
    auto-wrapping       & aaa aaa aaa b                  \\ \hline
    \Verb|\makecell|    & \makecell{aaa aaa aaa\\ b}     \\ \hline
    \Verb|\makecell[r]| & \makecell[r]{aaa aaa  aaa\\ b} \\ \hline
  \end{tabular}
  \medskip
}

\test

% emulate \raggedleft in ltugboat.cls
% c.f. https://github.com/TeXUsersGroup/tugboat/blob/trunk/latex/tugboat.dtx
\makeatletter
\def\nohyphens{\hyphenpenalty\@M\exhyphenpenalty\@M}
\newdimen\raggedskip    \raggedskip=\z@
\newdimen\raggedstretch \raggedstretch=5em    % ems of font set now (10pt)
\def\raggedspaces{\spaceskip=.3333em \relax \xspaceskip=.5em \relax }

\def\raggedleft{%
  \nohyphens
  \leftskip=\raggedskip\@plus\raggedstretch \raggedspaces
  \parfillskip=\z@skip
}
\makeatother

\test
\end{document}

image

lvjr commented 1 year ago

I can't get this. It seems \makecell used in a traditional tabular env behaves the same with latex2e or ltugboat \raggedleft. Did I miss sth?

There is no parbox in a \makecell because it is just a subtable. We need to compare different results of parboxes and p columns in tabular under different \raggedleft definitions.

CarLaTeX commented 1 year ago

The two definitions of \raggedright in the format and in the TUB class are different but that's acceptable for a class to make changes here. All that \raggedright specifies is that a certain area of text should be set in ragged style but what that precisely means, eg with or without indentation etc is up to the class. So I would say it is an issue with tabuarray making the assumption that \raggedright is exactly as in the format.

See what Ulrike wrote: https://topanswers.xyz/transcript?room=2263&id=146482#c146482:

the main problem seems to be that the ltugboat definition doesn’t redefine the end of line command, if I add

\AddToHook{cmd/raggedleft/before}{\let\\\@centercr}

it works (it is a mystery why only raggedleft is affected).

lvjr commented 1 year ago

See what Ulrike wrote: https://topanswers.xyz/transcript?room=2263&id=146482#c146482:

the main problem seems to be that the ltugboat definition doesn’t redefine the end of line command, if I add

\AddToHook{cmd/raggedleft/before}{\let\\\@centercr}

it works (it is a mystery why only raggedleft is affected).

Therefore it is mainly a bug of ltugboat class. Maybe @kberry would like to have a look at this issue.

CarLaTeX commented 1 year ago

Indeed I replied to him, hoping he'll see the message

kberry commented 1 year ago

I committed the fix (thanks much for finding it, would have taken me ages) and will send Carla the new ltugboat.cls. (I hope to make a release soon, but not today.) Thanks to all.

CarLaTeX commented 1 year ago

It works, thanks!