Re: Metapost - text alignment

Rob McDonald said:
On 1/27/07, Rob McDonald <rob a mcdonald gmail com> wrote:
On 1/27/07, Lars Clausen <lars raeder dk> wrote:
On Fri, 2007-01-26 at 07:51 -0800, Rob McDonald wrote:
In MetaPost, LaTeX renders the text, and I don't think MP ever
or 'controls' the text width.  The text width is a fallout from the
font size and the string.

Can't we tell the LaTeX part to scale it to a certain width?

I'll see what I can do.  I think I can come up with another MetaPost
macro to scale any object to a desired width.  However, I don't think
that is a great idea.

Here is the MetaPost to handle what you're after.  I still don't think
it is the right thing to do in 99% of all situations.

As I see it, there's two possible situations:  Either the text is plain
text or it's a LaTeX formula (of some kind).  The formulas we have no
chance to fit correctly until a separate LaTeXObject is introduced (which
could start out as a clone of TextObject) which the MetaPost renderer can
handle specially.  Plain text we actually have a chance to not just
position right, but also have a reasonable width of -- which is used in
the diagram, for sizing boxes etc.  If we always leave the size to
LaTeX/MP, the output is 99% guaranteed to be different from what you see
in Dia.  If we give LaTeX/MP the size (width!), any plain text will be
just as in Dia, but formulas will need fixing.

I'm very tempted to break the feature freeze and introduce LaTeXObject in
the Misc sheet, just so that all other text can be treated The Right Way
[tm].  Then it can later be updated to do LaTeX interaction in order to
render nicely and have the right bounding box.  I introduced render_object
in the renderer system exactly so that this kind of thing could be

% Define macro to scale to a desired width.
primarydef P scaledw W =
  P scaled (W/(xpart (lrcorner P - llcorner P)))

draw btex {\usefont{OT1}{cmr}{m}{n} $c^2=a^2+b^2$} etex scaled 1.0
shifted (11.00000x,4.650000y);
draw btex {\usefont{OT1}{cmr}{m}{n} Mary had a little lamb.} etex
scaled 1.0 shifted (11.00000x,5.000000y);

draw btex {\usefont{OT1}{cmr}{m}{n} $c^2=a^2+b^2$} etex scaledw 4.0cm
shifted (11.00000x,7.650000y);
draw btex {\usefont{OT1}{cmr}{m}{n} Mary had a little lamb.} etex
scaledw 4.0cm shifted (11.00000x,8.000000y);

Thanks, I'll give it a try.  Do you have a quick-and-dirty way to see if
metapost output is correct (e.g. convert MP files directly to PNG or
something)?  I'm not a metaposter myself.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]