# Problem with xargs package

I am trying to do what I though was fairly simple - use an xargs defined macro in a CS. MWE:

\documentclass{article}
\usepackage{xargs}
\usepackage{etoolbox}
\makeatletter
\def\abx@foo@baz@bar{test}
\def\abx@field@original@default@test{baz}

\newcommandx*{\blx@imc@thefield}[3][1=original,2=default]{\csuse{abx@field@#1@#2@#3}}

\def\blx@getformat#1#2{%
\ifcsundef{abx@#1@\blx@imc@thefield{test}@#2}
{no}
{yes}}

\begin{document}
\blx@getformat{foo}{bar}
\makeatother
\end{document}


For me, this always gives:

! Missing \endcsname inserted.
<to be read again>
\begingroup
l.17 \blx@getformat{foo}{bar}



-

## 1 Answer

This cannot work, at least using xargs. Inside a \csname construct, everything has to be fully expandable or consist of tokens TeX will allow in a name (letters, numbers, spaces, \$, ...). However, detecting optional arguments does not work that way: there is a \futurelet involved, but here there is also a \begingroup.

It is possible to grab optional arguments in an expandable manner, subject to some restrictions. The xparse package provides one wrapper for this

\documentclass{article}
\usepackage{xparse}
\usepackage{etoolbox}
\makeatletter
\def\abx@foo@baz@bar{test}
\def\abx@field@original@default@test{baz}

\DeclareExpandableDocumentCommand{\blx@imc@thefield}
{O{original}O{default}m}
{\csuse{abx@field@#1@#2@#3}}

\def\blx@getformat#1#2{%
\ifcsundef{abx@#1@\blx@imc@thefield{test}@#2}
{no}
{yes}}

\begin{document}
\blx@getformat{foo}{bar}
\makeatother
\end{document}


(although this is not a document command!), while etextools also provides a similar concept. However, I'm not really sure I'd want to handle an internal macro is this way: I'd much prefer something with only mandatory arguments.

-
Ah, I see, thanks. I am just experimenting to see how to tackle some things that need doing (in a package I think you know ...). xparse looks rather powerful. What are your thoughts on using this package for biblatex? –  PLK Nov 15 '12 at 13:06