[NTG-context] prevent gobbling of spaces when omitting optional argument

Florian Wobbe Florian.Wobbe at awi.de
Sat Jan 29 15:57:12 CET 2011


>> Hi,
>> 
>> please consider the following minimal example:
>> 
>> \def\before{\dodoubleempty\dobefore}%
>> \def\dobefore[#1][#2]{before}
>> 
>> \starttext
>> \before[] after (should be: \before[]\ after without explicit \type{\ })\par
>> \before[]after\par
>> \before[][] after\par % this works
>> \before[][]after\par
>> \stoptext
>> 
>> How can I prevent gobbling the following space, when the second optional argument is not given (i.e. first line). The macro itself should not insert space if the command is followed by any other character (2nd and 4th line).
> 
> 
> What do you want to achieve, maybe there is already something available.

Wolfgang, thank you very much! Recursion is really an elegant way. I wanted a wrapper around \cite with the same functionality like natbib's \citep[][]{} and \citet[][]{}, which saves a lot of typing. Especially if you start writing a text and at a later point decide to have a citation in parenthesis instead of textual. And of cause, if you switch between both styles in the same text.

Following your example, I came up with this now:

\def\citep[#1]%
 {\strictdoifnextoptionalelse{\docitep[#1]}{\nocitep[#1]}}

\def\docitep[#1][#2]%
 {\strictdoifnextoptionalelse{\dodocitep[#1][#2]}{\nodocitep[#1][#2]}}

\def\dodocitep[#1][#2][#3]%
 {\cite[alternative=authoryears, left={(#1 }, extras={#2}][#3]}

\def\nodocitep[#1][#2]%
 {\cite[alternative=authoryears, extras={#1}][#2]}

\def\nocitep[#1]%
 {\cite[alternative=authoryears][#1]}

\setuppublications[state=start,refcommand=authoryear]
\setupbibtex[database=sample]

\starttext
\startlines
%\cite[hh2010a] % commenting this out does not work
\stoplines
\citep[, p.\ 1][hh2010a].\par
\citep[, p.\ 1][hh2010a] more text.\par
\citep[see][, p.\ 1][hh2010a].\par
\citep[see][][hh2010a] more text.\par
\startlines
\cite[hh2010a] % this is ok at the end
\stoplines
\stoptext

I noticed there is this error: using the first cite in \startlines...\stoplines does not work.

Florian



More information about the ntg-context mailing list