5

In Exercise 22.7 of TeXbook, a special table is created using \halign with templates:

\def\welshverb#1={{\bf#1} = }
\halign{\welshverb#\hfil\tabskip=1em plus 1em&
  \welshverb#\hfil&\welshverb#\hfil\tabskip=0pt\cr
  rydw i=I am& ydw i=am I& roeddwn i=I was\cr
  rwyt ti=thou art& wyt ti=art thou& roeddet ti=thou wast\cr
  mae e=he is& ydy e=is he& roedd e=he was\cr
  mae hi=she is& ydy hi=is she& roedd hi=she was\cr}

enter image description here What's the easiest way to reproduce this table in modern LaTeX fashion?

3 Answers 3

6

You can do even better, with an input syntax less crowded than Knuth's.

\documentclass{article}
\usepackage{collcell}

\ExplSyntaxOn
\NewDocumentCommand{\welshverb}{m}
 {
  \stephen_welshverb:w #1
 }
\cs_new:Npn \stephen_welshverb:w #1 =
 {
  \textbf{#1}\unskip\ =\ \ignorespaces
 }
\ExplSyntaxOff

\begin{document}

\begin{tabular}{@{} *{3}{>{\collectcell\welshverb}l<{\endcollectcell}} @{}}
  rydw i  = I am     & ydw i  = am I     & roeddwn i  = I was \\
  rwyt ti = thou art & wyt ti = art thou & roeddet ti = thou wast \\
  mae e   = he is    & ydy e  = is he    & roedd e    = he was \\
  mae hi  = she is   & ydy hi = is she   & roedd hi   = she was
\end{tabular}

\end{document}

enter image description here

2
  • Oh, a question on which my L3 code uses higher abstraction level than yours... :P
    – Skillmon
    Dec 1, 2023 at 8:40
  • Nice! I forgot the w type argument specifiers. :(
    – Stephen
    Dec 1, 2023 at 8:50
8

Here's a solution that preserves Knuth's definition of \welshverb, apart from the minor change from \bf to \bfseries.

enter image description here

\documentclass{article} % or some other suitable document class
\usepackage{array}
\def\welshverb#1={{\bfseries #1} = }

\begin{document}

\begin{tabular}{ *{3}{>{\welshverb}l} }
  rydw i=I am& ydw i=am I& roeddwn i=I was \\
  rwyt ti=thou art& wyt ti=art thou& roeddet ti=thou wast \\
  mae e=he is& ydy e=is he& roedd e=he was \\
  mae hi=she is& ydy hi=is she& roedd hi=she was 
\end{tabular}

\end{document} 
4
  • And how about the definition of \welshverb? Can we also change it? For those who don't read TeXbook, maybe they hardly know that we can use = as the delimiter of the parameter in this way.
    – Stephen
    Dec 1, 2023 at 8:29
  • 1
    @Stephen - You asked for "the easiest way" to port the plain-TeX code to LaTeX; I assumed there was a reason for why you didn't ask for "the most idiomatic way". Using \def in a "modern LaTeX" document is entirely legitimate. There's definitely nothing old-fashioned, let alone deprecated, about using \def.
    – Mico
    Dec 1, 2023 at 8:32
  • 2
    I for one prefer this solution with \def over the L3 approaches - I find it much more readable and intuitive.
    – Marijn
    Dec 2, 2023 at 14:16
  • @Marijn - Thanks!
    – Mico
    Dec 2, 2023 at 15:23
6

If you want to use some highlevel language for the task, you could use the collcell package for grabbing the entire cell contents, and use an l3 implementation to split on equals signs.

This allows to put optional spaces before and after the equals sign in the input without altering the output (with the plainTeX solution you'd get doubled spaces).

\documentclass{article} % or some other suitable document class
\usepackage{array}

\ExplSyntaxOn
\NewDocumentCommand\welshverbcell{m}
  {
    \tl_if_in:nnTF {#1} { = }
      {
        % implementation here assumes just one = is present at top level (else
        % everything after the second equals sign is lost)
        \seq_set_split:Nnn \l_tmpa_seq { = } {#1}
        \exp_args:Nee \welshverbformat
          { \seq_item:Nn \l_tmpa_seq 1 }
          { \seq_item:Nn \l_tmpa_seq 2 }
      }
      {#1} % ignore cells not containing an equals sign
  }
\ExplSyntaxOff

\NewDocumentCommand\welshverbformat { m m }
  {%
    \textbf{#1} = #2%
  }
\usepackage{collcell}

\begin{document}

\begin{tabular}{ *{3}{>{\collectcell\welshverbcell}l<{\endcollectcell}} }
  rydw i=I am& ydw i=am I& roeddwn i=I was \\
  rwyt ti=thou art& wyt ti=art thou& roeddet ti=thou wast \\
  mae e=he is& ydy e=is he& roedd e=he was \\
  mae hi=she is& ydy hi=is she& roedd hi=she was 
\end{tabular}

\end{document} 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .