ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Florian Wobbe <Florian.Wobbe@awi.de>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: prevent gobbling of spaces when omitting optional argument
Date: Sat, 29 Jan 2011 15:57:12 +0100	[thread overview]
Message-ID: <EBEA59C0-F243-4C98-8BB9-D2421CCCBAFF@awi.de> (raw)
In-Reply-To: <85DA6141-2F92-4865-A872-AF951E8D876C@gmail.com>

>> 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

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


  reply	other threads:[~2011-01-29 14:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-28 22:24 Florian Wobbe
2011-01-29  8:51 ` Wolfgang Schuster
2011-01-29 14:57   ` Florian Wobbe [this message]
2011-01-29 16:21   ` Florian Wobbe
2011-01-29 17:09     ` Philipp Gesang
2011-01-29 17:20       ` Florian Wobbe
2011-02-01 12:27 ` Wolfgang Schuster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=EBEA59C0-F243-4C98-8BB9-D2421CCCBAFF@awi.de \
    --to=florian.wobbe@awi.de \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).