[NTG-context] Remove leading spaces
When a function is called, I would like to remove any leading space. Then the function can control the spacing. If I don't remove spaces, it then makes a difference whether or not I have a space before the function is called. I would like the output of the following two lines to be equal: This is a \MyFunction[1] test. This is a\MyFunction[1] test. However, they are not because the first line has a space before the function call. \def\MyFunction{\dosingleempty\doMyFunction} \def\doMyFunction[#1]{% \processaction[#1]% [1=\medspace dog ,% 2=\medspace cat ,% default=\ldots]% } \starttext Test1: This is a\MyFunction[1] test. Test2: This is a \MyFunction[1] test. Test3: This is a \MyFunction test. Test4: This is a\MyFunction test. \stoptext Is there a way to do this and not cause any side effects? Thanks, Bart ___ 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 ___
Re: [NTG-context] Remove leading spaces
Am 05.02.2009 um 21:26 schrieb Bart C. Wise: When a function is called, I would like to remove any leading space. Then the function can control the spacing. If I don't remove spaces, it then makes a difference whether or not I have a space before the function is called. Is there a way to do this and not cause any side effects? You can use \removeunwantedpsaces to remove preceding spaces before your command and \ignorespaces to gobble spaces after your command. A faster version of your macro is: \def\MyFunction {\dosingleempty\doMyFunction} \def\doMyFunction[#1]% {\removeunwantedspaces\executeifdefined{myfunction:#1} {\getvalue{myfunction:default}}} \setvalue{myfunction:1}{\medspace dog } \setvalue{myfunction:2}{\medspace cat } \setvalue{myfunction:default}{\ldots} 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 ___
Re: [NTG-context] Remove leading spaces
On Thursday 05 February 2009 01:36:16 pm Wolfgang Schuster wrote: Am 05.02.2009 um 21:26 schrieb Bart C. Wise: When a function is called, I would like to remove any leading space. Then the function can control the spacing. If I don't remove spaces, it then makes a difference whether or not I have a space before the function is called. Is there a way to do this and not cause any side effects? You can use \removeunwantedpsaces to remove preceding spaces before your command and \ignorespaces to gobble spaces after your command. A faster version of your macro is: \def\MyFunction {\dosingleempty\doMyFunction} \def\doMyFunction[#1]% {\removeunwantedspaces\executeifdefined{myfunction:#1} {\getvalue{myfunction:default}}} \setvalue{myfunction:1}{\medspace dog } \setvalue{myfunction:2}{\medspace cat } \setvalue{myfunction:default}{\ldots} Thanks Wolfgang for the answer! And thanks for the coding hints, they are always appreciated! Bart ___ 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 ___