# Slovak (and Czech) babel gives problems with cmidrule and cline

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

• Welcome to TeX.sx! I've taken the liberty of reformatting your question for greater clarity. – egreg May 2 '13 at 20:51
• slovak makes the - an active character. This has to be reversed for booktabs. (The same is true for the standard \cline.) – Qrrbrbirlbel May 2 '13 at 20:53

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}
\toks2=\expandafter{\@@@cmidrule[{#1}-{#2}]{#3}{#4}}%
}{}
\catcode-=\active
\edef\x{\gdef\unexpanded{\@cline#1-#2\@nil}{\the\toks0}}\x
\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.

The option slovak makes - an active character.

The macro \@@@cmidrule which is internally used by \cmidrule to split the argument 2-3 at the - is defined with an - of catcode 12 (the default).

The following code just re-defines \@@@cmidrule with an active -.

## Code

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

\begingroup
\makeatletter
\catcode\-=\active
\AtBeginDocument{
\def\@@@cmidrule[#1-#2]#3#4{\global\@cmidla#1\relax
\ifnum\@cmidla>0\global\let\@gtempa\@cmidrulea\else
\global\let\@gtempa\@cmidruleb\fi
\global\@cmidlb#2\relax
\global\@thisrulewidth=#3
\@setrulekerning{#4}
\ifnum\@lastruleclass=\z@\vskip \aboverulesep\fi
\ifnum0={\fi}\@gtempa
\noalign{\ifnum0=}\fi\futurenonspacelet\@tempa\@xcmidrule}
}
\endgroup
\begin{document}
\begin{tabular}{ccc}
A & B & C \\
\cmidrule{2-3}
A & B & C \\
\end{tabular}
\end{document}

• Thank you very much, you saved me a lot of time and energy. – Ivan May 2 '13 at 22:01

The czech ans slovak languages make hyphen active so it can be used as a macro allowing \splithyphens (i.e. repeating hyphen in a line-break) to work. If you do not need \splithyphens you can deactivate the hyphen by following:

\usepackage[english,slovak]{babel}
\AtBeginDocument{\shorthandoff{-}}


Later you can activate it again by using:

\shorthandon{-}


As others have said, the problem arises from using czech(or slovak) babel.

On some czech forum i found this fix:

\begin{table}
\catcode\-=12
\begin{tabular}{|c|c|c|}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{tabular}
\end{table}


it changes the category of the - character back to where it should be.

this change can be either done globally or only in tables.

• At last that was already mentioned by the other two answers .... Welcome to TeX.SE! – Mensch Jan 20 at 22:54