ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* \type{...} as macro argument
@ 2020-11-08 13:47 Sylvain Hubert
  2020-11-08 14:03 ` Wolfgang Schuster
  0 siblings, 1 reply; 5+ messages in thread
From: Sylvain Hubert @ 2020-11-08 13:47 UTC (permalink / raw)
  To: mailing list for ConTeXt users


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

Dear List,

I would like to ask how to define a command, \same, such that

    \same{\type{a   b c}}

produces the same result as its argument does

    \type{a   b c}

The naive way doesn't work because it makes all the spaces collapse:

    \define[1]\same{#1}

I would also like to ask whether this could be achieved using the lua
interface:

    \startluacode
    interfaces.definecommand {
       name="same",
       -- catcode/mode/arguments = ???
    }

Thanks in advance.

Best,
Sylvain

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

[-- Attachment #2: Type: text/plain, Size: 493 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: \type{...} as macro argument
  2020-11-08 13:47 \type{...} as macro argument Sylvain Hubert
@ 2020-11-08 14:03 ` Wolfgang Schuster
  2020-11-08 16:56   ` Sylvain Hubert
  0 siblings, 1 reply; 5+ messages in thread
From: Wolfgang Schuster @ 2020-11-08 14:03 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Sylvain Hubert schrieb am 08.11.2020 um 14:47:
> Dear List,
> 
> I would like to ask how to define a command, \same, such that
> 
>      \same{\type{a   b c}}
> 
> produces the same result as its argument does
> 
>      \type{a   b c}
> 
> The naive way doesn't work because it makes all the spaces collapse:
> 
>      \define[1]\same{#1}


\definetype [typeTEX] [option=tex]

\starttext

\type{\startsection[title=\tex{type}]}

\typeTEX{\startsection[title=\tex{typeTEX}]}

\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://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: \type{...} as macro argument
  2020-11-08 14:03 ` Wolfgang Schuster
@ 2020-11-08 16:56   ` Sylvain Hubert
  2020-11-08 17:27     ` Wolfgang Schuster
  0 siblings, 1 reply; 5+ messages in thread
From: Sylvain Hubert @ 2020-11-08 16:56 UTC (permalink / raw)
  To: Wolfgang Schuster, mailing list for ConTeXt users


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

Hi Wolfgang,

I'm sorry that the question was not clear enough. Let me ask in this way:
how to define a \dorecurse, such that \dorecurse{10}{\type{a    b c}} does
not squash the spaces?

Sylvain

On Sun, 8 Nov 2020 at 15:03, Wolfgang Schuster <
wolfgang.schuster.lists@gmail.com> wrote:

> Sylvain Hubert schrieb am 08.11.2020 um 14:47:
> > Dear List,
> >
> > I would like to ask how to define a command, \same, such that
> >
> >      \same{\type{a   b c}}
> >
> > produces the same result as its argument does
> >
> >      \type{a   b c}
> >
> > The naive way doesn't work because it makes all the spaces collapse:
> >
> >      \define[1]\same{#1}
>
>
> \definetype [typeTEX] [option=tex]
>
> \starttext
>
> \type{\startsection[title=\tex{type}]}
>
> \typeTEX{\startsection[title=\tex{typeTEX}]}
>
> \stoptext
>
> Wolfgang
>

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

[-- Attachment #2: Type: text/plain, Size: 493 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: \type{...} as macro argument
  2020-11-08 16:56   ` Sylvain Hubert
@ 2020-11-08 17:27     ` Wolfgang Schuster
  2020-11-08 18:35       ` Sylvain Hubert
  0 siblings, 1 reply; 5+ messages in thread
From: Wolfgang Schuster @ 2020-11-08 17:27 UTC (permalink / raw)
  To: Sylvain Hubert; +Cc: mailing list for ConTeXt users

Sylvain Hubert schrieb am 08.11.2020 um 17:56:
> Hi Wolfgang,
> 
> I'm sorry that the question was not clear enough. Let me ask in this way:
> how to define a \dorecurse, such that \dorecurse{10}{\type{a    b c}} 
> does not squash the spaces?

Verbatim in arguments of other commands is tricky because in case with 
\dorecurse the loop reads the content before it is passed to type, as a 
result of this process all spaces are collapsed.

One way to work around this is to use a buffer for the content of the loop.

\startbuffer[type]
\type{a    b c}
\stopbuffer

\starttext
\dorecurse{10}{\inlinebuffer[type]\par}
\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://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: \type{...} as macro argument
  2020-11-08 17:27     ` Wolfgang Schuster
@ 2020-11-08 18:35       ` Sylvain Hubert
  0 siblings, 0 replies; 5+ messages in thread
From: Sylvain Hubert @ 2020-11-08 18:35 UTC (permalink / raw)
  To: Wolfgang Schuster, mailing list for ConTeXt users


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

On Sun, 8 Nov 2020 at 18:27, Wolfgang Schuster <
wolfgang.schuster.lists@gmail.com> wrote:

> Sylvain Hubert schrieb am 08.11.2020 um 17:56:
> > Hi Wolfgang,
> >
> > I'm sorry that the question was not clear enough. Let me ask in this way:
> > how to define a \dorecurse, such that \dorecurse{10}{\type{a    b c}}
> > does not squash the spaces?
>
> Verbatim in arguments of other commands is tricky because in case with
> \dorecurse the loop reads the content before it is passed to type, as a
> result of this process all spaces are collapsed.
>
> One way to work around this is to use a buffer for the content of the loop.
>
> \startbuffer[type]
> \type{a    b c}
> \stopbuffer
>
> \starttext
> \dorecurse{10}{\inlinebuffer[type]\par}
> \stoptext
>

Many thanks for the answer!
It seems that the buffer mechanism is quite a powerful resort for the macro
language.

Sylvain

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

[-- Attachment #2: Type: text/plain, Size: 493 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

end of thread, other threads:[~2020-11-08 18:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-08 13:47 \type{...} as macro argument Sylvain Hubert
2020-11-08 14:03 ` Wolfgang Schuster
2020-11-08 16:56   ` Sylvain Hubert
2020-11-08 17:27     ` Wolfgang Schuster
2020-11-08 18:35       ` Sylvain Hubert

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