On Tue, 30 Jan 2007, Mojca Miklavec wrote:

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.

I mainly use the \sometxt[..]{..} feature to create labels in my metapost figures. The normal setup is

\definetextext[parbox]{\framed[frame=off, width=2cm, autowidth=force, align=middle, background=color, backgroundcolor=white]}


Which insures that I do not have to worry about line breaking of long labels, and the unfill trick to get white backgrounds in labels. The down-side is that the background is white instead of being transparent. So, if you have a colored page background, the figure
looks odd. I have attached a complete example.


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

The font is not hardcoded. But you need to have something there. Otherwise you need a mechanism to distinguish between

\sometxt[whatever] and
\sometxt[iwona]


%=======================================================
[snip[
%===============================================================

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.

It can be configurable. Maybe something like

\defineopttextext[whatever]{\command}

so that with \sometxt[whatever][2nd arg]{stuff} translates to \command[2nd ard]{stuff} and \sometxt[whatever]{stuff} translates to \command{stuff}.

That would involve more work to write the macro \command, but will provide more flexibility.


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]}
        ^^^^^^^^^^^^^^^^
\doifnothing or \doifsomething is easier to  read
      \strut\bf #2}}
for example and use it as
  \sometxt[myboldfont][iwona]{this will be bold and framed iwona}

It may be possible to extend definetextext to do this rather than \defineopttextext. In any case, it is upto the macro \command to ensure that it can handly the optinal argument. I will see if I can cook up something working.

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

Or persuade Hans to have a proper version in the core :)

Aditya
\setupcolors[state=start]

\usetypescriptfile[type-gyr]
\usetypescript[times][texnansi]
\setupbodyfont[times,8pt]

\def\BEFORE#1{\math{\underline{#1}}}
\def\AT#1{\math{#1}}
\def\AFTER#1{\math{\smash{\overline{#1}}}\vphantom{#1}}

\defineframed
  [parbox]
  [frame=off, width=2cm, autowidth=force, align=middle, background=color,
  backgroundcolor=white]

\definetextext[parbox]{\framed[frame=off, width=2cm, autowidth=force, 
align=middle, background=color, backgroundcolor=white]}

\starttext
\startMPpage
% Color for drawing helplines  
color helpcolor ; helpcolor := 0.5*white ;

% Scaling
u := 2cm ;        e := .1u ;

% Constants

xmax  :=  5u ;    ymax  := -3u ;
xstep := .5u ;    ystep := -.5u ;

xbefore := 2*xstep ;
xat     := 6*xstep ;
xafter  := xmax - 2*xstep ;

W := 0 ;
X := xstep ;
Z := 3*xstep ;
N := 4*xstep ;
Y := 5*xstep ;
M := 7*xstep ;
U := 9*xstep ;

c := xbefore + e ;
l := xat     + e ;
g := xafter  + e ;

path xline , yline , xshort;

xline := (-xstep,0) -- (xmax + xstep,0) ;
xshort:= (0,0) -- (xmax,0) ;
yline := (0,-0.8*ystep) -- (0,ymax + 0.5*ystep) ;


draw yline ;
draw yline shifted (xmax,0) ;

for i = 0 upto 6 :
  drawarrow xline shifted (0, i*ystep) ;
endfor ;

drawdblarrow xshort shifted (0, -0.6*ystep) ;

drawoptions(dashed evenly withcolor helpcolor) ;
draw yline shifted (xbefore,0) ;
draw yline shifted (xat,0) ;
draw yline shifted (xafter,0) ;

drawoptions() ;

y := 0 ;

dotlabel.top(\sometxt[parbox]{$t^+$},       (xbefore,y) ) ;
dotlabel.top(\sometxt[parbox]{$(t+1/2)$},   (xat,y)     ) ;
dotlabel.top(\sometxt[parbox]{$(t+1)^-$},  (xafter,y)  ) ;

y := ystep ;

dotlabel.top(\sometxt[parbox]{$\BEFORE t$}, (xbefore,y) ) ;
dotlabel.top(\sometxt[parbox]{$\AT t$},     (xat,y)     ) ;
dotlabel.top(\sometxt[parbox]{$\AFTER t$},  (xafter,y)  ) ;

y := 2*ystep ;

dotlabel.top(\sometxt[parbox]{$W_{t-1}$}, (W,y) ) ;
dotlabel.top(\sometxt[parbox]{$X_t$}, (X,y) ) ;
dotlabel.top(\sometxt[parbox]{$Z_t$}, (Z,y) ) ;
dotlabel.top(\sometxt[parbox]{$N_t$}, (N,y) ) ;
dotlabel.top(\sometxt[parbox]{$Y_t$}, (Y,y) ) ;
dotlabel.top(\sometxt[parbox]{$M_t$}, (M,y) ) ;
dotlabel.top(\sometxt[parbox]{$U_t$}, (U,y) ) ;

y := 3*ystep ;

dotlabel.bot(\sometxt[parbox]{$c_t$}, (c,y) ) ;
dotlabel.bot(\sometxt[parbox]{$l_t$}, (l,y) ) ;
dotlabel.bot(\sometxt[parbox]{$g_t$}, (g,y) ) ;

y := 4*ystep ;

dotlabel.top(\sometxt[parbox]{$\BEFORE I_t$}, (xbefore,y) ) ;
dotlabel.top(\sometxt[parbox]{$\AT I_t$},     (xat,y)     ) ;
dotlabel.top(\sometxt[parbox]{$\AFTER I_t$},  (xafter,y)  ) ;

y := 5*ystep ;

dotlabel.top(\sometxt[parbox]{$\BEFORE B_t$}, (xbefore,y) ) ;
dotlabel.top(\sometxt[parbox]{$\AT B_t$},     (xat,y)     ) ;
dotlabel.top(\sometxt[parbox]{$\AFTER B_t$},  (xafter,y)  ) ;

y := 6*ystep ;

dotlabel.top(\sometxt[parbox]{$\BEFORE \pi_t$}, (xbefore,y) ) ;
dotlabel.top(\sometxt[parbox]{$\AT \pi_t$},     (xat,y)     ) ;
dotlabel.top(\sometxt[parbox]{$\AFTER \pi_t$},  (xafter,y)  ) ;


label.lft(\sometxt[parbox]{actual time},       (-xstep, 0) ) ; 
label.lft(\sometxt[parbox]{time notation},     (-xstep, ystep) ) ;
label.lft(\sometxt[parbox]{System Variables},  (-xstep, 2*ystep) ) ;
label.lft(\sometxt[parbox]{Design Laws},       (-xstep, 3*ystep) ) ;
label.lft(\sometxt[parbox]{Information at the controller},
                                                (-xstep, 4*ystep) ) ;
label.lft(\sometxt[parbox]{Beliefs},           (-xstep, 5*ystep) ) ;
label.lft(\sometxt[parbox]{Information States},(-xstep, 6*ystep) ) ;

label.top(\sometxt[parbox]{Stage $t$}, (0.5*xmax,-0.6*ystep)) ;

\stopMPpage


\stoptext
_______________________________________________
dev-context mailing list
dev-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/dev-context

Reply via email to