ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Characters allowed in macro names
@ 2018-04-22 15:23 N. Raghavendra
  2018-04-22 16:04 ` Hans Hagen
  2018-04-22 18:08 ` Wolfgang Schuster
  0 siblings, 2 replies; 5+ messages in thread
From: N. Raghavendra @ 2018-04-22 15:23 UTC (permalink / raw)
  To: ntg-context

I was wondering if it is alright to use underscores in the names of
macros, e.g, as in the following file.  It looks like \startsetups, and
\def accept names with hyphens, underscores, and numerals, but
\starttexdefinition doesn't tolerate any of them.

1. In general, what characters are allowed in macro names?  Are Unicode
   characters admissible?

2. Apart from the fact that one can use whitespace freely in
   \starttexdefinition, is there any reason to prefer it over \def?

Thanks,
Raghu.

------------------------------------------------------------
\starttext

\startsetups [hello-world_1]
  Hello, world 1!
\stopsetups

\setups [hello-world_1]

\def\hello-world_2{Hello, world 2!}

\hello-world_2

\starttexdefinition helloWorld
  Hello, world!
\stoptexdefinition

\helloWorld

%% Doesn't work
%% \starttexdefinition fooBar1
%%   Foo, bar 1!
%% \stoptexdefinition
%%
%% \fooBar1

%% Doesn't work
%% \starttexdefinition foo_bar
%%   Foo, bar!
%% \stoptexdefinition
%%
%% \foo_bar

%% Doesn't work
%% \starttexdefinition foo-bar
%%   Foo, bar!
%% \stoptexdefinition
%%
%% \foo-bar

\stoptext
------------------------------------------------------------
--
N. Raghavendra <raghu@hri.res.in>, http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Characters allowed in macro names
  2018-04-22 15:23 Characters allowed in macro names N. Raghavendra
@ 2018-04-22 16:04 ` Hans Hagen
  2018-04-22 18:19   ` N. Raghavendra
  2018-04-22 18:08 ` Wolfgang Schuster
  1 sibling, 1 reply; 5+ messages in thread
From: Hans Hagen @ 2018-04-22 16:04 UTC (permalink / raw)
  To: ntg-context

On 4/22/2018 5:23 PM, N. Raghavendra wrote:
> I was wondering if it is alright to use underscores in the names of
> macros, e.g, as in the following file.  It looks like \startsetups, and
> \def accept names with hyphens, underscores, and numerals, but
> \starttexdefinition doesn't tolerate any of them.
> 
> 1. In general, what characters are allowed in macro names?  Are Unicode
>     characters admissible?

letters are (and _ is not a letter, unless we're in unprotected mode)

> 2. Apart from the fact that one can use whitespace freely in
>     \starttexdefinition, is there any reason to prefer it over \def?

depends ... sometimes more readble ... spaces are ignores ... you can 
use named parameters

> Thanks,
> Raghu.
> 
> ------------------------------------------------------------
> \starttext
> 
> \startsetups [hello-world_1]
>    Hello, world 1!
> \stopsetups
> 
> \setups [hello-world_1]
> 
> \def\hello-world_2{Hello, world 2!}
> 
> \hello-world_2
> 
> \starttexdefinition helloWorld
>    Hello, world!
> \stoptexdefinition
> 
> \helloWorld
> 
> %% Doesn't work
> %% \starttexdefinition fooBar1
> %%   Foo, bar 1!
> %% \stoptexdefinition
> %%
> %% \fooBar1
> 
> %% Doesn't work
> %% \starttexdefinition foo_bar
> %%   Foo, bar!
> %% \stoptexdefinition
> %%
> %% \foo_bar
> 
> %% Doesn't work
> %% \starttexdefinition foo-bar
> %%   Foo, bar!
> %% \stoptexdefinition
> %%
> %% \foo-bar
> 
> \stoptext
> ------------------------------------------------------------
> --
> N. Raghavendra <raghu@hri.res.in>, http://www.retrotexts.net/
> Harish-Chandra Research Institute, http://www.hri.res.in/
> ___________________________________________________________________________________
> 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://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
> 


-- 

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Characters allowed in macro names
  2018-04-22 15:23 Characters allowed in macro names N. Raghavendra
  2018-04-22 16:04 ` Hans Hagen
