Help with MetaPost and Metaobj with latex

Kind help with two examples to do metapost and metaobj in latex running from Texicenter.

what packages to include and program two examples

I read through book not able to understand.

First

input metafun

draw fulldiamond scaled 1cm withcolor blue;


second

input metaobj

nczigzag(a)(b);
nczigzag(a)(b)
"angleA(-90)","angleB(120)",
"linetension(0.8)","coilwidth(2mm)",
"linearc(0.1mm)";
drawObj(a,b);


Below code not working help

\documentclass{article}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
input test.mp
\end{mplibcode}
\end{document}


where test.mp

beginfig(1) ;
draw fulldiamond scaled 1cm withcolor blue ;
endfig ;
end ;


Then ran it in in LuLatex but errors and output not coming

second if in the above in above instead of test.mp as above code

if we have test.mp as

input metaobj
beginfig(1) ;
newCircle.a(btex A etex) ;
newCircle.b(btex B etex) ;
a.c=origin ;
b.c=(3cm,2cm) ;
nczigzag(a)(b) ;
nczigzag(a)(b) "angleA(-90)","angleB(120)",
"linetension(0.8)",
"coilwidth(2mm)", "linearc(0.1mm)" ;
drawObj(a,b) ;
endfig ;
end ;


How to run without errors Kind help

• You will find an answer to your first question in tex.stackexchange.com/questions/454934/… – sztruks Jan 19 at 16:11
• Is it possible to create frame like slide (like beamer slides) when we fun as metafun IF so help with an example with above two in two different frames – sriram Jan 22 at 5:03
• This is a new question. Please ask it as a separate question. – sztruks Jan 22 at 7:22

MetaFun

MetaFun are not macros which can be input, but it is another format (sort of like Plain TeX vs. LaTeX). So to run a file with MetaFun you have to preload the format with mpost '&metafun' test.mp.

beginfig(1) ;
draw fulldiamond scaled 1cm withcolor blue ;
endfig ;
end ;


MetaObj

Your MetaObj example can't work because you are trying to connect objects a and b which do not exist. I just made two circles and placed them somewhere.

input metaobj

beginfig(1) ;
newCircle.a(btex A etex) ;
newCircle.b(btex B etex) ;
a.c=origin ;
b.c=(3cm,2cm) ;
nczigzag(a)(b) ;
nczigzag(a)(b) "angleA(-90)","angleB(120)",
"linetension(0.8)",
"coilwidth(2mm)", "linearc(0.1mm)" ;
drawObj(a,b) ;
endfig ;
end ;


Embedding the figures in a document

You tagged the question with , so we can use luamplib. Since MetaFun is actually a superset of plain MetaPost, we can globally switch the format to MetaFun using \mplibsetformat{metafun}. We also add some convenience code in \everymplib and \everyendmplib so we don't have to type beginfig and endfig every time and the picture will always be in horizontal mode.

\documentclass{beamer}
\usepackage{luamplib}

\mplibsetformat{metafun}

\everymplib{
verbatimtex \leavevmode etex ;
beginfig(0) ;
}
\everyendmplib{
endfig ;
}

\begin{document}

\begin{frame}
\begin{mplibcode}
draw fulldiamond scaled 1cm withcolor blue ;
\end{mplibcode}
\end{frame}

\begin{frame}
\begin{mplibcode}
input metaobj ;

newCircle.a(btex A etex) ;
newCircle.b(btex B etex) ;
a.c=origin ;
b.c=(3cm,2cm) ;
nczigzag(a)(b) ;
nczigzag(a)(b) "angleA(-90)","angleB(120)",
"linetension(0.8)",
"coilwidth(2mm)", "linearc(0.1mm)" ;
drawObj(a,b) ;
\end{mplibcode}
\end{frame}

\end{document}


• Is it possible to create frame like slide (like beamer slides) when we fun as metafun IF so help with an example with above two in two different frames – sriram Jan 22 at 3:46
• @sriram In LaTeX or in plain MetaPost? – Henri Menke Jan 22 at 6:47