tabularray icon indicating copy to clipboard operation
tabularray copied to clipboard

Allow to evaluate all functions in the table body

Open lvjr opened this issue 3 years ago • 2 comments

Now that functional package has already had function \evalWhole for evaluating all functions defined with \prgNewFunction inside its argument (see https://github.com/lvjr/functional/issues/10), it is natural to add option evaluate=* in functional library, calling \evalWhole to evaluate all functions in the table body.

With \SetTblrOuter command, we can add option evaluate=* to the default settings of some tabularray environment, and use evaluate= to clear default evaluate setting later.

lvjr avatar May 28 '22 12:05 lvjr

But by design \evalWhole doesn't evaluate functions hiding in the return values of other functions. This may be a problem if we are using \fileInput in some inputted files. Maybe we need another option and another \evalRecursive function.

Update: now \evalWhole evaluates functions recursively (https://github.com/lvjr/functional/commit/7b38e45afff156f2f6facfdb48f4489d39fbd82b).

lvjr avatar May 28 '22 12:05 lvjr

It is more meaningful to use evaluate=all and evaluate=none (see https://github.com/lvjr/tabularray/wiki/KeyValue).

lvjr avatar Jun 25 '22 03:06 lvjr

Now we can use evaluate=all with functional library:

\documentclass{article}

\usepackage{../../tabularray}
\UseTblrLibrary{functional}

\IgnoreSpacesOn
\prgNewFunction \myFunA {} {
  \prgReturn { A & B \\ }
}
\prgNewFunction \myFunB {} {
  \prgReturn { C & D \\ }
}
\IgnoreSpacesOff

\begin{document}

\begin{tblr}[evaluate=\myFunA]{hlines}
  E & F \\
  \myFunA
  E & F \\
  \myFunA
  E & F \\
\end{tblr}
\qquad
\begin{tblr}[evaluate=all]{hlines}
  E & F \\
  \myFunA
  \myFunB
  E & F \\
  \myFunA
  \myFunB
  E & F \\
\end{tblr}

\end{document}

image

lvjr avatar Jan 01 '23 11:01 lvjr