lualatex / luamplib

generic TeX package - including MetaPost code in LuaTeX documents
http://ctan.org/pkg/luamplib
16 stars 11 forks source link

include btex...etex commands #1

Closed eroux closed 10 years ago

eroux commented 11 years ago

See http://tug.org/pipermail/lualatex-dev/2013-April/001504.html

dohyunkim commented 11 years ago

See also http://tug.org/pipermail/luatex/2013-May/004214.html

phi-gamma commented 11 years ago

Hans changed luatex-mplib.lua quite a bit since it was last imported -- wouldn’t it make more sense to first try and sync it with current Context? Compared to the font loader it will be bit harder to merge changes because everything is kept in a dtx, but not impossible.

eroux commented 11 years ago

Sure, an update is definitely something to do before any other test or improvements.

phi-gamma commented 11 years ago

I’ve just pulled the changes into luamplib.lua -- there weren’t really any major changes. Anyways I can’t test it because luatex dumps core on the tests:

luatex: ../../../texk/web2c/mplibdir/mp.w:5488: do_set_attr_head: Assertion `A->type==mp_structured' failed.
(./luamplib.lua))Aborted (core dumped)

which resembles this error from an earlier Context: http://www.ntg.nl/pipermail/ntg-context/2012/070567.html and it happens with Context from TL 2013 too, but not with the beta. Maybe a Luatex bug?

eroux commented 11 years ago

Hmm... this doesn't make things easy... is the LuaTeX binary in latest beta the same as in TeXLive 2013? If it's different, maybe we can ask Karl for an update of the binary? Otherwise, if it's the same, Hans should easily know how we could work it around...

phi-gamma commented 11 years ago

Context minimals:

[14:36:10=>phg@phlegethon=> ~] /home/phg/context/tex/texmf-linux-64/bin/luatex --version
This is LuaTeX, Version beta-0.76.0-2013040516  (TeX Live 2013/dev)(rev 4627)

TL pretest:

[14:37:15=>phg@phlegethon=> ~] /home/phg/src/texlive2013/bin/x86_64-linux/luatex --version
This is LuaTeX, Version beta-0.76.0-2013042316  (TeX Live 2013) (rev 4627)

Same revision.

eroux commented 11 years ago

So, at least theorically, there should be a way to make it work... Hans certainly remembers the chages, it seems the best source of information to me... Anyway, if there is no real bug in your code, this shouldn't happen so it's worth reporting in on LuaTeX bugtracker...

phi-gamma commented 11 years ago

False alarm. I just ran a full update of the pretest and now it works.

I created a gist of the style and lua file that I got mplib working with: https://gist.github.com/phi-gamma/5509115

Beware that I had to exclude % from the mplib catcode table because otherwise I’d get only empty strings on the Lua end. This must be solved otherwise.

eroux commented 11 years ago

I'm not sure having to exlude % is blocking, I think you can go ahead like this in a first time... are Kim's improvements easy to merge with it?

dohyunkim commented 11 years ago

I have imported btex ... etex code to latest luatex-mplib by Hans: http://ktug.org/~nomos/stuffs/luamplib.zip

phi-gamma commented 11 years ago

@dohyunkim Thank you, I will look into it.

eroux commented 11 years ago

@dohyunkim : I've made a first version of the merge here: https://github.com/eroux/luamplib, but I realized I have no test file... can you test it and provide one please?

dohyunkim commented 11 years ago

Hmm. I'm sorry that I have to say it does not work. Anyway, I have just included a test file into http://ktug.org/~nomos/stuffs/luamplib.zip

eroux commented 11 years ago

@dohyunkim I've made some modifications and adapated some code, but it still doesn't work... I have to say it's difficult for me to dig into the code. I can do it but I'm pretty sure you know it quite well already. As you have a github account, what about forking and making a pull request?

phi-gamma commented 11 years ago

I’m on it.

eroux commented 11 years ago

Ok. It almost works with my latest push (see the modified test file for LaTeX), but I now have weird errors in the pdf...

phi-gamma commented 11 years ago

@eroux can you test my master?

@dohyunkim thanks for the patches, just one comment: please next time don’t mix tabs and spaces, it made the patch hard to adapt.

eroux commented 11 years ago

@phi-gamma apart from a few easy to fix typos, it seems to work ok, I'll adapt it, thanx!

phi-gamma commented 11 years ago

I’ve just given you access to my repo, do what you think is best.

eroux commented 11 years ago

Thanks: I did the same changes as on my repo, but more slowly, so I managed to find the bug, it was because I changed

  \directlua{
    luamplib.settexboxes([===[\unexpanded{#1}]===])
  }%
  \directlua{
    local data = luamplib.gettexboxes([===[\unexpanded{#1}]===])
    luamplib.process(data)
  }%

to

  \directlua{
    luamplib.settexboxes([===[\unexpanded{#1}]===])
    local data = luamplib.gettexboxes([===[\unexpanded{#1}]===])
    luamplib.process(data)
  }%

I have to say I don't really understand why it makes such a bug... if you have an explanation I'd be glad to hear it, otherwise I think I'm done for today, you can continue if you want, and even upload on CTAN.

@dohyunkim can you test https://github.com/phi-gamma/luamplib?

phi-gamma commented 11 years ago

The difference is that each call to \directlua creates a new Lua closure that is compiled and evaluated at the end of the TeX group that is the argument to \directlua. While the Lua snippet is run, TeX is practically inactive. So you cannot do something like

\let\\=\relax
\directlua{
  tex.sprint"\\newcount\\foo"
  tex.count.foo = 23
  tex.sprint("·",tostring(tex.count.foo),"·")
}
\bye

but TeX has to take over again, even if it looks as though it remains idle:

\let\\=\relax
\directlua{
  tex.sprint"\\newcount\\foo"
}
%% end of closure; TeX kicks in and creates the register
\directlua{
  tex.count.foo = 23
  tex.sprint("·",tostring(tex.count.foo),"·")
}
\bye

Same goes for boxes and other TeX resources.

eroux commented 11 years ago

Ok, I see now... Thank you!

dohyunkim commented 11 years ago

Works great! Thanks a lot. BTW, what is the use of the macro \FV@hack?

eroux commented 11 years ago

I have to say I'm not sure, maybe the code is dead since we changed the environment. By the way, changing it we added a bug: https://github.com/lualatex/luamplib/issues/3. I'll be away this evening and tomorrow, if someone has time to look at this...