I suppose that compilation is made by latex (no tex). What about
label.top(btex
\begin{minipage}{4cm}
First Line\par
Second Line
\end{minipage}
etx, (0,0));
Jean-C\^ome Charpentier
When I said compile I meant when I try to run metapost on the file i.e. when I type
>mp file.mp
at the dos prompt.
Try the following example:
verbatimtex
\documentclass{article}
\begin{document}
etex
beginfig(1)
pair A, B, C, D, E;
A:=(0,0);
B:=(5cm,0);
C:=(5cm,3cm);
D:=(0,3cm);
E:=(1cm,1.5cm);
draw A--B--C--D--cycle;
dotlabel.rt(btex \parbox{3cm}{Line1 \\ Line2} etex, E);
label.top(btex \parbox{3cm}{Line1 \\ Line2} etex, (7cm,1.5cm));
endfig;
end
And when I said compile I meant when metpost call TeX to build the btex
... etex. By default, it's TeX, so the \\ or the \begin{minipage} will
produce many error messages.
If you use metapost by default (without verbatimtex \documentclass ...
at the beginning), you could try
label.top(btex First Line\par Second Line etex, (0, 0))
or
label.top(btex \hsize=4cm First Line\par Second Line etex, (0,0))
(not tested)
Jean-C\^ome Charpentier
When I copy and paste this into a new metapost file then I still get
errors when I run mp on it. Am I using a different version of
metapost?
> Stefan Lagotzki <lag...@gmx.de> wrote in message
> news:<cgap29$ts5$02$1...@news.t-online.com>...
> > Hasan Zaidi <hasz...@gmail.com>:
> > > Does anyone know how to produce a new line in a metapost label? I have
> > > tried:
> > > label.top(btex First Line\\Second Line etex, (0, 0)) but I get a
> > > compilation error. Can anyone help?
> >
> > Try the following example:
> >
> > verbatimtex
> > \documentclass{article}
> > \begin{document}
> > etex
> >
> > beginfig(1)
> > dotlabel.rt(btex \parbox{3cm}{Line1 \\ Line2} etex, origin);
> > label.top(btex \parbox{3cm}{Line1 \\ Line2} etex, (7cm,1.5cm));
> > endfig;
> >
> > end
>
> When I copy and paste this into a new metapost file then I still get
> errors when I run mp on it. Am I using a different version of
> metapost?
You have to tell metapost to use latex, instead of tex to handle the
btex ... etex bits. Try
mpost -tex=latex yourfile.mp
(but verify that a dos prompt uses the same syntax as the unix system,
mpost -help prints a usage message here).
Maarten
The syntax is the same but I still get an error message. Although,
when I remove the \\ from the label then re-run with:
mp -tex=latex yourfile.mp
then I get the same error message.
What error message; how are you trying to view the result?
I just tried the example, and it produces exactly what I expect.
Try the following:
mpost -tex=latex test.mp
mptopdf test.1
and open the resulting test-1.pdf in acrobat of your favourite pdf
viewer. GSView might have trouble opening the resulting mpost output
directly. (test.mp contains the sample code shown before).
Maarten
There are 17 different reasons for this. It would help narrow the
possibilities if you told us the error message.
What do you think error messages are for?
Some background:
1. Metapost simply copies the content of the btex...etex to a file
inside \hbox{...}. That is, the above becomes:
\hbox{First Line\\ Second Line}
Now \hbox is the TeX foundation on which latex's \mbox is built, and
this _prohibits_ line breaks.
So the first thing you need is to wrap your code in something that
allows line breaking.
2. Metapost runs some version of tex on the resulting file. By default
plain tex. If you want it to run latex on it you have to tell it so, and
you have to include a basic latex preamble inside a verbatimtex...etex
group.
The following should work:
% Id: file1.mp
verbatimtex
\documentclass{article}
\begin{document}
etex;
beginfig(1);
label(btex \begin{tabular}{l} First Line\\ Second Line
\end{tabular} etex, (0,0));
endfig;
end
provided you call metapost with
mpost --tex=latex file1.mp
The following should also work:
% Id: file2.mp
beginfig(1);
label(btex \halign{#\hfil\cr First Line\cr Second Line\cr}
etex, (0,0));
endfig;
end
even with plain tex (i.e. just using "mpost file2.mp").
If you are using MiKTeX (another thing you should have told us),
there have been problems with the temporary files created by mpost
not being found when the current directory is under texmf or
localtexmf.
Dan
--
Dan Luecking Department of Mathematical Sciences
University of Arkansas Fayetteville, Arkansas 72701
To reply by email, change Look-In-Sig to luecking
The first one works but I have not tried the second method. Thanks for
everyone's help.
Regards, Hasan Zaidi
This is what I ended up using, when I needed such. I'm pretty sure I
got it from somewhere else -- the MetaPost manual, I think, but I'm not
certain of that.
At the top of the MetaPost document:
\verbatimtex
\def\stk#1#2{$\matrix{\hbox{#1}\cr\hbox{#2}\cr}$}
\def\tstk#1#2#3{$\matrix{\hbox{#1}\cr\hbox{#2}\cr\hbox{#3}\cr}$}
etex
Then, in the document:
label(btex \stk{Rest}{Room} etex, (2.95,3.2));
or
label(btex \tstk{Registration}{and}{Reception} etex, (4.25,2.3));
Note that this is rather more complicated than you asked for, because
it's also centering each line. The concepts are there, though.
- Brooks
--
The "bmoses-nospam" address is valid; no unmunging needed.