[Tex/LaTex] etoolbox ifblank error with xkeyval

etoolboxxkeyval

I am trying to create my first class, which is basically just my ordinary preamble with a set of options. These options are handled by xkeyval using the following syntax:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myclass}[2013/07/19]

\RequirePackage{xkeyval}

\DeclareOptionX{firstoption}[]{\newcommand\myclass@firstoption{#1}}
\DeclareOptionX{secondoption}[]{\newcommand\myclass@secondoption{#1}}

\presetkeys{myclass.cls}{}{firstoption, secondoption} %sets all keys to their default values
                                     %unless set by the user


\ProcessOptionsX\relax

\LoadClass{memoir}
\RequirePackage{etoolbox}

\title{\ifblank{\myclass@firstoption}{% check if firstoption is blank
                %do nothing
    }{%
        \myclass@firstoption: %
    }%
    \myclass@secondoption%
}

The last piece of code is supposed to output firstoption: secondoption if firstoption is not blank, but only secondoption in case of the opposite.

However, for strange reasons, the colon always appears, independently of whether or not firstoption is set.

Best Answer

The right test to use is \ifdefempty

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{gaussler}[2013/07/19]

\RequirePackage{xkeyval}

\def\myclass@firstoption{}
\def\myclass@secondoption{}

\DeclareOptionX{firstoption}[]{\def\myclass@firstoption{#1}}
\DeclareOptionX{secondoption}[]{\def\myclass@secondoption{#1}}


\ProcessOptionsX\relax

\LoadClass{memoir}
\RequirePackage{etoolbox}

\title{\ifdefempty{\myclass@firstoption}{% check if firstoption is blank
                %do nothing
    }{%
        \myclass@firstoption: %
    }%
    \myclass@secondoption
}
\endinput

\ifdefempty{⟨control sequence⟩}{⟨true⟩}{⟨false⟩}
Expands to ⟨true⟩ if the ⟨control sequence⟩ is defined and is a parameterless macro whose replacement text is empty, and to ⟨false⟩ otherwise. In contrast to \ifx, this test ignores the prefixes of the ⟨command⟩.