[Tex/LaTex] Slovak (and Czech) babel gives problems with cmidrule and cline

babelbooktabs

I tried to use the Slovak language with the booktabs package.

Let's see a couple of cases.

  1. slovak is included in the options to babel

    \usepackage[english,slovak]{babel}
    

    or

    \usepackage[slovak,english]{babel}
    

    or

    \usepackage[slovak]{babel}`
    
  2. "slovak" is NOT included in the options to babel

    \usepackage[english]{babel}
    

Similarly two cases for \cmidrule

A. \cmidrule{2-3} is included in the table

B. \cmidrule{2-3} is NOT included in the table

If both (slovak+\cmidrule) are included (case 1A), then following error occurrs

Paragraph ended before \@@@cmidrule was complete

(and a lot of other errors)

In the other cases (1B, 2A and 2B) (NO slovak or NO \cmidrule), then pdflatex is succesful

Does anybody know why 1A is wrong?

And how to use slovak and \cmidrule together (case 1A)?

\documentclass[10pt]{book}
\usepackage[english,slovak]{babel}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{ccc}
A & B & C \\
%\cmidrule{2-3}
A & B & C \\
\end{tabular}

\end{document}

I have Win7, TeXstudio 2.5.2

Best Answer

The slovak (and also czech) module for babel not only breaks \cmidrule, but also the kernel command \cline (and possibly many others).

Since the active - is used for hyphenation, its role shouldn't be important in tables. The following hack seems to fix things:

\documentclass[10pt]{book}
\usepackage[english,slovak]{babel}
\usepackage{booktabs}

\usepackage{etoolbox}
\preto\tabular{\shorthandoff{-}}

\begin{document}

\begin{tabular}{ccc}
A & B & C \\
\cmidrule{2-3}
A & B & C \\
\cline{1-2}
A & B & C \\
\end{tabular}

\end{document}

A less invasive hack is to change the delimiter in the definition of \@@@cmidrule and of \@cline:

\documentclass[10pt]{book}
\usepackage[english,slovak]{babel}
\usepackage{booktabs}

\usepackage{regexpatch}
\makeatletter
% Change the `-` delimiter to an active character
\xpatchparametertext\@@@cmidrule{-}{\cA-}{}{}
\xpatchparametertext\@cline{-}{\cA-}{}{}
\makeatother

\begin{document}

\begin{tabular}{ccc}
A & B & C \\
\cmidrule{2-3}
A & B & C \\
\cline{1-2}
A & B & C \\
\end{tabular}

\end{document}

A package-free version (it could be made to work also without \unexpanded):

\documentclass{article}
\usepackage[slovak]{babel}
\usepackage{booktabs}

\makeatletter
\begingroup
\toks0=\expandafter{\@cline{#1}-{#2}\@nil}
\@ifpackageloaded{booktabs}{%
  \toks2=\expandafter{\@@@cmidrule[{#1}-{#2}]{#3}{#4}}%
}{}
\catcode`-=\active
\edef\x{\gdef\unexpanded{\@cline#1-#2\@nil}{\the\toks0}}\x
\@ifpackageloaded{booktabs}{%
  \edef\x{\gdef\unexpanded{\@@@cmidrule[#1-#2]#3#4}{\the\toks2}}\x
}{}
\endgroup
\makeatother

\begin{document}

\begin{tabular}{ccc}
A & B & C \\
\cmidrule{2-3}
A & B & C \\
\cline{1-2}
A & B & C \\
\end{tabular}

\end{document}

The patch is independent of the loading of booktabs, but of course it must be placed after it.