* Determing if the argument is one character or not @ 2009-02-03 23:11 Aditya Mahajan 2009-02-03 23:24 ` Hans Hagen 2009-02-03 23:53 ` Wolfgang Schuster 0 siblings, 2 replies; 5+ messages in thread From: Aditya Mahajan @ 2009-02-03 23:11 UTC (permalink / raw) To: mailing list for ConTeXt users Hi, I want to write a macro which behaves differently depending on whether its argumet is a single character or not. \MACRO[a] should give $X_{a}$ \MACRO[a:b] should give $X_{[a:b]}$ Any hints on how to do this? Thanks, Aditya ___________________________________________________________________________________ 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Determing if the argument is one character or not 2009-02-03 23:11 Determing if the argument is one character or not Aditya Mahajan @ 2009-02-03 23:24 ` Hans Hagen 2009-02-04 1:06 ` Aditya Mahajan 2009-02-03 23:53 ` Wolfgang Schuster 1 sibling, 1 reply; 5+ messages in thread From: Hans Hagen @ 2009-02-03 23:24 UTC (permalink / raw) To: mailing list for ConTeXt users Aditya Mahajan wrote: > Hi, > > I want to write a macro which behaves differently depending on whether > its argumet is a single character or not. > > \MACRO[a] should give $X_{a}$ > \MACRO[a:b] should give $X_{[a:b]}$ > > Any hints on how to do this? \def\MACRO[#1#2]% {\doifelsenothing{#2} {$X_{#1}$} {$X_{[#1#2]}$}} ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Determing if the argument is one character or not 2009-02-03 23:24 ` Hans Hagen @ 2009-02-04 1:06 ` Aditya Mahajan 0 siblings, 0 replies; 5+ messages in thread From: Aditya Mahajan @ 2009-02-04 1:06 UTC (permalink / raw) To: mailing list for ConTeXt users On Wed, 4 Feb 2009, Hans Hagen wrote: > Aditya Mahajan wrote: >> Hi, >> >> I want to write a macro which behaves differently depending on whether its >> argumet is a single character or not. >> >> \MACRO[a] should give $X_{a}$ >> \MACRO[a:b] should give $X_{[a:b]}$ >> >> Any hints on how to do this? > > \def\MACRO[#1#2]% > {\doifelsenothing{#2} > {$X_{#1}$} > {$X_{[#1#2]}$}} Duh. I should really try to understand TeX parsing rules some day. Thanks, Aditya ___________________________________________________________________________________ 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Determing if the argument is one character or not 2009-02-03 23:11 Determing if the argument is one character or not Aditya Mahajan 2009-02-03 23:24 ` Hans Hagen @ 2009-02-03 23:53 ` Wolfgang Schuster 2009-02-04 1:07 ` Aditya Mahajan 1 sibling, 1 reply; 5+ messages in thread From: Wolfgang Schuster @ 2009-02-03 23:53 UTC (permalink / raw) To: mailing list for ConTeXt users Am 04.02.2009 um 00:11 schrieb Aditya Mahajan: > I want to write a macro which behaves differently depending on > whether its argumet is a single character or not. > > \MACRO[a] should give $X_{a}$ > \MACRO[a:b] should give $X_{[a:b]}$ > > Any hints on how to do this? To test for the number argument use \counttoken(s) and to check if the string contains a ":" use \doifinstring/\doifinstringelse. 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Determing if the argument is one character or not 2009-02-03 23:53 ` Wolfgang Schuster @ 2009-02-04 1:07 ` Aditya Mahajan 0 siblings, 0 replies; 5+ messages in thread From: Aditya Mahajan @ 2009-02-04 1:07 UTC (permalink / raw) To: mailing list for ConTeXt users On Wed, 4 Feb 2009, Wolfgang Schuster wrote: > > Am 04.02.2009 um 00:11 schrieb Aditya Mahajan: > >> I want to write a macro which behaves differently depending on whether its >> argumet is a single character or not. >> >> \MACRO[a] should give $X_{a}$ >> \MACRO[a:b] should give $X_{[a:b]}$ >> >> Any hints on how to do this? > > To test for the number argument use \counttoken(s) and to check > if the string contains a ":" use \doifinstring/\doifinstringelse. Thanks. For the moment, I will go with Hans's solution, since it is much simpler. Aditya ___________________________________________________________________________________ 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-02-04 1:07 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2009-02-03 23:11 Determing if the argument is one character or not Aditya Mahajan 2009-02-03 23:24 ` Hans Hagen 2009-02-04 1:06 ` Aditya Mahajan 2009-02-03 23:53 ` Wolfgang Schuster 2009-02-04 1:07 ` Aditya Mahajan
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).