1

I get the following error in my .dtx file:

) (./test.dtx
! Undefined control sequence.
l.35 % \rowcolors
{1}{colorrow}{colorbody}

which I do not understand since xcolor and colortbl are loaded and all other xcolor commands work.

This is the code of the .dtx file for testing:

% \iffalse
%<*driver>
\ProvidesFile{test.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{test}
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{test}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
%
\RequirePackage{colortbl}
\RequirePackage{xcolor}
%
\listfiles
\begin{document}
  \DocInput{test.dtx}
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{test.dtx}
%
% \colorlet{colorbody}{white!100}
% \colorlet{colorsubhead}{gray!30}
% \colorlet{colorhead}{gray!25}
% \colorlet{colorrow}{gray!15.0}
%
% \rowcolors{1}{colorrow}{colorbody}
% \begin{tabular}{*{2}{p{0.45\textwidth}}}
%  content  & content \tabularnewline
%  content  & content \tabularnewline
%  content  & content \tabularnewline
% \end{tabular}
% 
% \StopEventually{}
% \clearpage
% \section{Implementation}
%
% \iffalse
%<*test.sty>
% \fi
%
% \subsection{Setup and packages}           
%
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesPackage{test}
%    \end{macrocode}
% 
%    \begin{macrocode}
\RequirePackage{array}
\RequirePackage{colortbl} 
\RequirePackage{xcolor}
%    \end{macrocode}
%
% \iffalse
%</test.sty>
% \fi
%
% \Finale
\endinput
Schweinebacke
  • 26,336
  • 1
    Read my comments in your previous question: http://tex.stackexchange.com/questions/35156/requirepackage-without-option-clashes-because-of-the-package-loading-order. You must use the [table]-Option when loading xcolor. – Ulrike Fischer Nov 18 '11 at 15:29

1 Answers1

6

You should replace

\RequirePackage{colortbl}
\RequirePackage{xcolor}

at line 16+17 by

\usepackage[table]{xcolor}

because package loading at the document preamble should be done using \usepackage instead of \RequirePackage, and at line 59+60 by

\RequirePackage[table]{xcolor}

because loading both packages on your own is not the same. Section 2.12, "Color in table", of xcolor manual recommends using the option because:

These commands require the table option.

"These commands" are \rowcolors, \rowcolors*, \showrowcolors, \hiderowcolors, and \rownum (which is not a command but a TeX counter).

Schweinebacke
  • 26,336
  • The reason why I load them separately is shown here: http://tex.stackexchange.com/questions/35156/requirepackage-without-option-clashes-because-of-the-package-loading-order. If I load the package with options I risk option clash problems. – Matthias Pospiech Nov 18 '11 at 18:28
  • Nevertheless it is better, that the user gets information about a problem instead of having a problem without information. I'd add something like \@ifpackageloaded{xcolor}{\@ifundefined{\rowcolors}{\PackageError{test}{xcolor must not be loaded before test without option table}{You've already …}}{}}{} before \RequirePackage[table]{xcolor} at test.sty, to give the user more information about the problem and to suggest a solution. – Schweinebacke Nov 19 '11 at 07:38
  • I do that already. – Matthias Pospiech Nov 19 '11 at 15:18