Re: [NTG-context] Using external libraries in LuaTeX

2010-03-19 Thread Taco Hoekwater

Graham Douglas wrote:


One question, in the minimal example below, the XML text:

text = 'elem1text elem2/ more text /elem1'

parses fine *if* on a single line. If I break the text onto multiple 
lines, eg


text = 'elem1text elem2/
 more text /elem1'



it fails with

! LuaTeX error main ctx instance:3: unfinished string near ''elem1   
text elem2/'.

} = lxp.new(callbacks)d

\dodostartluacode ...d \directlua \zerocount {#1}}

l.21 \stopluacode


Why is this --- is this a catcode issue?


No, not at all. Lua supports only single-line '' or  strings.


Can you suggest a fix?


Multi-line strings in Lua use square brackets

text = [[elem1text elem2/
 more text /elem1]]

See http://www.lua.org/manual/5.1/manual.html#2.1 for details.

Best wishes,
Taco
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Using external libraries in LuaTeX

2010-03-19 Thread luigi scarso
On Thu, Mar 18, 2010 at 11:29 PM, Graham Douglas
graham.doug...@readytext.co.uk wrote:
 Hi Luigi

 That is very cool work. At present, it is a bit beyond
 my fuzzy skills, but I will dfinitely keep a copy of your
 slides for future reference as I slowly get a bit
 more familiar with LuaTeX etc.

 Thanks for sharing that.

We have 2 ways to interface with an external program

1) \write18 . In this way (lua/pdf)tex  runs the program using the OS,
ie something like os.cmd, .
and a completely new task is created. We have a clear separation
between luatex process an program process
and usually if the program process aborts luatex can manage this
situation nicely.
It's robust but it's also slow, as  the case for mkii with metapost shown;

2) dynamic loading of a library, a *so or a *dll.
In  this case there is not another process to start: luatex is
extended with this new library at runtime.
So, if a the library aborts while you are calling a function, then
luatex aborts --- and you can't manage this situation.

Now, if your library declare a symbol that is also defined by luatex
or if you library has a function that load another
library at runtime and this one has a symbol that is also defined by
luatex , then you have a symbol collision and hence
with high probability a segfault . Trace the symbol collision can be
very hard, so actually it's less robust than 1)
(remember that *tex must be portable to many SO, so robustness  is
really important).

Of course there is a benefict: the  gain in speed  can be 1000 (one
thousand times)  and if I remember well,
Hans reported 1 with mplib (which is included in luatex at
compilation time ).




-- 
luigi
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Using external libraries in LuaTeX

2010-03-19 Thread Graham Douglas

 Why is this --- is this a catcode issue?

emotion feeling=DOHI need to read more
before asking stupid questions/mode

Thanks Taco, much appreciated as always.

Warm regards

Graham

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Using external libraries in LuaTeX

2010-03-19 Thread Graham Douglas

snip

Hi Luigi

Great stuff, thank you. If you ever had time to write an
article which really explained the underlying programming
concepts you demonstrated in your slides I am sure you would find a lot
of people interested to read it. I think the ability to extend LuaTeX
via Lua libraries really is a powerful feature. With LuaTeX there is so
much going on, so many fascinating possibilities to explore, that it 
needs people like you, and other experts on this list, to open the 
doors to the rest of us, by showing the big picture and how it all 
really fits together. Leaving Taco + Hans to keep writing the goodies :-)


But, of course, articles etc take much time to write and
we all have busy day jobs etc.

Once again, many thanks.

Graham

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Using external libraries in LuaTeX

