# Conflicts with existing macro when using kvoptions: Undefined control sequence

I am trying to use kvoptions pacakage to allow passing key options to my style file. Here is a MWE of the style file:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{test}
\newcommand{\rtitle}{TITLE}
\RequirePackage{kvoptions}
\SetupKeyvalOptions{
family=EL,
prefix=EL@
}
\DeclareStringOption[TITLE]{rtitle}
\ProcessKeyvalOptions*

\ifx\EL@rtitle\@empty
\PackageWarningNoLine{\@currname}{Running title is not passed to rtitle'}
\else
\renewcommand{\rtitle}{\EL@rtitle}
\fi

\makeatletter
\def\@xfootnote[#1]{%
\protected@xdef\@thefnmark{#1}%
\@footnotemark\@footnotetext}
\makeatother

\RequirePackage{fancyhdr}
\fancyhf{}
\pagestyle{fancy}

\endinput


Here is the tex file:

\documentclass[11pt,letterpaper]{article}
\usepackage[rtitle = {A\ TEST\ TITLE}]{test}

\begin{document}
Some random text.\footnote[*]{Some footnote with a special marker.}
\end{document}


Here is the issue. I try to simplify the style file by directly using the macro generated by \DeclareStringOption and not using \newcommand{\rtitle}{TITLE}:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{test}

\RequirePackage{kvoptions}
\SetupKeyvalOptions{
family=EL,
prefix=EL@
}
\DeclareStringOption[TITLE]{rtitle}
\ProcessKeyvalOptions*

\ifx\EL@rtitle\@empty
\PackageWarningNoLine{\@currname}{Running title is not passed to rtitle'}
\fi

\makeatletter
\def\@xfootnote[#1]{%
\protected@xdef\@thefnmark{#1}%
\@footnotemark\@footnotetext}
\makeatother

\RequirePackage{fancyhdr}
\fancyhf{}
\pagestyle{fancy}

\endinput


After this modification of the style file, compiling the tex file gives an error message saying control sequence not defined.

What is wrong with directly using the macro EL@rtitle in the fancyheader?

Thanks!

Edit: I realized that there is a conflict with the macro

\makeatletter
\def\@xfootnote[#1]{%
\protected@xdef\@thefnmark{#1}%
\@footnotemark\@footnotetext}
\makeatother


If I remove this part, then everything works fine. But, how should I fix this macro (except changing the order)? I still need to use a footnote with special marker.

• Are you sure? Using your second package, I got no error and the .tex file compiled normally. Jul 19, 2018 at 2:53
• @RuixiZhang Thanks for pointing that out! I just realized that I should not remove the other macro I use which is the true source of issues. The post is updated now. Jul 19, 2018 at 5:08

The error in the second version of the package file arises because you issued a \makeatother after the footnote part, so the @ is not a valid for macro names and the command \fancyhead[L]{\EL@rtitle} is basically read as \fancyhead[L]{\EL @rtitle}. The ! Undefined control sequence is thrown by the \EL command which is not defined.

By default, in package files, the catcode of @ is "letter", so you don't need to use \makeatletter and \makeatother, so I think the best solution is to just remove them:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{test}

\RequirePackage{kvoptions}
\SetupKeyvalOptions{
family=EL,
prefix=EL@
}
\DeclareStringOption[TITLE]{rtitle}
\ProcessKeyvalOptions*

\ifx\EL@rtitle\@empty
\PackageWarningNoLine{\@currname}{Running title is not passed to rtitle'}
\fi

% \makeatletter
\def\@xfootnote[#1]{%
\protected@xdef\@thefnmark{#1}%
\@footnotemark\@footnotetext}
% \makeatother

\RequirePackage{fancyhdr}
\fancyhf{}
`