On 1/30/07, Aditya Mahajan wrote:
On Tue, 30 Jan 2007, Mojca Miklavec wrote:
Hello,
instead of checking the problems with MyWay about database module, I created another unfinished piece about \sometxt (as promised already long ago):
http://dl.contextgarden.net/myway/sometxt.pdf
\sometxt{...} should be used instead of textext("...") in metafun graphics whenever possible, since it's much more efficient. An average user shouldn't care about much more than that. The MyWay is devoted to the curious ones. I hope that I included all the major ideas which Hans implemented in Summer/Autumn 2006 on my request. Although not all of them are documented well enough, I tried to mention them at least.
Very nice. Now, I do not need to look up old mails to figure out how to manipulate sometxt.
I've put there everything that came to my mind, but 99% of the usage is still only \sometxt{...}. The rest is trickery.
I have one example where \sometxt[...]{...} is useful. If you are interested, I can send it to you.
I can include it in the manual if you want. I used \sometxt[] for gnuplot because it looks more elegant and more backward compatible that adding a bunch of additonal macros in front of it. The example in MyWay is "artificial".
I thought a bit about your feature request, and it is not too difficult to implement it. Here is a patch that allows you to use \sometext[font][iwona,20pt]{...}. Careful of spurious linebreaks.
Great!!! Having a hardcoded \sometxt[font] doesn't help me much, but I'll copy the code literally to the module and replace [font] by [gp].
%=======================================================
\long\def\redofiltersometxt[#1]% {\doifnextcharelse[{\reredofiltersometxt[#1]}{\redodofiltersometxt[#1]}}
\long\def\redodofiltersometxt[#1]#2% {\increment\txtcounter \TeXtext[#1]\txtcounter{#2}% \filtersometxt}
\long\def\reredofiltersometxt[#1][#2]#3% {\increment\txtcounter \TeXtext[#1]\txtcounter{\switchtobodyfont[#2]\strut#3}% \filtersometxt}
\definetextext[font]{\donothing}
\usetypescript[iwona][texnansi]
\starttext \startMPcode draw fullcircle xyscaled (3cm,2cm); label(\sometxt{Hello world!}, origin); \stopMPcode
% Does not cause any harm. \startMPcode draw fullcircle xyscaled (3cm,2cm); label(\sometxt[font]{Hello world!}, origin); \stopMPcode
\startMPcode draw fullcircle xyscaled (3cm,2cm); label(\sometxt[font][iwona,20pt]{Hello world!}, origin); \stopMPcode
\stoptext
%===============================================================
I haven't tested it, but I do not think that this should cause any problems with existing code. \definetextext[font] is just a dummy. It should work with other things also. You can get rid of the dummy by checking in redodofiltersometxt if #1 is has a comma or not. Would that extra overhead be useful of gnuplot?
Yes. But copying the code literally doesn't make as much sense since other users might have different needs than "second optional parameter should switch the font". I'll add that to the gnuplot module directly. The only thing that could help would be a high-level user interface to define such commands, such as is \definetextext[name]{\command} So that one could then define % I'm not sure what should come inbetween \definetextext[myboldfont]???{\myboldfont} % #1 might be empty \def\myboldfont[#1]#2{\framed{ \doifnot{#1}{}{\switchtobodyfont[#1]} \strut\bf #2}} for example and use it as \sometxt[myboldfont][iwona]{this will be bold and framed iwona} But your current code is more than enough for me (apart from the fact that it's not really nice to redefine low-level macros, but I'll try to keep up with low-level changes, should any accur) ;) Thanks again, Mojca (Before you asked for the feature of having optional parameters, I redefined the low-level interface to accept \gptext{...} and \gptext[fontname]{...} ;)
Hans, is there a reason for not defining dodofiltersometxt as
\long\def\dodofiltersometxt#1#2% #3 {\ifx#2\empty \else \increment\txtcounter \TeXtext\txtcounter{#1}% \expandafter\filtersometxt \fi#2}% #3
whih will be a bit faster.