ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* directlua in xml-environment
@ 2016-11-13 13:56 Meer, Hans van der
  2016-11-13 17:23 ` Hans Hagen
  0 siblings, 1 reply; 4+ messages in thread
From: Meer, Hans van der @ 2016-11-13 13:56 UTC (permalink / raw)
  To: NTG ConTeXt

Here is something I do not understand. Possibly I am doing something wrong.

The following code is fine, within <<>> the current contextversion is printed.
  \def\mymacro{\directlua{tex.print("\\contextversion")}}
  \starttext
   calling mymacro <<\mymacro>>\par
  \stoptext

However calling \mymacro from inside \startxmlsetup .. \stopxmlsetup does not work and results in <<\contextversion>>. I guess that the catcode regime in that environment is to blame.
But how do I change that in order to get things working? I looked into the LuaTeX-manual where catcodes in relation to tex.print are treated, but in vain and could not find how to.

What do I have to change?

Hans van der Meer




___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: directlua in xml-environment
  2016-11-13 13:56 directlua in xml-environment Meer, Hans van der
@ 2016-11-13 17:23 ` Hans Hagen
  2016-11-14  8:50   ` Meer, Hans van der
  0 siblings, 1 reply; 4+ messages in thread
From: Hans Hagen @ 2016-11-13 17:23 UTC (permalink / raw)
  To: ntg-context

On 11/13/2016 2:56 PM, Meer, Hans van der wrote:
> Here is something I do not understand. Possibly I am doing something wrong.
>
> The following code is fine, within <<>> the current contextversion is printed.
>   \def\mymacro{\directlua{tex.print("\\contextversion")}}
>   \starttext
>    calling mymacro <<\mymacro>>\par
>   \stoptext
>
> However calling \mymacro from inside \startxmlsetup .. \stopxmlsetup does not work and results in <<\contextversion>>. I guess that the catcode regime in that environment is to blame.
> But how do I change that in order to get things working? I looked into the LuaTeX-manual where catcodes in relation to tex.print are treated, but in vain and could not find how to.
>
> What do I have to change?
\starttexcode
  ...
\stoptexcode

> Hans van der Meer
>
>
>
>
> ___________________________________________________________________________________
> 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://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
>


-- 

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: directlua in xml-environment
  2016-11-13 17:23 ` Hans Hagen
@ 2016-11-14  8:50   ` Meer, Hans van der
  2016-11-17  8:57     ` Hans Hagen
  0 siblings, 1 reply; 4+ messages in thread
From: Meer, Hans van der @ 2016-11-14  8:50 UTC (permalink / raw)
  To: NTG ConTeXt

Beste Hans,

Je bent weer terug, alles goed met je, hoop ik.
Twee opmerkingen hier.

(1) Inmiddels na veel pogingen ook een andere oplossing gevonden: tex.print(0,string) i.p.v. tex.print(string). Het duurde nogal lang voordat ik doorhad wat het LuaTeX-manual bedoelde. De truc met tex.print(0,string) bleek nodig om een comma-list komend uit een \xmlatt te kunnen verwerken. Ik heb het zo opgelost, misschien iet de beste manier maar het werkt wel:
-- Return comma separated list called with macro name:
	hvdm.commalist = function (name, argument)
		local s
		for s in string.gmatch(argument,"%a+") do
			tex.print(0,"\\"..name.."{"..s.."}")
		end
	end
in een macro aangeroepen met: \directlua{hvdm.commalist("name","#1")}

(2) Ik heb de door mij aangevulde \xmlchainatt en \xmlchainattdef in een aantal situaties gebruikt en zo te zien werkt het nu zoals ik uit de xml-mkiv manual begrijp: afbreken zodra er een match is en in geval van ..def de default teruggeven. Ik recapituleer voor het gemak nog even de veranderingen in lxml-tex.lua, in mijn versie vanaf regel 1407:

local function chainattribute(collected,arguments,default) -- AANGEVULD MET ,default
    if collected and #collected > 0 then
        local e = collected[1]
        while e do
            local at = e.at
            if at then
                local a = at[arguments]
                if a then
                    contextsprint(notcatcodes,a)
                    return				-- RETURN TOEGEVOEGD
                end
            else
                break -- error
            end
            e = e.__p__
        end
    end
    if default then					-- DEZE IF TOEGEVOEGD
    	contextsprint(notcatcodes,default)
    end
