3

I'm having trouble with a "Bad math environment delimiter" when using certain math environments inside tabu. Minimal example:

\documentclass[a4paper,12pt]{scrreprt}

\usepackage{xcolor}
\usepackage{tabu}

\begin{document}
\begin{table}[h!]
  \begin{tabu}{ X } 
    \[ b \]
  \end{tabu}
\end{table}
\end{document}

This error only shows when xcolor is loaded and also appears when \[ is replaced with an equation, align, or gather environment, but not when using $$. The above example used to work a year ago and the error appeared recently after updating MikTex and all packages.

2
  • 2
    you should consider that tabu is not maintained, so it not respond on recent changes in many of packages. for example in array and it seems that in xcolor too.
    – Zarko
    Commented Jan 9, 2019 at 2:37
  • @Zarko I don't think any change in xcolor is responsible for this, it all comes from change in array.
    – user4686
    Commented Jan 9, 2019 at 13:36

1 Answer 1

5

UPDATE 2019-01-14

An equivalent patch has been applied in tabu 2.9 which has been submitted to ctan.


This is not a full solution, only a first try!!!

At some place in the code tabu checks the "current group type" (What combinations of mode and \currentgrouptype exist?).

The problem is that array added an additional "color group" to p-columns to avoid that colors leaks out. This color group is active if a color package is used. When tabu tests the current group type it now gets a different answer then previously and so takes the wrong code path.

One possibility to get around the problem is to save the currentgrouptype before the color group and to use this value in the tabu code.

Attention I suspect that more places will need adjustments.

\documentclass{article}

\usepackage{color,array,longtable}
%Save the currentgrouptype before the color@begingroup:
\makeatletter
\newcount\array@currentgrouptype
\def\@startpbox#1{\bgroup \array@currentgrouptype\currentgrouptype
  \color@begingroup
  \setlength\hsize{#1}\@arrayparboxrestore
   \everypar{%
      \vrule \@height \ht\@arstrutbox \@width \z@
      \everypar{}}%
   }
\makeatother

\usepackage{tabu}
\makeatletter
%Use the new \array@currentgrouptype
\def\tabu@verticalmeasure{\everypar{}%
    %\showthe\currentgrouptype %14 in tl18, 5 in tl17
    \ifnum \array@currentgrouptype>12         % 
        \setbox\tabu@box =\hbox\bgroup
            \let\tabu@verticalspacing \tabu@verticalsp@lcr
            \d@llarbegin                % after \hbox ...
    \else
         \edef\tabu@temp{\ifnum\array@currentgrouptype=5\vtop
                        \else\ifnum\array@currentgrouptype=12\vcenter
                        \else\vbox\fi\fi}%
        \setbox\tabu@box \hbox\bgroup$\tabu@temp \bgroup
            \let\tabu@verticalspacing \tabu@verticalsp@pmb
    \fi
}% \tabu@verticalmeasure

\usepackage{etoolbox}

\patchcmd\tabu@startpboxmeasure
  {\aftergroup\tabu@endpboxmeasure}
  {\aftergroup\tabu@endpboxmeasure 
   \color@begingroup
  }{\typeout{tabu patched}}{\typeout{tabu patch failed!}}

\patchcmd\tabu@LT@startpbox
 {\bgroup}{\bgroup\color@begingroup}
 {\typeout{tabu patched}}{\typeout{tabu patch failed!}}
\makeatletter


\begin{document}

\begin{tabu}{X}
  \[ b \]
\end{tabu}

\begin{longtabu}{X}
  \[ b \]
\end{longtabu}

\end{document}
1
  • just to link to another answer as you incorporate its patch which incorporates your longtable patch from yet another answer
    – user4686
    Commented Jan 9, 2019 at 13:35

You must log in to answer this question.

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