Andrej Kastrin | 10 Nov 2011 19:31
Picon
Favicon

Decimal numbers

Dear all,

I'm a 2nd day METAPOST user. I wonder how to get a number rounded to a desired number of decimal places. A
minimal example is pasted below.

beginfig(1);
xmax:=10;

ux:=0.5cm;

drawarrow (0,0)*ux..(xmax+0.7,0)*ux;

for i=0 upto xmax:

  draw (i,-0.05)*ux -- (i,0.05)*ux;

  label.bot(decimal(i/10), (i,0)*ux);

endfor;

endfig;
end

The labels in the example above are as follows:
  "0, 0.1, 0.2,..., 0.9, 1"
but the desired output is:
  "0.0, 0.1, 0.2,..., 0.9, 1.0" or even better:
".0, .1, .2,..., .9, 1.0"

Thanks in advance for any pointers and/or suggestions.
(Continue reading)

Yogeshwarsing Calleecharan | 11 Nov 2011 12:32
Picon
Favicon

graphing problems in metapost

Hi,
     I have some data as follows (first and second columns) in the file 
mydata.d which I want to graph:

8   98826   year 2008
9   104925  year 2009
10  140153  year 2010
11  178414  year 2011

As we have big numbers in the second numbers, I have used the macro 
sarith. Here's my metapost code for the plot:

input graph
input sarith
beginfig(1);
draw begingraph(8cm,5cm);
setrange(8,whatever,12,whatever);
gdraw "mydata.d" withpen pencircle scaled 1.5pt;;
gdraw "mydata.d" plot btex $\bullet$ etex;
autogrid(otick.bot,);
gdotlabel.lrt(btex $98\;826$ etex, 8,"98826");
gdotlabel.lrt(btex $104\;925$ etex, 9,"104925");
gdotlabel.lrt(btex $140\;153$ etex, 10,"140153");
gdotlabel.lrt(btex $178\;414$ etex, 11,"178414");
endgraph;
endfig;
end

So I am plotting the first two columns, taking away the y-axis tickmarks 
and labels and also writing the y-value at each coordinate in the plot. 
(Continue reading)

Dirk Laurie | 12 Nov 2011 07:28
Picon

Re: Decimal numbers

2011/11/10 Andrej Kastrin <andrej.kastrin <at> yahoo.com>:

>
> I wonder how to get a number rounded to a desired number of decimal places.

*def rnd(expr x,d) = round(x*(10**d))/(10**d) enddef;

*show rnd(sqrt(2),3);
>> 1.414

> Thanks in advance for any pointers and/or suggestions.
>
This sort of thing is in the Metafont Book by Donald Knuth and not
repeated in the Metapost manual.

Dirk
--
http://tug.org/metapost/

Troy Henderson | 12 Nov 2011 09:35
Picon

Re: Decimal numbers

> I'm a 2nd day METAPOST user. I wonder how to get a number rounded to a
> desired number of decimal places.

The format package can do this for you already.  It is part of the base
MetaPost system.  You can use it in the following way:

input format;
show roundd(x,d);

where x is the number you want to round to d decimal places.  Note that
d could be positive, 0, or negative.  Positive d acts as you expect, d=0
rounds to the nearest ones place, and negative d rounds to the nearest
10^(-d) place.

> The labels in the example above are as follows:
>   "0, 0.1, 0.2,..., 0.9, 1"
> but the desired output is:
>   "0.0, 0.1, 0.2,..., 0.9, 1.0"

label.bot(format("%1f",i/10), (i,0)*ux); % Also requires "input format;"

> or even better:
> ".0, .1, .2,..., .9, 1.0"

I try not to make a habit of telling people what they want to see from
their MetaPost output (since MetaPost is so flexible), but as a
mathematician myself, I detest decimals without the leading 0 in the
ones place because if the print is bad, the decimal point might not show
up well and a number like .2 might be viewed as 2 instead of 0.2.
Therefore, it is my opinion that a leading 0 should be present when a
(Continue reading)

Olivier.Jutand | 12 Nov 2011 14:53
Picon
Favicon

Problem with metapost and stacksize

Hello,

I'm a french maths teacher and I've been using LaTeX for several years and Metapost for my diagrams. But I'm
afraid I face a problem I can't solve alone.
I wanted to set up Ocaml and camllight on my Mac (OS 10.5.8).
It was asked to change the stacksize
I copy those lines in the Terminal 

echo 'limit stacksize 64M' >>~/.tcshrc
echo 'setenv PATH "${PATH}:/usr/local/bin"' >>~/.tcshrc 
/usr/local/bin/ocaml
echo 'limit stacksize 64M' >>~/.tcshrc

