Hi Guys,
I'm a beginner of metapost. When I make figures by metapost, figures always appear at the bottom left corner of the layout. For example, I tried an example from 'Tutorial in MetaPost by Andre Heck' on Page 33, see:
But the plotted figure appear partly at the corner, see:
My computer is MacOS Mojave 10.14.5. And the version of metapost is kpathsea version 6.2.2, which was installed by macport. Actually this problem occurred several years ago, when I first tried metapost and then gave it up. I will appreciate if you can help me to solve this issue. Thanks in advance.
Zun
Graphics, Figures & Tables ⇒ metapost creates figure out of the border
-
- Posts: 2
- Joined: Mon Jul 15, 2019 11:46 am
-
- Posts: 2
- Joined: Mon Jul 15, 2019 11:46 am
metapost creates figure out of the border
Solved! After creating eps by 'mpost', user should use 'epstopdf' instead of 'ps2pdf'.
Seems the preview is not a good software to open eps file. And 'ps2pdf' doesn't work very well.
Seems the preview is not a good software to open eps file. And 'ps2pdf' doesn't work very well.
- Stefan Kottwitz
- Site Admin
- Posts: 10308
- Joined: Mon Mar 10, 2008 9:44 pm
metapost creates figure out of the border
Hi,
welcome to the forum!
Thank you for letting us know the solution you found. It can help other metapost users searching for a fix for such an issue.
I tried metapost myself, I just find TikZ more intuitive and readable. Here's a code example for such rotated triangles as in your figure, written by Martin Scharrer here:
It's a complete document, the picture code is pretty short too. The output:
It is an example from the TikZ gallery.
Stefan
welcome to the forum!
Thank you for letting us know the solution you found. It can help other metapost users searching for a fix for such an issue.
I tried metapost myself, I just find TikZ more intuitive and readable. Here's a code example for such rotated triangles as in your figure, written by Martin Scharrer here:
Code: Select all
\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz,ifthen}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (-60:12cm);
\coordinate (C) at (240:12cm);
\foreach \density in {20,30,...,160}{%
\draw[fill=MidnightBlue!\density] (A)--(B)--(C)--cycle;
\path
(A) coordinate (X)
-- (B) coordinate[pos=.15](A)
-- (C) coordinate[pos=.15](B)
-- (X) coordinate[pos=.15](C);
}
\end{tikzpicture}
\end{document}
It is an example from the TikZ gallery.
Stefan
LaTeX.org admin
- Ijon Tichy
- Posts: 640
- Joined: Mon Dec 24, 2018 10:12 am
metapost creates figure out of the border
With luaatex and luamplib it is very easy to add MetaPost-Code into a LaTeX document:
If you cannot use lualatex, but have to use xelatex or pdflatex, you can use package gmp:
But in this case you either have to run pdflatex or xelatex with option --shell-escape or follow the advice in the log-file to generate the MetaPost image between two LaTeX runs.
\documentclass{article} \usepackage{luamplib} \begin{document} \begin{mplibcode} beginfig(1); pair A,B,C; u:=3cm; A=u*dir(-30); B=u*dir(90); C=u*dir(210); transform T; A transformed T = 1/6[A,B]; B transformed T = 1/6[B,C]; C transformed T = 1/6[C,A]; path p; p = A--B--C--cycle; for i=0 upto 60: draw p; p:= p transformed T; endfor; endfig; \end{mplibcode} \end{document}
\documentclass{article} % See the gmp-manual for information about using % one of the following lines: \usepackage[shellescape]{gmp} %\usepackage[noshellescape]{gmp} %\usepackage[nowrite]{gmp} \begin{document} \begin{mpost} beginfig(1); pair A,B,C; u:=3cm; A=u*dir(-30); B=u*dir(90); C=u*dir(210); transform T; A transformed T = 1/6[A,B]; B transformed T = 1/6[B,C]; C transformed T = 1/6[C,A]; path p; p = A--B--C--cycle; for i=0 upto 60: draw p; p:= p transformed T; endfor; endfig; \end{mpost} \end{document}
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. 
