Not a completely automatic solution, but to reproduce the distance,
- add a strut of
\baselineskip on each row (normally array environment does automatically if \arraystretch is 1, and \baselineskip is equal to \normalbaselineskip; nevertheless we want some adjustment in row distance we will do this manually -- see note below)
- then, the distance is
\jot if the lines are "not tall" (in particular if the internal boxes doesn't touch each other), or \jot+\lineskip otherwise.
In this particular case it can be reproduced by:
%! TEX program = lualatex
\documentclass{article}
\usepackage{prettytok} % ← alternatively comment this out and replace \pretty:x with \tl_show:x. This is just for debug printing
\usepackage{amsmath}
\usepackage{zref-savepos}
\begin{document}
%\def\texta{\dfrac22}
\def\texta{a=b}
\def\textb{\dfrac22}
%\def\textb{a=b}
\begin{gather}
\texta \zsavepos{a1} \
\textb \zsavepos{b1}
\end{gather}
[
\edef\oldlineskip{\the\lineskip}
\def\arraystretch{0}
\begin{array}{c}
\texta \zsavepos{c1} \strut
\[0pt]\[\dimexpr\jot+\oldlineskip\relax]
%\[0pt]\[\jot]
\textb \zsavepos{d1} \strut
\end{array}
]
\ExplSyntaxOn
\pretty:x{
\int_eval:n{\zposy{a1} - \zposy{b1}}sp
=
\int_eval:n{\zposy{c1} - \zposy{d1}}sp
}
\ExplSyntaxOff
\end{document}
(you need \oldlineskip because \lineskip is set to 0 in array environments. Alternatively just hard code the default value of \lineskip, which is 3pt, in.)
The zref-savepos proves that the vertical length are equal.
Nevertheless if the \textb is a=b instead, the vertical boxes doesn't "touch" each other and you need
the second version (\\[\jot]) to get the same spacing.
Note: Struts does not always correctly reproduce TeX's behavior to space the baseline -- for example,
I think if in an align environment both rows has height=0 and depth=0.5\baselineskip then the baselineskip
will be exactly \baselineskip; nevertheless if the strut is added the height of the row below becomes 0.7\baselineskip
and the distance will be something like 1.2\baselineskip+\lineskip instead?
To determine it automatically... I think there are two ways
you need to put the content into two boxes, then take the \dp of the row above and the \ht of the row below,
add them together and compare with \baselineskip.
alternatively, use the zref-savepos itself and check if the two lines are \baselineskip apart, in that case add \lineskip.
Example (this may require up to 3 compilation passes however, or maybe 4 in some cases...?)
Make sure you understand what the code does and modify it accordingly. You'll get into trouble if the reference names/auxiliary macro name conflict etc.
%! TEX program = lualatex
\documentclass{article}
\usepackage{prettytok} % ← alternatively comment this out and replace \pretty:x with \tl_show:x. This is just for debug printing
\usepackage{amsmath}
\usepackage{zref-savepos}
\begin{document}
%\def\texta{\dfrac22}
\def\texta{a=b}
%\def\textb{\dfrac22}
\def\textb{a=b}
\begin{gather}
\texta \zsavepos{a1} \
\textb \zsavepos{b1}
\end{gather}
% if this is first run \extradistance will be undefined
\ifx\extradistance\relax
\gdef\extradistance{0pt}
\fi
% then compute extradistance
\ifdim
\dimexpr \zposy{c1}sp - \zposy{d1}sp \relax
=
\dimexpr \extradistance+\baselineskip \relax
% the rows appears to be short, don't need add \lineskip
\xdef\extradistance{\the\dimexpr\jot\relax} % \jot is probably not an internal dimen but just in case
\else
% otherwise, add \lineskip
\xdef\extradistance{\the\dimexpr\jot+\lineskip\relax}
\fi
\makeatletter
% store the extradistance to aux file
\write@auxout{\gdef\noexpand\extradistance{\extradistance}}
\makeatother
[
\def\arraystretch{0}
\begin{array}{c}
\texta \zsavepos{c1} \strut
\[0pt]\[\extradistance]
\textb \zsavepos{d1} \strut
\end{array}
]
\ExplSyntaxOn
\pretty:x{
\int_eval:n{\zposy{a1} - \zposy{b1}}sp
=
\int_eval:n{\zposy{c1} - \zposy{d1}}sp
}
\pretty:x{
\dim_to_decimal_in_sp:n {\jot+\baselineskip}sp
}
\ExplSyntaxOff
\end{document}
See also https://tex.stackexchange.com/a/95915/250119.
\\[<length>]doesn't always give the space between rows; you need\noalign{\vspace{<lenght>}. See https://tex.stackexchange.com/questions/180099/vertical-spacing-in-tabular-with-bmatrix – L.J.R. Jun 01 '22 at 08:44\\\noalign{\vspace{<lenght>}works fine in a minimal example on my computer. I think you need to minimalize your tex file and test it again. – L.J.R. Jun 01 '22 at 08:53\usepackage{amsmath}since the code does not compile without it. – frabjous Jun 01 '22 at 16:32\baselineskip=0pt\relax \lineskip=0pt\relax \def\jot{0pt} \savebox\strutbox {}. No idea what it does though. – user202729 Jun 05 '22 at 09:17\jotis a dimension allocated by\newdimen, so you should use\setlength, instead of\def, to sets its value. – muzimuzhi Z Jun 06 '22 at 20:05arraycode from my MWE? – antshar Jun 11 '22 at 14:06arrayas in amsmath environments, using expression with baselineskip/lineskip/jot/strutbox, it will satisfy me. I spent more than a couple of hours looking into the source code and I know how deep it's hidden somewhere, so I think I'll be fine even without a source code proof, because the actual goal is to achieve the precise spacing inarraythat would be the same as in amsmath environments. – antshar Jun 11 '22 at 15:38\jotor\jot+lineskip(add the size of the tags into account) depends on whether the content are tall enough to touch each other (recall that TeX automatically addslineskipdistance whenever the distance between two adjacent vbox are ≤lineskiplimit= 0pt by default), butarrayenvironment does not use lineskip so it would be a bit difficult to reimplement it. The alternative is to use the underlying TeX primitive (halign) and not use thearrayenvironment, might be easier. – user202729 Jun 12 '22 at 15:25alignenvironment family, wouldn't that be sufficient? (you don't really need to usearray) – user202729 Jun 12 '22 at 15:37*{n}{cols},@{},>{},<{}nor vertical lines|. – antshar Jun 12 '22 at 16:06@mkpream(which parses the preamble) which uses low level API but is in my opinion still easier than emulating it witharray. – user202729 Jun 13 '22 at 00:14lineskipwill break the|anyway. https://tex.stackexchange.com/questions/374524/can-i-set-lineskiplimit-in-tabular – user202729 Jun 13 '22 at 00:44