[XeTeX] newcommand with optional arguments

Diederick C. Niehorster diederick at niehorster.eu
Sun Nov 30 16:10:39 CET 2008

Sorry for bumping an old post and sorry for being slightly off-topic, but I have a follow-up question regarding the post below.

I have also been trying to find a way to use optional arguments as I wanted to write a \cite in the possessive form for natbib where I would sometimes want to include text between author and year -- and sometimes not ;).
This led me to an old thread started by Sven Siegmund, to which I now reply. Find his final macro at http://xelatex.blogspot.com/2008/03/newcommand-with-optional-argument.html

I have adopted this to the following for my purpose
\long\def\tlist at if@empty at nTF #1{%
  \citeauthor{#2}'s %
  \tlist at if@empty at nTF{#1}{}{#1 }% when false, code in third brace gets executed

This works great when I include it in the preamble of a tex-file directly. However, I have a .sty which I use to call packages I often use and set defaults the way I like it. Putting the above in my .sty gives me errors during parsing of the .sty.
The first error I get is a bunch of lines later (where line 103 is from my .sty):
! You can't use `\spacefactor' in vertical mode.
                 \@m {}
l.103 \@

Does somebody know where this seemingly unrelated (to the newly added code) error comes from? And how can I solve it?


> -----Original Message-----
> From: xetex-bounces at tug.org [mailto:xetex-bounces at tug.org] On Behalf Of Morten Høgholm
> Sent: Tue Mar 4 08:58:42 CET 2008
> Subject: Re: [XeTeX] newcommand with optional arguments
> On Mon, Mar 3, 2008 at 10:30 PM, Ross Moore <ross at ics.mq.edu.au> wrote:
> > A more bullet-proof approach is:
> *The* bulletproof (and purely expandable) method of testing whether an
> argument is empty is this:
> \long\def\tlist at if at empty at nTF #1{%
>   \expandafter\ifx\expandafter\\\detokenize{#1}\\%
>     \expandafter\@firstoftwo
>   \else
>     \expandafter\@secondoftwo
>   \fi
> }
> See l3tlp.dtx for details. It also contains a bullet-proof test for
> testing if an argument is blank.
> Just my 2 øre,
> -- 
> Morten

More information about the XeTeX mailing list