<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.luatex.org/index.php?action=history&amp;feed=atom&amp;title=Metapost_with_LuaTeX</id>
	<title>Metapost with LuaTeX - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.luatex.org/index.php?action=history&amp;feed=atom&amp;title=Metapost_with_LuaTeX"/>
	<link rel="alternate" type="text/html" href="https://wiki.luatex.org/index.php?title=Metapost_with_LuaTeX&amp;action=history"/>
	<updated>2026-04-19T10:42:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.luatex.org/index.php?title=Metapost_with_LuaTeX&amp;diff=35&amp;oldid=prev</id>
		<title>Patrick: Copied from the old bluwiki.com luatex wiki</title>
		<link rel="alternate" type="text/html" href="https://wiki.luatex.org/index.php?title=Metapost_with_LuaTeX&amp;diff=35&amp;oldid=prev"/>
		<updated>2010-12-07T21:27:15Z</updated>

		<summary type="html">&lt;p&gt;Copied from the old bluwiki.com luatex wiki&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Writing directly some metapost code is now possible in LuaTeX, through MPLib. It only works in pdf mode.&lt;br /&gt;
&lt;br /&gt;
To get it working, you will need three files: [http://source.contextgarden.net/tex/context/base/supp-mpl.lua supp-mpl.lua] and [http://source.contextgarden.net/tex/context/base/supp-mpl.tex supp-mpl.tex] (you need to copy/paste them) from the ConTeXt distribution, and a stupid .sty file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
\NeedsTeXFormat{LaTeX2e}&lt;br /&gt;
\ProvidesPackage{mplib}&lt;br /&gt;
&lt;br /&gt;
\input supp-mpl.tex&lt;br /&gt;
&lt;br /&gt;
\directlua0{dofile(kpse.find_file(&amp;quot;formathack.lua&amp;quot;))}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And create a file formathack.lua containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
local preamble = [[&lt;br /&gt;
input %s ; dump ;&lt;br /&gt;
]]&lt;br /&gt;
metapost.make = function (name, mem_name)&lt;br /&gt;
    local mpx = mplib.new {&lt;br /&gt;
        ini_version = true,&lt;br /&gt;
        find_file = metapost.finder,&lt;br /&gt;
        job_name =  name}&lt;br /&gt;
    if mpx then&lt;br /&gt;
        local result = mpx:execute(string.format(preamble,name))&lt;br /&gt;
        mpx:finish()&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
function replacesuffix(filename, suffix)&lt;br /&gt;
  return (string.gsub(filename,&amp;quot;%.[%a%d]+$&amp;quot;,&amp;quot;&amp;quot;)) .. &amp;quot;.&amp;quot; .. suffix&lt;br /&gt;
end&lt;br /&gt;
metapost.load = function (name)&lt;br /&gt;
    local mpx = mplib.new {&lt;br /&gt;
            ini_version = false,&lt;br /&gt;
            mem_name = replacesuffix(name,&amp;quot;mem&amp;quot;),&lt;br /&gt;
            find_file = finder&lt;br /&gt;
        }&lt;br /&gt;
    local result&lt;br /&gt;
    if not mpx then&lt;br /&gt;
        metapost.make(name)&lt;br /&gt;
        metapost.report(&amp;quot;creating %s.mem&amp;quot;, name)&lt;br /&gt;
        mpx = mplib.new {&lt;br /&gt;
            ini_version = false,&lt;br /&gt;
            mem_name = replacesuffix(name,&amp;quot;mem&amp;quot;),&lt;br /&gt;
            find_file = finder&lt;br /&gt;
        }&lt;br /&gt;
    end&lt;br /&gt;
    if not mpx then&lt;br /&gt;
        result = { status = 99, error = &amp;quot;out of memory&amp;quot;}&lt;br /&gt;
    end&lt;br /&gt;
    return mpx, result&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have all four files, the following example should work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
\mplibcode&lt;br /&gt;
beginfig(1);&lt;br /&gt;
pickup pencircle xscaled 5 rotated 30;&lt;br /&gt;
draw unitsquare scaled 20 withcmykcolor (0.3,0.4,0.6,0);&lt;br /&gt;
endfig;&lt;br /&gt;
\endmplibcode &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
as well as any metapost code.&lt;/div&gt;</summary>
		<author><name>Patrick</name></author>
		
	</entry>
</feed>