tabularray icon indicating copy to clipboard operation
tabularray copied to clipboard

Support verbatim environments in the table

Open albert-github opened this issue 4 years ago • 12 comments

As far as I can see the environment:

\begin{tblr*}

does not yet work, any plans for this?

albert-github avatar May 31 '21 12:05 albert-github

Yes, there will be a tblr* environment in the near future.

lvjr avatar May 31 '21 13:05 lvjr

It is much more complicated than what I have thought to support verbatim code.

Because tabularray package collects the whole table body before typesetting the table, and some characters (e.g., comment chars, newline chars and mulitiple spaces) are discarded by TeX in this collecting process. Therefore I need to use the dangerous \catcode command before tblr environment, and it will probably break something.

@albert-github, could you provide some examples that you use, so that I can do some testing while implementing this feature?

lvjr avatar Jun 03 '21 00:06 lvjr

I don't have a direct example. I saw that in the doxygen manual the longtabu and longtabu* were used and when I did some tests with it I saw that tblr didn't have the tblr* environment (along wit the missing longtblr).

albert-github avatar Jun 03 '21 07:06 albert-github

Maybe you could provide a sample TeX file generated by doxygen? A link for it is also OK.

lvjr avatar Jun 14 '21 03:06 lvjr

Now we can use \verb command inside the table with verb option:

\begin{tblr}{verb}
  20 & 30 & \verb!Hello!40 \\
  50 & \verb!Hello!60 & 70 \\
\end{tblr}

image

lvjr avatar Jul 15 '21 02:07 lvjr

Since there is some fake \write behind \scantokens command we are using, an extra space character is added after every macro inside \verb, such as \verb!\cmd{arg}!. Need to fix this problem.

lvjr avatar Jul 15 '21 12:07 lvjr

The previous commit fixed the problem:

\begin{tblr}{hlines,verb}
  20 & 30 & \verb!\hello{world}!40 \\
  50 & \verb!\hello!60 & 70 \\
\end{tblr}

image

lvjr avatar Jul 17 '21 03:07 lvjr

Since tabularray need to split cells from table body before reading the cell contents, to make sure we will always get a correct table, we may need to force users to write verbatim environments in a specified way, such as:

\begin{tblr*}{ll}
Cell1
&
\begin{verbatim}
code1
\end{verbatim}
\\
\begin{verbatim}
code2
\end{verbatim}
&
Cell2
\\
\end{tblr*}

Update1: Or we can make user list the verbatim environments with verbatim={lstlisting,Verbatim} option for example.

Update2: Maybe we can provide a command \RegisterTblrVerbatim.

lvjr avatar Sep 16 '21 02:09 lvjr

The "matrix of nodes" part of TikZ has an "ampersand replacement" option that lets the user specify with which character (eg. \&) columns are specified instead of &, which then allows this character to be used inside of nodes. Maybe that would be a solution ?

Also, I agree with the aforementionned, an option to tell tblr what are the verbatim commands would be great, because one often uses packages and shorthands, not always the basic \verb.

An option to change the catcode of % would also be convenient.

ysalmon avatar Jan 29 '23 11:01 ysalmon

I would be interested in a tblr* / longtblr* not appearing in the list-of-tables, too.

SteffenMeinecke avatar Oct 27 '23 15:10 SteffenMeinecke

What's the expected semantics of tblr* environment?

  • tabular* from the LaTeX2e kernel accepts an extra mandatory argument width.
  • tabu* from tabu library re-tokenizes the table content (by using \scantokens).

Issue author didn't give a precise description, though most part of discussion in this issue is about the re-tokenization purpose, but https://github.com/lvjr/tabularray/issues/13#issuecomment-1783110707 talked about a third semantic: caption=text,entry=none.

muzimuzhi avatar Feb 22 '24 01:02 muzimuzhi

I have edited the title.

lvjr avatar Feb 22 '24 01:02 lvjr