2010-03-19 Thread luigi scarso
On Fri, Mar 19, 2010 at 7:29 PM, Graham Douglas
graham.doug...@readytext.co.uk wrote:
 snip

 Hi Luigi

 Great stuff, thank you. If you ever had time to write an
 article which really explained the underlying programming
 concepts you demonstrated in your slides I am sure you would find a lot
 of people interested to read it. I think the ability to extend LuaTeX
 via Lua libraries really is a powerful feature. With LuaTeX there is so
 much going on, so many fascinating possibilities to explore, that it needs
 people like you, and other experts on this list, to open the doors to the
 rest of us, by showing the big picture and how it all really fits
 together. Leaving Taco + Hans to keep writing the goodies :-)

 But, of course, articles etc take much time to write and
 we all have busy day jobs etc.
Well if you are really interested then you should
join ntg + tug  now.
My article --- as many others about luatex  mkiv --- is in the last
number of TUGBOAT

-- 
luigi
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Using external libraries in LuaTeX

2010-03-19 Thread Graham Douglas

Hi Luigi

Well if you are really interested then you should
join ntg + tug  now. My article --- as many others about luatex  mkiv 
--- is in the last number of TUGBOAT


-- already made TUG membership application, plus made a donation to the 
LuaTeX fund.


Warm regards

Graham


___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Using external libraries in LuaTeX

2010-03-18 Thread Taco Hoekwater

Hi,


Graham Douglas wrote:
 
 So, I was wondering if anyone has a minimal example they would be
 kind enough to share, or can give me a few pointers/guidelines so that I
 can start experimenting. In particular, I'm interested to call external
 libraries and inject the output from an external library into TeX for
 typesetting. For example, is it possible to load a library once, keep
 it loaded and access the library functions from different commands
 during the TeX run?

Here is a trivial example using LuaExpat:

\starttext
\startluacode
require lxp;
text = 'phello world/p'
callbacks = { EndElement = false,
  StartElement = false,
  Default = function (p, s) tex.sprint(s) end }
p = lxp.new(callbacks)
\stopluacode

Some xml output: \directlua{p:parse(text)}!.

\directlua{p:close()}
\stoptext

Disclosure: for this test, I copied lxp.so into the local directory
because I am not sure exactly how context mkiv searches for Lua cpath
files.

Best wishes,
Taco

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Using external libraries in LuaTeX

2010-03-18 Thread Graham Douglas

snip

Taco wrote:
=

Here is a trivial example using LuaExpat:

\starttext
\startluacode
require lxp;
text = 'phello world/p'
callbacks = { EndElement = false,
  StartElement = false,
  Default = function (p, s) tex.sprint(s) end }
p = lxp.new(callbacks)
\stopluacode

Some xml output: \directlua{p:parse(text)}!.

\directlua{p:close()}
\stoptext

=

Wonderful! Thanks Taco. Just for the record, for other Windows users,
to get this working I downloaded

luaexpat-1.1.win32-lua51.zip

from http://luaforge.net/projects/luaexpat/files

and from that I copied the following DLLs
(from luaexpat-1.1.win32-lua51.zip)

libexpat.dll
lxp.dll

into the following directory on my PC

C:\Context\tex\texmf-mswin\bin\lib\lua
(adapt to your ConText install)

One question, in the minimal example below, the XML text:

text = 'elem1text elem2/ more text /elem1'

parses fine *if* on a single line. If I break the text onto multiple 
lines, eg


text = 'elem1text elem2/
 more text /elem1'

it fails with

! LuaTeX error main ctx instance:3: unfinished string near ''elem1 
  text elem2/'.

} = lxp.new(callbacks)d