end

Ik hoop dat het de weg naar de volgende beta vindt en dat ik hiermee weer een bescheiden bijdrage heb kunnen leveren aan het ConTeXt-'kunstwerk'.

met vriendelijke groet
Hans van der Meer




> On 13 Nov 2016, at 18:23, Hans Hagen <pragma@wxs.nl> wrote:
> 
> On 11/13/2016 2:56 PM, Meer, Hans van der wrote:
>> Here is something I do not understand. Possibly I am doing something wrong.
>> 
>> The following code is fine, within <<>> the current contextversion is printed.
>>  \def\mymacro{\directlua{tex.print("\\contextversion")}}
>>  \starttext
>>   calling mymacro <<\mymacro>>\par
>>  \stoptext
>> 
>> However calling \mymacro from inside \startxmlsetup .. \stopxmlsetup does not work and results in <<\contextversion>>. I guess that the catcode regime in that environment is to blame.
>> But how do I change that in order to get things working? I looked into the LuaTeX-manual where catcodes in relation to tex.print are treated, but in vain and could not find how to.
>> 
>> What do I have to change?
> \starttexcode
> ...
> \stoptexcode
> 
>> Hans van der Meer
>> 
>> 
>> 
>> 

___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: directlua in xml-environment
  2016-11-14  8:50   ` Meer, Hans van der
@ 2016-11-17  8:57     ` Hans Hagen
  0 siblings, 0 replies; 4+ messages in thread
From: Hans Hagen @ 2016-11-17  8:57 UTC (permalink / raw)
  To: ntg-context

On 11/14/2016 9:50 AM, Meer, Hans van der wrote:
> Beste Hans,
>
> Je bent weer terug, alles goed met je, hoop ik.
> Twee opmerkingen hier.
>
> (1) Inmiddels na veel pogingen ook een andere oplossing gevonden: tex.print(0,string) i.p.v. tex.print(string). Het duurde nogal lang voordat ik doorhad wat het LuaTeX-manual bedoelde. De truc met tex.print(0,string) bleek nodig om een comma-list komend uit een \xmlatt te kunnen verwerken. Ik heb het zo opgelost, misschien iet de beste manier maar het werkt wel:
> -- Return comma separated list called with macro name:
> 	hvdm.commalist = function (name, argument)
> 		local s
> 		for s in string.gmatch(argument,"%a+") do
> 			tex.print(0,"\\"..name.."{"..s.."}")
> 		end
> 	end
> in een macro aangeroepen met: \directlua{hvdm.commalist("name","#1")}

\startluacode
     context.sprint(tex.ctxcatcodes,"line ",1,"\\par","line ",2)
\stopluacode



> (2) Ik heb de door mij aangevulde \xmlchainatt en \xmlchainattdef in een aantal situaties gebruikt en zo te zien werkt het nu zoals ik uit de xml-mkiv manual begrijp: afbreken zodra er een match is en in geval van ..def de default teruggeven. Ik recapituleer voor het gemak nog even de veranderingen in lxml-tex.lua, in mijn versie vanaf regel 1407:
>
> local function chainattribute(collected,arguments,default) -- AANGEVULD MET ,default
>     if collected and #collected > 0 then
>         local e = collected[1]
>         while e do
>             local at = e.at
>             if at then
>                 local a = at[arguments]
>                 if a then
>                     contextsprint(notcatcodes,a)
>                     return				-- RETURN TOEGEVOEGD
>                 end
>             else
>                 break -- error
>             end
>             e = e.__p__
>         end
>     end
>     if default then					-- DEZE IF TOEGEVOEGD
>     	contextsprint(notcatcodes,default)
>     end
> end
>
> Ik hoop dat het de weg naar de volgende beta vindt en dat ik hiermee weer een bescheiden bijdrage heb kunnen leveren aan het ConTeXt-'kunstwerk'.

Ok

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-11-17  8:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-13 13:56 directlua in xml-environment Meer, Hans van der
2016-11-13 17:23 ` Hans Hagen
2016-11-14  8:50   ` Meer, Hans van der
2016-11-17  8:57     ` Hans Hagen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).