Re: [NTG-context] the difference between \def and \define

2013-04-16 Thread Hans Hagen

On 4/15/2013 4:21 PM, Wolfgang Schuster wrote:


Am 15.04.2013 um 16:12 schrieb Hans Hagen pra...@wxs.nl:


On 4/15/2013 4:07 PM, Marco Patzer wrote:


I don't think named parameters are possible with \define, but maybe
I'm mistaken.


just use suffix .mkvi or put % macros=mkvi at the top of your file


Marco tries to do something like

   \define[3]\Test{#one#two#three}

which doesn’t work.


hm, ok, do \define is not mkvi then ... too messy to catch that one too

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-
___
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
___


Re: [NTG-context] the difference between \def and \define

2013-04-16 Thread Marco Patzer
On 2013–04–16 Hans Hagen wrote:

 Marco tries to do something like
 
\define[3]\Test{#one#two#three}
 
 which doesn’t work.
 
 hm, ok, do \define is not mkvi then ... too messy to catch that one too

No need to bother with that. I was just pointing out the differences
between \def and \define for Tim. And named parameters is something
\define can't do. It doesn't make sense to use named parameters with
\define, since you explicitly pass the parameter *number* in
brackets. You cannot refer to a number by name. Well, you could
theoretically, but I'd strongly object.


Marco


signature.asc
Description: Digital signature
___
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
___

Re: [NTG-context] the difference between \def and \define

2013-04-16 Thread Thomas A. Schmitz

On 04/16/2013 11:05 AM, Marco Patzer wrote:

It doesn't make sense to use named parameters with
\define, since you explicitly pass the parameter*number*  in
brackets. You cannot refer to a number by name. Well, you could
theoretically, but I'd strongly object.


Just out of curiosity: why would you object? In Lua, we have the syntax

function whatever(one, two, three)
  do something with(one, two, three)
end

I'm not lobbying for define to have something similar, I just want to 
point out that it would be in the spirit of convergence between ConTeXt 
and Lua. It certainly isn't an urgent need, but having


\define[one,two,three]

wouldn't be absurd, now would it?

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


Re: [NTG-context] the difference between \def and \define

2013-04-16 Thread Marco Patzer
On 2013–04–16 Thomas A. Schmitz wrote:

 I'm not lobbying for define to have something similar, I just want
 to point out that it would be in the spirit of convergence between
 ConTeXt and Lua. It certainly isn't an urgent need, but having
 
 \define[one,two,three]
 
 wouldn't be absurd, now would it?

Sorry, misunderstanding on my part. That one looks fine. I thought
we're talking about translating the number to words, which wouldn't
make any sense:

  \define[3]\foo{#one, #two, #three}

I still don't think it's necessary to use named parameters with
\define. For modules most likely \def, \setvalue or texdefinition
are being used and \define for in-document markup, wherefore
numbered parameters are perfectly fine. The only thing that could be
improved is a definition which doesn't interfere with \asciimode,
but that's low priority and can easily be worked around.

Marco


signature.asc
Description: Digital signature
___
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
___

Re: [NTG-context] the difference between \def and \define

2013-04-16 Thread Hans Hagen

On 4/16/2013 11:10 AM, Thomas A. Schmitz wrote:

On 04/16/2013 11:05 AM, Marco Patzer wrote:

It doesn't make sense to use named parameters with
\define, since you explicitly pass the parameter*number*  in
brackets. You cannot refer to a number by name. Well, you could
theoretically, but I'd strongly object.


Just out of curiosity: why would you object? In Lua, we have the syntax

function whatever(one, two, three)
   do something with(one, two, three)
end

I'm not lobbying for define to have something similar, I just want to
point out that it would be in the spirit of convergence between ConTeXt
and Lua. It certainly isn't an urgent need, but having

\define[one,two,three]

wouldn't be absurd, now would it?


there is a commented blob that implements thinsg like this

\starttext
\define[2]\whatevera{#1+#2}
\whatevera{A}{B}
\define[me][too][2]\whateverb{#1+#2+#3+#4}
\whateverb[A]{B}{C}
\whateverb[A][B]{C}{D}
\define[alpha][beta][gamma][delta]\whateverc{#1+#2+#3+#4}
\whateverc[P][Q]
\stoptext

but it's just an old idea.

Hans


-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-
___
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
___


Re: [NTG-context] the difference between \def and \define

2013-04-16 Thread Alan BRASLAU
Since the question has been raised about understanding \define, etc.
indeed some use remains a bit unclear (to me).

On Tue, 16 Apr 2013 12:34:48 +0200
Hans Hagen pra...@wxs.nl wrote:

 there is a commented blob that implements thinsg like this
 
 \starttext
  \define[2]\whatevera{#1+#2}
  \whatevera{A}{B}
  \define[me][too][2]\whateverb{#1+#2+#3+#4}
  \whateverb[A]{B}{C}
  \whateverb[A][B]{C}{D}
  \define[alpha][beta][gamma][delta]\whateverc{#1+#2+#3+#4}
  \whateverc[P][Q]
 \stoptext
 
 but it's just an old idea.

I am perhaps a bit bewildered today... but I do not understand the
above. It gets too tricky for me!

In fact, I do not understand well the handling of arguments,
especially optional variants.
For example,
\define[1]\Index{\index{#1}#1}
can be handy. But let's say that I want to be able to use a variant:
\Index[alpha]{$\alpha$}
(\index[alpha]{$\alpha$}$\alpha$)

Or, maybe, I might like to handle authors:
\define[2]\Author{\index{#2, #1}#1 #2}
\Author{Thomas A.}{Schmitz}
But what if I were to type \Author{Aristotle}?

Alan

P.S. I indeed like the idea of the suggestion:

\define[one,two,three]\whatever{first: #one second: #two third: #three}

On 4/16/2013 11:10 AM, Thomas A. Schmitz wrote:
 It certainly isn't an urgent need, but having

 \define[one,two,three]

 wouldn't be absurd, now would it?
___
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
___


Re: [NTG-context] the difference between \def and \define

2013-04-16 Thread Hans Hagen

On 4/16/2013 1:14 PM, Alan BRASLAU wrote:

Since the question has been raised about understanding \define, etc.
indeed some use remains a bit unclear (to me).

On Tue, 16 Apr 2013 12:34:48 +0200
Hans Hagen pra...@wxs.nl wrote:


there is a commented blob that implements thinsg like this

\starttext
  \define[2]\whatevera{#1+#2}
  \whatevera{A}{B}
  \define[me][too][2]\whateverb{#1+#2+#3+#4}
  \whateverb[A]{B}{C}
  \whateverb[A][B]{C}{D}
  \define[alpha][beta][gamma][delta]\whateverc{#1+#2+#3+#4}
  \whateverc[P][Q]
\stoptext

but it's just an old idea.


I am perhaps a bit bewildered today... but I do not understand the
above. It gets too tricky for me!


that's why it's commented code -)

\define
  [optional-arg-1-default][optional-arg-2-default]...[number of {} args]

but .. not likely to become enabled anyway (was an experiment)


Or, maybe, I might like to handle authors:
\define[2]\Author{\index{#2, #1}#1 #2}
\Author{Thomas A.}{Schmitz}
But what if I were to type \Author{Aristotle}?


the [] are optional with an optional default


\define[one,two,three]\whatever{first: #one second: #two third: #three}


that's not too complex to implement (as mkvi) if there's enough votes 
for it



On 4/16/2013 11:10 AM, Thomas A. Schmitz wrote:

It certainly isn't an urgent need, but having

\define[one,two,three]

wouldn't be absurd, now would it?



--

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-
___
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
___


Re: [NTG-context] the difference between \def and \define

2013-04-16 Thread Hans Hagen

On 4/16/2013 12:11 PM, Marco Patzer wrote:

On 2013–04–16 Thomas A. Schmitz wrote:


I'm not lobbying for define to have something similar, I just want
to point out that it would be in the spirit of convergence between
ConTeXt and Lua. It certainly isn't an urgent need, but having

\define[one,two,three]

wouldn't be absurd, now would it?


Sorry, misunderstanding on my part. That one looks fine. I thought
we're talking about translating the number to words, which wouldn't
make any sense:

   \define[3]\foo{#one, #two, #three}

I still don't think it's necessary to use named parameters with
\define. For modules most likely \def, \setvalue or texdefinition
are being used and \define for in-document markup, wherefore
numbered parameters are perfectly fine. The only thing that could be
improved is a definition which doesn't interfere with \asciimode,
but that's low priority and can easily be worked around.


It's also messy (in parsing):

\define[#one,#two]\test{#one#two}

there we have to collect and move the test backwards. Also, names 
defeats the use of the one number becoming multiple #'s so it then close to


\define\test[#one,#two]{#one#two}

which is nearly

\def\test[#one,#two]{#one#two}

apart from the checking, so i decided to provide this:

\checked\def \whatevera#alpha#beta{#alpha + #beta}
\checked\edef\whatevera#alpha#beta{#beta + #alpha}

\unique \def \whateverb#alpha#beta{#alpha + #beta}
\unique \edef\whateverb#alpha#beta{#beta + #alpha}

\whatevera{1}{2}\par
\whateverb{1}{2}\par

(can be used with \def \edef \xdef \gdef \udef \uedef \uxdef and \ugdef)

Hans

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-
___
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
___


Re: [NTG-context] the difference between \def and \define

2013-04-15 Thread Wolfgang Schuster

Am 15.04.2013 um 15:47 schrieb Tim Li timli2...@outlook.com:

 In plain TeX, we always use \def for creating a new macro, but in ConTeXt, 
 sometimes it won't work, especially when making own chapter titles. The \def 
 can produce the error message like this : Argument of \... has an extra }. 
 \define in ConTeXt can solve this problem.
  
 What's the difference between \def and \define? Can I use \define to replace 
 all \def?

The \define command is a short form for \unexpanded\def which prevents commands 
to be expanded when used inside \edef or when passed to Lua.

Most of the high level commands are created to be unexpanded and expandable 
commands are used for internal functions.

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
___

Re: [NTG-context] the difference between \def and \define

2013-04-15 Thread Marco Patzer
On 2013–04–15 Tim Li wrote:

 What's the difference between \def and \define?

\define is basically the same as \unexpanded\def. It uses a slightly
different syntax for specifying optional arguments:

  \define[3]\foo{First: #1, Second: #2, Third: #3}
  \unexpanded\def\foo#1#2#3{First: #1, Second: #2, Third: #3}

Furthermore, \define displays a message if the command is already
defined:

  systemcommand '\foo' is already defined

However, ConTeXt happily overwrites the existing macro.

 Can I use \define to replace all \def?

There is \defineexpandable, which uses the same syntax as \define,
but it's a simple \def, without \unexpanded which is the closest
replacement.

I don't think named parameters are possible with \define, but maybe
I'm mistaken.

  \def\bar#first#second{First: #first, Second: #second}

For you information, there's also

  \starttexdefinition mycmd #1
…
  \stoptexdefinition

  \starttexdefinition mycmd $#first #second
…
  \stoptexdefinition


  \starttexdefinition unexpanded mycmd #first #second
…
  \stoptexdefinition


Marco


signature.asc
Description: Digital signature
___
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
___

Re: [NTG-context] the difference between \def and \define

2013-04-15 Thread Hans Hagen

On 4/15/2013 4:07 PM, Marco Patzer wrote:


I don't think named parameters are possible with \define, but maybe
I'm mistaken.


just use suffix .mkvi or put % macros=mkvi at the top of your file


-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-
___
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
___


Re: [NTG-context] the difference between \def and \define

2013-04-15 Thread Wolfgang Schuster

Am 15.04.2013 um 16:12 schrieb Hans Hagen pra...@wxs.nl:

 On 4/15/2013 4:07 PM, Marco Patzer wrote:
 
 I don't think named parameters are possible with \define, but maybe
 I'm mistaken.
 
 just use suffix .mkvi or put % macros=mkvi at the top of your file

Marco tries to do something like

  \define[3]\Test{#one#two#three}

which doesn’t work.

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
___


Re: [NTG-context] the difference between \def and \define

2013-04-15 Thread Marco Patzer
On 2013–04–15 Hans Hagen wrote:

 I don't think named parameters are possible with \define, but maybe
 I'm mistaken.
 
 just use suffix .mkvi or put % macros=mkvi at the top of your file

That's how to enable named parameters for \def. I was talking about
\define. The arguments are provided as a number in brackets, which
makes it hard to refer to them by name:

  %% fails, of course
  \define[2]\foo{#first, #second}

Marco


signature.asc
Description: Digital signature
___
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
___