2

I try do define a command \tes@define@key@length. Everything work but when I use the following line:

\expandafter\setlength\csname test@#1@length\endcsname{\csname testl@#1\endcsname}%

I get an error. Here an example where I comment the special line:

\setcounter{errorcontextlines}{999}
\RequirePackage{filecontents}
\begin{filecontents*}{testpaket.sty}
\RequirePackage{kvoptions}
\RequirePackage{etoolbox}
\SetupKeyvalOptions{family=test,prefix=test@}

\newlength{\tes@templength}
\def\test@defaultunit{pt}
\def\tes@iflength#1{%
  \afterassignment\tes@iflength@check%
  \tes@templength=#1\test@defaultunit\relax\relax
  \expandafter\endgroup\next
}
\def\tes@iflength@check#1{%
  \begingroup
  \ifx\relax#1\@empty
    \def\next{\@secondoftwo}
  \else
    \def\next{\@firstoftwo}
    \expandafter\tes@iflength@cleanup
  \fi
}
\def\tes@iflength@cleanup#1\relax{}


%#1 Bezeichnung Länge
%#2 Defaultwert Länge
\newrobustcmd*{\tes@optionlength}[2]{%
 \csxdef{test@#1}{#1 wurde definiert}
 \gdef\test@default{#2 ist der Defaultwert}
 \expandafter\newlength\csname test@#1@length\endcsname
 \expandafter\setlength\csname test@#1@length\endcsname{#2}%
}
%#1 option
\newrobustcmd*{\tes@define@key@length}[1]{%
  \define@key{test}{#1}{%
     \def\@tempa{##1}
     \tes@iflength{\@tempa}%
     {\csxdef{testl@#1}{\the\tes@templength}}%
     {\csxdef{testl@#1}{\the\tes@templength}}%
%    \expandafter\setlength\csname test@#1@length\endcsname{\csname testl@#1\endcsname}%
    }
}
\def\tes@define@key@@length{\define@key{mdf}}

\tes@define@key@length{skipabove}

\ProcessKeyvalOptions*

\end{filecontents*}
\documentclass{article}
\usepackage[skipabove=40pt]{testpaket}
\begin{document}
\makeatletter
\tes@iflength{12pt}{ja}{nein}
\tes@iflength{12}{ja}{nein}

\tes@optionlength{skipabove}{4pt}
\test@skipabove\
\test@default\

\the\test@skipabove@length

\advance\test@skipabove@length by 2pt

\the\test@skipabove@length

\testl@skipabove
\makeatother
\end{document}
5

\test@skipabove@length is not defined until you use \tes@optionlength{skipabove}{4pt}. But you use \tes@define@key@length{skipabove} without defining the length earlier.

BTW, you can simply use

\setlength{\csname test@#1@length\endcsname}{\csname testl@#1\endcsname}

without \expandafter.

  • thanks. Without expandafter is new for me. But the mistake is very bad – Marco Daniel Jun 11 '11 at 12:22
5

The error I see is that the length \test@#1@length is not yet defined when you try to set it up.

If I add \expandafter\show\csname test@#1@length\endcsname before the commented line, I get

> \test@skipabove@length=\relax
<recently read> \test@skipabove@length

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.