@ 2018-04-22 18:08 ` Wolfgang Schuster
  2018-04-22 18:22   ` N. Raghavendra
  1 sibling, 1 reply; 5+ messages in thread
From: Wolfgang Schuster @ 2018-04-22 18:08 UTC (permalink / raw)
  To: N. Raghavendra, mailing list for ConTeXt users


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



> N. Raghavendra <mailto:nyraghu27132@gmail.com>
> 22. April 2018 um 17:23
> I was wondering if it is alright to use underscores in the names of
> macros, e.g, as in the following file. It looks like \startsetups, and
> \def accept names with hyphens, underscores, and numerals, but
> \starttexdefinition doesn't tolerate any of them.
>
> 1. In general, what characters are allowed in macro names? Are Unicode
> characters admissible?
>
> 2. Apart from the fact that one can use whitespace freely in
> \starttexdefinition, is there any reason to prefer it over \def?
>
> Thanks,
> Raghu.
>
> ------------------------------------------------------------
> \starttext
>
> \startsetups [hello-world_1]
> Hello, world 1!
> \stopsetups
>
> \setups [hello-world_1]
>
> \def\hello-world_2{Hello, world 2!}
You’re defining a command named \hello which has to be followed by the 
string "-world_2".


You can use the following example as test.

%%%% begin example
\starttext

\def\hello-1{Hello \letterhash 1}

\def\hello-2{Hello \letterhash 2}

\hello-1

\hello-2

\stoptext
%%%% end example

Here I create a command named \hello which has to be followed by “-1" 
and "-2".

When you run TeX on this example you get the following error message:

%%%% begin error message
tex error > tex error on line 7 in file /Users/wolf/TeX/test/test.tex: ! 
Use of \hello doesn't match its definition

l.7 \hello-1
%%%% end error message

Wolfgang

[-- Attachment #1.2: Type: text/html, Size: 2585 bytes --]

[-- Attachment #2: Type: text/plain, Size: 492 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Characters allowed in macro names
  2018-04-22 16:04 ` Hans Hagen
@ 2018-04-22 18:19   ` N. Raghavendra
  0 siblings, 0 replies; 5+ messages in thread
From: N. Raghavendra @ 2018-04-22 18:19 UTC (permalink / raw)
  To: ntg-context

At 2018-04-22T18:04:28+02:00, Hans Hagen wrote:

>> 1. In general, what characters are allowed in macro names?  Are Unicode
>>     characters admissible?
>
> letters are (and _ is not a letter, unless we're in unprotected mode)
>
>> 2. Apart from the fact that one can use whitespace freely in
>>     \starttexdefinition, is there any reason to prefer it over \def?
>
> depends ... sometimes more readble ... spaces are ignores ... you can
> use named parameters

Thanks for the clarification.

Raghu.

--
N. Raghavendra <raghu@hri.res.in>, http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: Characters allowed in macro names
  2018-04-22 18:08 ` Wolfgang Schuster
@ 2018-04-22 18:22   ` N. Raghavendra
  0 siblings, 0 replies; 5+ messages in thread
From: N. Raghavendra @ 2018-04-22 18:22 UTC (permalink / raw)
  To: ntg-context

At 2018-04-22T20:08:34+02:00, Wolfgang Schuster wrote:

> You can use the following example as test.
>
> %%%% begin example
> \starttext
>
> \def\hello-1{Hello \letterhash 1}
>
> \def\hello-2{Hello \letterhash 2}
>
> \hello-1
>
> \hello-2
>
> \stoptext
> %%%% end example
>
> Here I create a command named \hello which has to be followed by “-1"
> and "-2".
>
> When you run TeX on this example you get the following error message:
>
> %%%% begin error message
> tex error       > tex error on line 7 in file /Users/wolf/TeX/test/
> test.tex: ! Use of \hello doesn't match its definition
>
> l.7 \hello-1
> %%%% end error message

Yes, I get that error.  Thanks for the explanation.

Raghu.

--
N. Raghavendra <raghu@hri.res.in>, http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

end of thread, other threads:[~2018-04-22 18:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-22 15:23 Characters allowed in macro names N. Raghavendra
2018-04-22 16:04 ` Hans Hagen
2018-04-22 18:19   ` N. Raghavendra
2018-04-22 18:08 ` Wolfgang Schuster
2018-04-22 18:22   ` N. Raghavendra

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