Determing if the argument is one character or not
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
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 -----------------------------------------------------------------
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
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
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
participants (3)
-
Aditya Mahajan
-
Hans Hagen
-
Wolfgang Schuster