\dodostartluacode ...d \directlua \zerocount {#1}}

l.21 \stopluacode


Why is this --- is this a catcode issue?

Can you suggest a fix?

Once again, thank you, as always, for sharing your expertise.

Warm wishes

Graham



===
Minimal Example

\startluacode
require lxp;
text = 'elem1text elem2/ more text /elem1'
callbacks = {
StartElement = function (p, s)
tex.sprint(Starting element:  ..s)  
end,
EndElement = function (p, s)
tex.sprint(Finishing element:  ..s)
end,
CharacterData = function (p, s)
tex.sprint(s)
end
}
p = lxp.new(callbacks)
\stopluacode











___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Using external libraries in LuaTeX

2010-03-18 Thread Graham Douglas

Hi Luigi

That is very cool work. At present, it is a bit beyond
my fuzzy skills, but I will dfinitely keep a copy of your
slides for future reference as I slowly get a bit
more familiar with LuaTeX etc.

Thanks for sharing that.

Warm wishes

Graham

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


[NTG-context] Using external libraries in LuaTeX

2010-03-17 Thread Graham Douglas

Dear All

In a the recent Luatex 0.46.0 announcement

http://tug.org/pipermail/luatex/2009-November/001118.html

experimental support for loading external libraries was reported.

I am running Windows Vista with

ConTeXt  ver: 2010.03.12 19:49 MKIV  fmt: 2010.3.16  int: 
english/english with LuaTeX, Version beta-0.51.0-2010031309 (rev 3479)


I have also downloaded Lua 5.1 from http://luaforwindows.luaforge.net/
and so have Lua5.1.dll installed.

This distribution has a number of interesting extenal libraries
(ie DLLs) that I would like to try out with LuaTeX. If I can make 
progress I would be happy to document and write-up my experiments for 
posting on the Wiki in case they may be of interest to others. I should 
say that my coding skills are somewhat rusty as I've been away from 
programming/TeX for a few years... so do please excuse my simplistic

questions :-)

So, I was wondering if anyone has a minimal example they would be
kind enough to share, or can give me a few pointers/guidelines so that I 
can start experimenting. In particular, I'm interested to call external
libraries and inject the output from an external library into TeX for 
typesetting. For example, is it possible to load a library once, keep
it loaded and access the library functions from different commands 
during the TeX run?


In outline...

--- run some code to load the library (initialisation)
--- keeping the library available
--- some commands\definitions to accss library functions
eg \calltolibrary{)

--- make callsto library and pass the output into TeX for
typesetting

I would be very grateful for any guidance/help that can be offered.

Warm wishes to all

Graham



___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Using external libraries in LuaTeX

2010-03-17 Thread luigi scarso
On Thu, Mar 18, 2010 at 1:10 AM, Graham Douglas
graham.doug...@readytext.co.uk wrote:
 Dear All

 In a the recent Luatex 0.46.0 announcement

 http://tug.org/pipermail/luatex/2009-November/001118.html

 experimental support for loading external libraries was reported.

 I am running Windows Vista with

 ConTeXt  ver: 2010.03.12 19:49 MKIV  fmt: 2010.3.16  int: english/english
 with LuaTeX, Version beta-0.51.0-2010031309 (rev 3479)

 I have also downloaded Lua 5.1 from http://luaforwindows.luaforge.net/
 and so have Lua5.1.dll installed.

 This distribution has a number of interesting extenal libraries
 (ie DLLs) that I would like to try out with LuaTeX. If I can make progress I
 would be happy to document and write-up my experiments for posting on the
 Wiki in case they may be of interest to others. I should say that my coding
 skills are somewhat rusty as I've been away from programming/TeX for a few
 years... so do please excuse my simplistic
 questions :-)

 So, I was wondering if anyone has a minimal example they would be
 kind enough to share, or can give me a few pointers/guidelines so that I can
 start experimenting. In particular, I'm interested to call external
 libraries and inject the output from an external library into TeX for
 typesetting. For example, is it possible to load a library once, keep
 it loaded and access the library functions from different commands during
 the TeX run?

 In outline...

 --- run some code to load the library (initialisation)
 --- keeping the library available
 --- some commands\definitions to accss library functions
 eg \calltolibrary{)

 --- make callsto library and pass the output into TeX for
 typesetting

 I would be very grateful for any guidance/help that can be offered.

http://www.ntg.nl/EuroTeX2009/slides/luigi-slides.pdf


-- 
luigi
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___