ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* prevent gobbling of spaces when omitting optional argument
@ 2011-01-28 22:24 Florian Wobbe
  2011-01-29  8:51 ` Wolfgang Schuster
  2011-02-01 12:27 ` Wolfgang Schuster
  0 siblings, 2 replies; 7+ messages in thread
From: Florian Wobbe @ 2011-01-28 22:24 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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

Thanks,
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: prevent gobbling of spaces when omitting optional argument
  2011-01-28 22:24 prevent gobbling of spaces when omitting optional argument Florian Wobbe
@ 2011-01-29  8:51 ` Wolfgang Schuster
  2011-01-29 14:57   ` Florian Wobbe
  2011-01-29 16:21   ` Florian Wobbe
  2011-02-01 12:27 ` Wolfgang Schuster
  1 sibling, 2 replies; 7+ messages in thread
From: Wolfgang Schuster @ 2011-01-29  8:51 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 28.01.2011 um 23:24 schrieb Florian Wobbe:

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

% \one, \one[…] and \one[…][…] (no spaces between “[][]” allowed)

\def\one
  {\strictdoifnextoptionalelse\doone\noone}

\def\noone{[]}

\def\doone[#1]%
  {\strictdoifnextoptionalelse{\dodoone[#1]}{\nodoone[#1]}}

\def\dodoone[#1][#2]%
  {[#1:#2]}

\def\nodoone[#1]%
  {[#1]}

% \two, \two{…} and \two{…} (no spaces between “{}{}” allowed)

\def\two
  {\dodoublegroupempty\dotwo}

\def\dotwo#1#2%
  {\ifsecondargument
     [#1:#2]%
   \else\iffirstargument
     [#1]%
   \else
     []%
   \fi\fi}

\starttext
\startlines
\one text
\one[1] text
\one[1][2] text
\two text
\two{1} text
\two{1}{2} text
\stoplines
\stoptext

Wolfgang

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: prevent gobbling of spaces when omitting optional argument
  2011-01-29  8:51 ` Wolfgang Schuster
@ 2011-01-29 14:57   ` Florian Wobbe
  2011-01-29 16:21   ` Florian Wobbe
  1 sibling, 0 replies; 7+ messages in thread
From: Florian Wobbe @ 2011-01-29 14:57 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: prevent gobbling of spaces when omitting optional argument
  2011-01-29  8:51 ` Wolfgang Schuster
  2011-01-29 14:57   ` Florian Wobbe
@ 2011-01-29 16:21   ` Florian Wobbe
  2011-01-29 17:09     ` Philipp Gesang
  1 sibling, 1 reply; 7+ messages in thread
From: Florian Wobbe @ 2011-01-29 16:21 UTC (permalink / raw)
  To: mailing list for ConTeXt users

> % \one, \one[…] and \one[…][…] (no spaces between “[][]” allowed)
> 
> \def\one
>  {\strictdoifnextoptionalelse\doone\noone}
> 
> \def\noone{[]}
> 
> \def\doone[#1]%
>  {\strictdoifnextoptionalelse{\dodoone[#1]}{\nodoone[#1]}}
> 
> \def\dodoone[#1][#2]%
>  {[#1:#2]}
> 
> \def\nodoone[#1]%
>  {[#1]}

One more problem: Adding

\setupinteraction[state=start]

> \starttext

and\footnote{\one[1]} etc. do not work. Why not?
Florian

> \startlines
> \one text
> \one[1] text
> \one[1][2] text
> \stoplines
> \stoptext

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: prevent gobbling of spaces when omitting optional argument
  2011-01-29 16:21   ` Florian Wobbe
@ 2011-01-29 17:09     ` Philipp Gesang
  2011-01-29 17:20       ` Florian Wobbe
  0 siblings, 1 reply; 7+ messages in thread
From: Philipp Gesang @ 2011-01-29 17:09 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1385 bytes --]

Hi Florian!

On 2011-01-29 <17:21:26>, Florian Wobbe wrote:
> > % \one, \one[…] and \one[…][…] (no spaces between “[][]” allowed)
> > 
> > \def\one

\unexpanded\def\one % should make it work in footnotes

Philipp

> >  {\strictdoifnextoptionalelse\doone\noone}
> > 
> > \def\noone{[]}
> > 
> > \def\doone[#1]%
> >  {\strictdoifnextoptionalelse{\dodoone[#1]}{\nodoone[#1]}}
> > 
> > \def\dodoone[#1][#2]%
> >  {[#1:#2]}
> > 
> > \def\nodoone[#1]%
> >  {[#1]}
> 
> One more problem: Adding
> 
> \setupinteraction[state=start]
> 
> > \starttext
> 
> and\footnote{\one[1]} etc. do not work. Why not?
> Florian
> 
> > \startlines
> > \one text
> > \one[1] text
> > \one[1][2] text
> > \stoplines
> > \stoptext
> 
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________

-- 
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments

[-- Attachment #1.2: Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 486 bytes --]

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: prevent gobbling of spaces when omitting optional argument
  2011-01-29 17:09     ` Philipp Gesang
@ 2011-01-29 17:20       ` Florian Wobbe
  0 siblings, 0 replies; 7+ messages in thread
From: Florian Wobbe @ 2011-01-29 17:20 UTC (permalink / raw)
  To: mailing list for ConTeXt users

> \unexpanded\def\one % should make it work in footnotes

Great, that did the trick. Thanks!
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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: prevent gobbling of spaces when omitting optional argument
  2011-01-28 22:24 prevent gobbling of spaces when omitting optional argument Florian Wobbe
  2011-01-29  8:51 ` Wolfgang Schuster
@ 2011-02-01 12:27 ` Wolfgang Schuster
  1 sibling, 0 replies; 7+ messages in thread
From: Wolfgang Schuster @ 2011-02-01 12:27 UTC (permalink / raw)
  To: Florian Wobbe; +Cc: mailing list for ConTeXt users


Am 28.01.2011 um 23:24 schrieb Florian Wobbe:

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

With the last beta this does no longer happen and the space after the missing arguments remains.

Wolfgang

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-02-01 12:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-28 22:24 prevent gobbling of spaces when omitting optional argument Florian Wobbe
2011-01-29  8:51 ` Wolfgang Schuster
2011-01-29 14:57   ` Florian Wobbe
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

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