* Re[2]: MetaPost question
2001-11-18 11:57 ` Denis B. Roegel
@ 2001-11-18 13:17 ` Jose Luis Diaz
0 siblings, 0 replies; 4+ messages in thread
From: Jose Luis Diaz @ 2001-11-18 13:17 UTC (permalink / raw)
Cc: ConTeXt Mailing List
Hi Denis,
Denis> Build your string s with something like
Denis> s="$t_" & decimal(i) & "=" & decimal(t[i]) & "$";
Aha! I didn't know the decimal() operator, that is what I was looking
for. Thank you very much.
Denis> and then write
Denis> label.bot(TEX s,(0,t[i]*u))
Denis> and don't forget input TEX at the beginning of your file.
This works fine. However it has several drawbacks:
1) It doesn't work if I want to use LaTeX macros or packages for the
typeset material. I managed to work around this with a macro similar
to TEX, as follows:
vardef LATEX primary s =
write "verbatimtex" to "mptextmp.mp";
write "\documentclass[10pt]{book}" to "mptextmp.mp";
%
% write the required \usepackage here
%
write "\begin{document}" to "mptextmp.mp";
write "etex" to "mptextmp.mp";
write "btex "&s&" etex" to "mptextmp.mp";
write EOF to "mptextmp.mp";
scantokens "input mptextmp"
enddef;
2) The process for typesetting the labels is very slow. It requires
the generation and processing of an independent metapost file for
each label. And these can't be reutilized for subsequent metapost
runnings (since the same .mpx is overwritten for each label).
3) The results given by my macro LATEX or by the metapost macro TEX
are typeset, in general, in a different font than the rest of the
metapost document. For example, assume that in my main metapost file
I include some verbatimtex for changing the default fonts. I would
have to repeat this code inside the TEX/LATEX macro for achieving the
same fonts in the labels generated via these macros.
So I would like to avoid is possible the methods using the TEX macros.
I was studying the source code of "format.mp", which is used by
mpgraph for typesetting the labels for the plots. The method used by
"format.mp" does not require the TEX macro, and then it uses
consistently the same typefaces among all the figures, and it is
processed faster. However it is very tricky and not very general. It
seems to be targeted explicitly for writing numbers in scientific
notation.
I was able to adapt some of the code that format.mp used for
typesetting the exponents of the scientific notation, for my
particular case of typesetting subindexes. This is the code, just in
case someone could be interested:
%-------------------------------------------------------
input format; % For having the macro Fline_up_
vardef subindexed(expr t, i) =
% t is the text to be subindexed
% i is an integer number which will appear in the subindex
save scalesub, lowersub,fontsub, e, p;
numeric lowersub, scalesub; picture e, p; string fontsub;
e:=btex ${}_1$ etex; % Build a "sample" subindex
for p within e: % for looking up some parameters
fontsub := fontpart p; % look up the font
scalesub := xxpart p; % the scale
lowersub := ypart llcorner p; % and the baseline
exitif true;
endfor;
% Create a picture with the text for our subindex
p:=nullpicture;
addto p also (decimal i infont fontsub scaled scalesub
shifted (0,lowersub));
% Build the complete text, subindex included
Fline_up_(t,p) % This is a macro defined in format.mp which
% link together several pictures
enddef;
%-----------------------------------------------------------
Example of use:
for i=1 upto 10:
label(subindexed(btex $\beta$ etex, i), (i*1cm, i*.5cm));
endfor;
This works as expected, but is very specific and rather clumsy. Well,
I guess that there is no a better way of doing this, since "mpgraph"
itself uses this method...
Thanks again for your solution, Denis.
--
Saludos,
Jose mailto:jldiaz@telecable.es
^ permalink raw reply [flat|nested] 4+ messages in thread