or

echo "source .bashrc" >> ~/.bash_profile
echo "export PATH=${PATH}:/usr/local/bin" >> ~/.bashrc
echo "ulimit -s 64000" >> ~/.bashrc
echo 'limit stacksize 64M' >>~/.bashrc

But now if I want to compute a simple diagram with metapost in Texshop, 
nothing :

"limit: stacksize: Can't set limit (Operation not permitted)" in the Console

If any of you could help me ...

Thank you !
--
http://tug.org/metapost/
(Continue reading)

source liu | 15 Nov 2011 03:54
Picon

a problem of label when using metapost

Hi all,

it has been quite a few years since i picked up, but i've picked up
metapost just for a short time.

It works almost right,  except for the case i want to insert label.

I'm sure the problem lies in it,  for i comment the label line, it
layout the exact figure i want to get(
without text of course).

1.  TeX
when it comes to the first line of
-------------------------------------------
label.top(btex *somethinghere* etex, z1)
-------------------------------------------

it would be fine,  but the situation changes when a second similar
label is invoking as above.

the error message is always be something like , >> mpx file can't be create.

2. LaTeX

it is said that one can changed the defaut TeX system by placing
%&latex at the beginning.

yet, it is true, except for it works not the same as i found through
the internet, which i found
%&latex is after vebatimtex,
(Continue reading)

Troy Henderson | 15 Nov 2011 17:53
Picon

Re: a problem of label when using metapost

Liu An,

A minimal MetaPost file for me using LaTeX labels and embedding fonts (so that
the resulting output is self-contained) might look like:

=== begin cut here ===

prologues:=3;
verbatimtex
%&latex
\documentclass{minimal}
\begin{document}
etex

beginfig(0);
...
label(btex *somethinghere* etex,origin);
...
endfig;

end

=== end cut here ===

This should work.  If it doesn't you might try manually making sure that MetaPost
is being called to use LaTeX to typeset the labels by

mpost -tex=latex foo.mp

--
(Continue reading)

Dan Luecking | 15 Nov 2011 18:40
Picon
Favicon

Re: a problem of label when using metapost

At 08:54 PM 11/14/2011, you wrote:

>i comment the label line, it
>layout the exact figure i want to get(
>without text of course).
>
>1.  TeX
>when it comes to the first line of
>-------------------------------------------
>label.top(btex *somethinghere* etex, z1)
>-------------------------------------------
>
>it would be fine,  but the situation changes when a second similar
>label is invoking as above.
>
>the error message is always be something like , >> mpx file can't be create.
>
>2. LaTeX
>
>it is said that one can changed the defaut TeX system by placing
>%&latex at the beginning.
>
>yet, it is true, except for it works not the same as i found through
>the internet, which i found
>%&latex is after vebatimtex,
>
>such as
>-----------------------------------------
>vebatimtex
>    %&latex
(Continue reading)

source liu | 16 Nov 2011 02:17
Picon

Re: a problem of label when using metapost

> % near the top of your .mp file:
> verbatimtex
>  %&latex
>  \documentclass{article}
>  % \usepackage commands here
>  \begin{document}
> etex
> %...
> % then later in your figure:
> label.top(btex *something here* etex, z1);
> label.bot(btex *something else* etex, z2);
> %...
> --------------------------------
>
> If that doesn't work, prepare a short, but complete,
> figure file that fails for you and include that in your
> next email.

almost the same structure as me, i'm afraid i cant give out figure except for
i comment all the labels.  i wrote this way it simple gave a error message
even on recognizing such control sequence as \documentclass.

and i find the
$tex mproof something.eps
gave me a error message, even with the eps which was generated without label(
eps seem to be correct, as i can include in tex file, or view with
imagemagick).

I've test on <tex mproof > on the computer in the work place, but it
still failed me on
(Continue reading)

source liu | 16 Nov 2011 02:23
Picon

Re: a problem of label when using metapost

Its really nice of you

> A minimal MetaPost file for me using LaTeX labels and embedding fonts (so that
> the resulting output is self-contained) might look like:

> === begin cut here ===
>
> prologues:=3;
> verbatimtex
> %&latex
> \documentclass{minimal}

which i used is *article* or *book* rather than
yours minimal,  and i do find reference on manuals or blogs
to support my choice.

> \begin{document}
> etex

almost the same, expect for my prologue goes here, after etex.

> beginfig(0);
> ...
> label(btex *somethinghere* etex,origin);
> ...
> endfig;
>
> end
>
> === end cut here ===
(Continue reading)


Gmane