Re: [NTG-context] Compare contents of macros via \doif etc. alternatives
On 7/23/2017 8:46 AM, Henri Menke wrote: On 07/23/2017 05:55 PM, Jaroslav Hajtmar wrote: Thanx Hans for reply. also, it depends on what you want to achieve ... maybe comparing macros is not needed at all You have right, that anytime compares are not needed, but for my very needed compares is not working in next eight examples. Problem is in expansions macros with optional argument. For “normal” macros are compares without problem as you see in last four examples…. Did you read my first reply? Scanning for optional arguments is _inherently_ unexpandable. Peeking ahead _always_ involves \futurelet which performs an assignment. This can _never_ be edef-expanded. indeed. fwiw, one can do some trickery with lua (read and push back) but even then you run into the fact that when reading a token expansion happens (so the expanded stuff is then in front) Hans - 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 ___
Re: [NTG-context] Compare contents of macros via \doif etc. alternatives
On 07/23/2017 05:55 PM, Jaroslav Hajtmar wrote: > > Thanx Hans for reply. > >> >> also, it depends on what you want to achieve ... maybe comparing macros is >> not needed at all > > You have right, that anytime compares are not needed, but for my very needed > compares is not working in next eight examples. Problem is in expansions > macros with optional argument. For “normal” macros are compares without > problem as you see in last four examples…. Did you read my first reply? Scanning for optional arguments is _inherently_ unexpandable. Peeking ahead _always_ involves \futurelet which performs an assignment. This can _never_ be edef-expanded. > > > mymacro > > \doifelse{\mymacro}{123}{equal content}{not equal content} > > \doifsamestringelse{\mymacro}{123}{equal content}{not equal content} > > \doifinstringelse{\mymacro}{123}{equal content}{not equal content} > > \doifincsnameelse{\mymacro}{123}{equal content}{not equal content} > > > \hairline > > mymacro[123] > > \doifelse{\mymacro[123]}{123}{equal content}{not equal content} > > \doifsamestringelse{\mymacro[123]}{123}{equal content}{not equal content} > > \doifinstringelse{\mymacro[123]}{123}{equal content}{not equal content} > > \doifincsnameelse{\mymacro[123]}{123}{equal content}{not equal content} > > > > \hairline > > > myothermacro > > \doifelse{\myothermacro}{123}{equal content}{not equal content} > > \doifsamestringelse{\myothermacro}{123}{equal content}{not equal content} > > \doifinstringelse{\myothermacro}{123}{equal content}{not equal content} > > \doifincsnameelse{\myothermacro}{123}{equal content}{not equal content} > > >> >> there is not that much benefit defining these at the lua end if you directly >> feed back into tex anyway > > sure, but I need define some macros automatically from luacode (is part of > custom lua library) > > Thanx > Jaroslav Hajtmar > > > > >> 22. 7. 2017 v 13:23, Hans Hagen <pra...@wxs.nl <mailto:pra...@wxs.nl>>: >> >> On 7/22/2017 3:58 AM, Henri wrote: >>> On Fri, 2017-07-21 at 11:25 +, Jaroslav Hajtmar wrote: >>>> Hello ConTeXist. >>>> Is there any way to evaluate of contents of two macros as I am showing in >>>> my minimal example? >>>> I know, that problem is in expansion, but I dont know to resolve it. >>>> My minimal example consist of piece lua code, because I am solving my >>>> problem in mixed codes (TeX >>>> & Lua) >>> Something similar has been asked before and it is not possible. The >>> interfaces.definecommand >>> function defines a new macro using \protected\def. To compare as equal in >>> a \doif context, both >>> operands have to _expand_ to the same thing (here 123). Here \mymacro is >>> not expandable and thus >>> only \doifelse{\mymacro}{\mymacro} will ever compare true. >>> Furthermore, scanning for optional arguments (i.e. [...]) is inherently >>> non-expandable. To get >>> something expandable you must at least switch to mandatory arguments (i.e. >>> {...}). Still, using >>> interfaces.definecommand will still not be possible. I believe that >>> scanning arguments is better >>> done on the macro level than in Lua, but that's just my opinion. >> >> also, it depends on what you want to achieve ... maybe comparing macros is >> not needed at all >> >>>> Thanx for help. >>>> Jaroslav Hajtmar >>>>\starttext >>>> \startluacode >>>> interfaces.definecommand ("domymacro", { >>>> arguments = { { "option", "string" } }, >>>> macro = function (opt_1) >>>>if #opt_1>0 then >>>>context(opt_1) >>>>else >>>>context("123") >>>>end >>>> end >>>>}) >>>> interfaces.definecommand("mymacro", { >>>> macro = function () >>>> context.dosingleempty() >>>> context["domymacro"]() >>>> end >>>>}) >>>> \stopluacode >> >> there is not that much
Re: [NTG-context] Compare contents of macros via \doif etc. alternatives
Thanx Hans for reply. also, it depends on what you want to achieve ... maybe comparing macros is not needed at all You have right, that anytime compares are not needed, but for my very needed compares is not working in next eight examples. Problem is in expansions macros with optional argument. For “normal” macros are compares without problem as you see in last four examples…. mymacro \doifelse{\mymacro}{123}{equal content}{not equal content} \doifsamestringelse{\mymacro}{123}{equal content}{not equal content} \doifinstringelse{\mymacro}{123}{equal content}{not equal content} \doifincsnameelse{\mymacro}{123}{equal content}{not equal content} \hairline mymacro[123] \doifelse{\mymacro[123]}{123}{equal content}{not equal content} \doifsamestringelse{\mymacro[123]}{123}{equal content}{not equal content} \doifinstringelse{\mymacro[123]}{123}{equal content}{not equal content} \doifincsnameelse{\mymacro[123]}{123}{equal content}{not equal content} \hairline myothermacro \doifelse{\myothermacro}{123}{equal content}{not equal content} \doifsamestringelse{\myothermacro}{123}{equal content}{not equal content} \doifinstringelse{\myothermacro}{123}{equal content}{not equal content} \doifincsnameelse{\myothermacro}{123}{equal content}{not equal content} there is not that much benefit defining these at the lua end if you directly feed back into tex anyway sure, but I need define some macros automatically from luacode (is part of custom lua library) Thanx Jaroslav Hajtmar 22. 7. 2017 v 13:23, Hans Hagen <pra...@wxs.nl<mailto:pra...@wxs.nl>>: On 7/22/2017 3:58 AM, Henri wrote: On Fri, 2017-07-21 at 11:25 +, Jaroslav Hajtmar wrote: Hello ConTeXist. Is there any way to evaluate of contents of two macros as I am showing in my minimal example? I know, that problem is in expansion, but I dont know to resolve it. My minimal example consist of piece lua code, because I am solving my problem in mixed codes (TeX & Lua) Something similar has been asked before and it is not possible. The interfaces.definecommand function defines a new macro using \protected\def. To compare as equal in a \doif context, both operands have to _expand_ to the same thing (here 123). Here \mymacro is not expandable and thus only \doifelse{\mymacro}{\mymacro} will ever compare true. Furthermore, scanning for optional arguments (i.e. [...]) is inherently non-expandable. To get something expandable you must at least switch to mandatory arguments (i.e. {...}). Still, using interfaces.definecommand will still not be possible. I believe that scanning arguments is better done on the macro level than in Lua, but that's just my opinion. also, it depends on what you want to achieve ... maybe comparing macros is not needed at all Thanx for help. Jaroslav Hajtmar \starttext \startluacode interfaces.definecommand ("domymacro", { arguments = { { "option", "string" } }, macro = function (opt_1) if #opt_1>0 then context(opt_1) else context("123") end end }) interfaces.definecommand("mymacro", { macro = function () context.dosingleempty() context["domymacro"]() end }) \stopluacode there is not that much benefit defining these at the lua end if you directly feed back into tex anyway \def\myothermacro{123} \hairline \mymacro[123] \mymacro \myothermacro \hairline \doifelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} \doifsamestringelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} \doifinstringelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} \doifincsnameelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} \hairline \doifelse{\mymacro}{\myothermacro}{equal content}{not equal content} \doifsamestringelse{\mymacro}{\myothermacro}{equal content}{not equal content} \doifinstringelse{\mymacro}{\myothermacro}{equal content}{not equal content} \doifincsnameelse{\mymacro}{\myothermacro}{equal content}{not equal content} \stoptext ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl<mailto: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 ___ __
[NTG-context] Compare contents of macros via \doif etc. alternatives
Hello ConTeXist. Is there any way to evaluate of contents of two macros as I am showing in my minimal example? I know, that problem is in expansion, but I dont know to resolve it. My minimal example consist of piece lua code, because I am solving my problem in mixed codes (TeX & Lua) Thanx for help. Jaroslav Hajtmar \starttext \startluacode interfaces.definecommand ("domymacro", { arguments = { { "option", "string" } }, macro = function (opt_1) if #opt_1>0 then context(opt_1) else context("123") end end }) interfaces.definecommand("mymacro", { macro = function () context.dosingleempty() context["domymacro"]() end }) \stopluacode \def\myothermacro{123} \hairline \mymacro[123] \mymacro \myothermacro \hairline \doifelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} \doifsamestringelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} \doifinstringelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} \doifincsnameelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} \hairline \doifelse{\mymacro}{\myothermacro}{equal content}{not equal content} \doifsamestringelse{\mymacro}{\myothermacro}{equal content}{not equal content} \doifinstringelse{\mymacro}{\myothermacro}{equal content}{not equal content} \doifincsnameelse{\mymacro}{\myothermacro}{equal content}{not equal content} \stoptext ___ 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 ___
Re: [NTG-context] Compare contents of macros via \doif etc. alternatives
On 7/22/2017 3:58 AM, Henri wrote: On Fri, 2017-07-21 at 11:25 +, Jaroslav Hajtmar wrote: Hello ConTeXist. Is there any way to evaluate of contents of two macros as I am showing in my minimal example? I know, that problem is in expansion, but I dont know to resolve it. My minimal example consist of piece lua code, because I am solving my problem in mixed codes (TeX & Lua) Something similar has been asked before and it is not possible. The interfaces.definecommand function defines a new macro using \protected\def. To compare as equal in a \doif context, both operands have to _expand_ to the same thing (here 123). Here \mymacro is not expandable and thus only \doifelse{\mymacro}{\mymacro} will ever compare true. Furthermore, scanning for optional arguments (i.e. [...]) is inherently non-expandable. To get something expandable you must at least switch to mandatory arguments (i.e. {...}). Still, using interfaces.definecommand will still not be possible. I believe that scanning arguments is better done on the macro level than in Lua, but that's just my opinion. also, it depends on what you want to achieve ... maybe comparing macros is not needed at all Thanx for help. Jaroslav Hajtmar \starttext \startluacode interfaces.definecommand ("domymacro", { arguments = { { "option", "string" } }, macro = function (opt_1) if #opt_1>0 then context(opt_1) else context("123") end end }) interfaces.definecommand("mymacro", { macro = function () context.dosingleempty() context["domymacro"]() end }) \stopluacode there is not that much benefit defining these at the lua end if you directly feed back into tex anyway \def\myothermacro{123} \hairline \mymacro[123] \mymacro \myothermacro \hairline \doifelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} \doifsamestringelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} \doifinstringelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} \doifincsnameelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} \hairline \doifelse{\mymacro}{\myothermacro}{equal content}{not equal content} \doifsamestringelse{\mymacro}{\myothermacro}{equal content}{not equal content} \doifinstringelse{\mymacro}{\myothermacro}{equal content}{not equal content} \doifincsnameelse{\mymacro}{\myothermacro}{equal content}{not equal content} \stoptext ___ 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 ___ ___ 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 ___
Re: [NTG-context] Compare contents of macros via \doif etc. alternatives
Thanks to Henri for the answer. To I admit, I thought it a bit technically that it would not be technically possible. At least I know why I was tearing my teeth while trying to test ... One more thanx. Jaroslav Hajtmar Dne 22.07.17 3:58, ntg-context za uživatele Henri <ntg-context-boun...@ntg.nl za uživatele henrime...@gmail.com> napsal(a): On Fri, 2017-07-21 at 11:25 +, Jaroslav Hajtmar wrote: > Hello ConTeXist. > Is there any way to evaluate of contents of two macros as I am showing in my minimal example? > I know, that problem is in expansion, but I dont know to resolve it. > My minimal example consist of piece lua code, because I am solving my problem in mixed codes (TeX > & Lua) Something similar has been asked before and it is not possible. The interfaces.definecommand function defines a new macro using \protected\def. To compare as equal in a \doif context, both operands have to _expand_ to the same thing (here 123). Here \mymacro is not expandable and thus only \doifelse{\mymacro}{\mymacro} will ever compare true. Furthermore, scanning for optional arguments (i.e. [...]) is inherently non-expandable. To get something expandable you must at least switch to mandatory arguments (i.e. {...}). Still, using interfaces.definecommand will still not be possible. I believe that scanning arguments is better done on the macro level than in Lua, but that's just my opinion. > Thanx for help. > Jaroslav Hajtmar > > > \starttext > > \startluacode > interfaces.definecommand ("domymacro", { > arguments = { { "option", "string" } }, > macro = function (opt_1) >if #opt_1>0 then >context(opt_1) >else >context("123") >end > end >}) > interfaces.definecommand("mymacro", { > macro = function () > context.dosingleempty() > context["domymacro"]() > end >}) > \stopluacode > > \def\myothermacro{123} > > \hairline > > \mymacro[123] > > \mymacro > > \myothermacro > > \hairline > > \doifelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} > > \doifsamestringelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} > > \doifinstringelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} > > \doifincsnameelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} > > > \hairline > > \doifelse{\mymacro}{\myothermacro}{equal content}{not equal content} > > \doifsamestringelse{\mymacro}{\myothermacro}{equal content}{not equal content} > > \doifinstringelse{\mymacro}{\myothermacro}{equal content}{not equal content} > > \doifincsnameelse{\mymacro}{\myothermacro}{equal content}{not equal content} > > > > \stoptext > > > > ___ > 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 > ___ ___ 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 ___ ___ 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 ___
Re: [NTG-context] Compare contents of macros via \doif etc. alternatives
On Fri, 2017-07-21 at 11:25 +, Jaroslav Hajtmar wrote: > Hello ConTeXist. > Is there any way to evaluate of contents of two macros as I am showing in my > minimal example? > I know, that problem is in expansion, but I dont know to resolve it. > My minimal example consist of piece lua code, because I am solving my problem > in mixed codes (TeX > & Lua) Something similar has been asked before and it is not possible. The interfaces.definecommand function defines a new macro using \protected\def. To compare as equal in a \doif context, both operands have to _expand_ to the same thing (here 123). Here \mymacro is not expandable and thus only \doifelse{\mymacro}{\mymacro} will ever compare true. Furthermore, scanning for optional arguments (i.e. [...]) is inherently non-expandable. To get something expandable you must at least switch to mandatory arguments (i.e. {...}). Still, using interfaces.definecommand will still not be possible. I believe that scanning arguments is better done on the macro level than in Lua, but that's just my opinion. > Thanx for help. > Jaroslav Hajtmar > > > \starttext > > \startluacode > interfaces.definecommand ("domymacro", { > arguments = { { "option", "string" } }, > macro = function (opt_1) > if #opt_1>0 then > context(opt_1) > else > context("123") > end > end > }) > interfaces.definecommand("mymacro", { > macro = function () > context.dosingleempty() > context["domymacro"]() > end > }) > \stopluacode > > \def\myothermacro{123} > > \hairline > > \mymacro[123] > > \mymacro > > \myothermacro > > \hairline > > \doifelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} > > \doifsamestringelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} > > \doifinstringelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} > > \doifincsnameelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} > > > \hairline > > \doifelse{\mymacro}{\myothermacro}{equal content}{not equal content} > > \doifsamestringelse{\mymacro}{\myothermacro}{equal content}{not equal content} > > \doifinstringelse{\mymacro}{\myothermacro}{equal content}{not equal content} > > \doifincsnameelse{\mymacro}{\myothermacro}{equal content}{not equal content} > > > > \stoptext > > > > ___ > 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 > ___ ___ 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 ___
[NTG-context] Compare contents of macros via \doif etc. alternatives
Hello ConTeXist. Is there any way to evaluate of contents of two macros as I am showing in my minimal example? I know, that problem is in expansion, but I dont know to resolve it. My minimal example consist of piece lua code, because I am solving my problem in mixed codes (TeX & Lua) Thanx for help. Jaroslav Hajtmar \starttext \startluacode interfaces.definecommand ("domymacro", { arguments = { { "option", "string" } }, macro = function (opt_1) if #opt_1>0 then context(opt_1) else context("123") end end }) interfaces.definecommand("mymacro", { macro = function () context.dosingleempty() context["domymacro"]() end }) \stopluacode \def\myothermacro{123} \hairline \mymacro[123] \mymacro \myothermacro \hairline \doifelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} \doifsamestringelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} \doifinstringelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} \doifincsnameelse{\mymacro}{\mymacro[123]}{equal content}{not equal content} \hairline \doifelse{\mymacro}{\myothermacro}{equal content}{not equal content} \doifsamestringelse{\mymacro}{\myothermacro}{equal content}{not equal content} \doifinstringelse{\mymacro}{\myothermacro}{equal content}{not equal content} \doifincsnameelse{\mymacro}{\myothermacro}{equal content}{not equal content} \stoptext ___ 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 ___
[NTG-context] \doif... and Lua
Hello, is it possible to use a block of context code depending on a value of a Lua variable? I tried something like: --- \starttext \directlua{test = true} %\directlua{test = 5} %\directlua{test = a} \doifempty{\directlua{return test}} %\doifempty{\directlua{test}} {Yes} {No} \stoptext --- But this gives me always No. - I'm not sure if this is a good way, and whether attempt to use \doif(...) macro is a good idea at all. Any (better) solution? Best regards, Lukas -- Ing. Lukáš Procházka [mailto:l...@pontex.cz] Pontex s. r. o. [mailto:pon...@pontex.cz] [http://www.pontex.cz] Bezová 1658 147 14 Praha 4 Tel: +420 244 062 238 Fax: +420 244 461 038 ___ 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] \doif... and Lua
Am 25.03.2011 um 13:04 schrieb Procházka Lukáš Ing. - Pontex s. r. o.: Hello, is it possible to use a block of context code depending on a value of a Lua variable? I tried something like: --- \starttext \directlua{test = true} %\directlua{test = 5} %\directlua{test = a} \doifempty{\directlua{return test}} %\doifempty{\directlua{test}} {Yes} {No} \stoptext --- But this gives me always No. - I'm not sure if this is a good way, and whether attempt to use \doif(...) macro is a good idea at all. Any (better) solution? \starttext \ctxlua{test = true} Test is \ctxlua{commands.testcase(test)}{True}{False}. \ctxlua{test = false} Test is \ctxlua{commands.testcase(test)}{True}{False}. \stoptext Wolfgang ___ 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] \doif... and Lua
Perfect, thanks. Lukas On Fri, 25 Mar 2011 13:25:52 +0100, Wolfgang Schuster schuster.wolfg...@googlemail.com wrote: Am 25.03.2011 um 13:04 schrieb Procházka Lukáš Ing. - Pontex s. r. o.: Hello, is it possible to use a block of context code depending on a value of a Lua variable? I tried something like: --- \starttext \directlua{test = true} %\directlua{test = 5} %\directlua{test = a} \doifempty{\directlua{return test}} %\doifempty{\directlua{test}} {Yes} {No} \stoptext --- But this gives me always No. - I'm not sure if this is a good way, and whether attempt to use \doif(...) macro is a good idea at all. Any (better) solution? \starttext \ctxlua{test = true} Test is \ctxlua{commands.testcase(test)}{True}{False}. \ctxlua{test = false} Test is \ctxlua{commands.testcase(test)}{True}{False}. \stoptext Wolfgang ___ 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] \doif(not)empty(else)
Hi, Re: http://wiki.contextgarden.net/System_Macros/Branches_and_Decisions What kind of emptyness do \doifempty, \doifnotempty, \doifemptyelse test ? \def\ISay{} %\def\ISay{Boe!} \starttext \doifemptyelse{\ISay}{I say sht}{I say \ISay} \blank \doif{\ISay}{}{I say sht} \blank \doifnot{\ISay}{}{I say \ISay} \stoptext -- Best, Alan * TeX engine = LuaTeX * ConTeXt minimals ver: 2009.01.18 14:39 MKIV fmt: 2009.1.22 int: english/english * Ubuntu 8.04 Hardy Heron, Windows XP SP3 Home ___ 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___
Re: [NTG-context] \doif(not)empty(else)
On Sun, 8 Feb 2009, Alan Stone wrote: Re: http://wiki.contextgarden.net/System_Macros/Branches_and_Decisions What kind of emptyness do \doifempty, \doifnotempty, \doifemptyelse test ? Hello Alan, Here a small test file: \def\Empty{} \def\Macro#1{argument is \doifemptyelse{#1}{empty}{full}} \starttext \quotation{Remember to expand it yourself where needed.} \Macro{}, \Macro{blabla} Nothing: \doifemptyelse{}{empty}{full} \type{\Empty}: \doifemptyelse{\Empty}{empty}{full} \type{all expanded}: \expanded{\doifemptyelse{\Empty}{empty}{full}} \type{with \expandafter}: \expandafter\doifemptyelse\expandafter{\Empty}{empty}{full} \stoptext Cheers, Peter -- Contact information: http://pmrb.free.fr/contact/ ___ 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___
Re: [NTG-context] \doif(not)empty(else)
Peter Münster schrieb: On Sun, 8 Feb 2009, Alan Stone wrote: Re: http://wiki.contextgarden.net/System_Macros/Branches_and_Decisions What kind of emptyness do \doifempty, \doifnotempty, \doifemptyelse test ? Hello Alan, Here a small test file: \def\Empty{} \def\Macro#1{argument is \doifemptyelse{#1}{empty}{full}} \starttext \quotation{Remember to expand it yourself where needed.} \Macro{}, \Macro{blabla} Nothing: \doifemptyelse{}{empty}{full} \type{\Empty}: \doifemptyelse{\Empty}{empty}{full} \type{all expanded}: \expanded{\doifemptyelse{\Empty}{empty}{full}} \type{with \expandafter}: \expandafter\doifemptyelse\expandafter{\Empty}{empty}{full} You can use ConTeXt's \ExpandAfter: \ExpandAfter\doifemptyelse{\Empty}{empty}{full} \stoptext @Alan: It's better to use \doifsomething / \doifelsenothing because they work also with macro content. Wolfgang ___ 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___
Re: [NTG-context] currentheadnumber / doif.. problem
ok, I found the solution. In the documentation (cont-eni.pdf) at page 172 following is written: For example: \currentheadnumber : 8.3 \headnumber[chapter] : 8 \headnumber[section] : 8.3 but that is partly wrong. There should be standing (change example from 8.3 to 8.3.2): For example: \finalsectionnumber : 8.3.2 \currentheadnumber : 2 \headnumber[chapter] : 8 \headnumber[section] : 8.3 Or are \finalsectionnumber and \currentheadnumber interchanged in the code and the documentation is as it should be? But that is a question I cannot answer. Ciao, P. ___ 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___
Re: [NTG-context] currentheadnumber / doif.. problem
Aditya wrote: Can you create a minimum example to play with? I attached the module t-pararef.tex and the example pararef-test.tex. The ref1 is still wrong. When I replace \currentheadnumber in \paragraphMark with the before defined \presentheadnumber context is saying that a «Missing control sequence inserted» - but I don't see any mistake there (but there must be)... But finally I only want that the ref1 in the example is also working (see at the end of example file). A second questions: why is the paragraph of ref3 in the example indented? Thanks, P. \usemodule[pararef] \starttext \chapter{first heading} \section{hamha} \startparagraph\paragraphMark[ref1]\paragraphHeading{tztzttzt} blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla \stopparagraph \startparagraph blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla \stopparagraph \section[ref2]{dumdidim} \startparagraph blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla \stopparagraph \chapter{first heading} \startparagraph blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla \stopparagraph \startparagraph\paragraphHeading{heuho} blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla \stopparagraph \startparagraph\paragraphMark[ref3] blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla blabla \stopparagraph ref1 should be: para. 1.1/2 and is: \crossref{para.}[ref1] ref2 should be: sec. 1.2 and is: \crossref{sec.}[ref2] ref3 should be: para. 2/3 and is: \crossref{para.}[ref3] \stoptext \startmodule[pararef] \unprotect % variable and functions % % paragraphNumber running number starts at every heading with 1 % % paragraphMark[] Marks the paragraph to make references to it % tmpparagraphMark{}[] replaces temporary paragraphMark until %presentheadnumber is working % getParagraphNumber Writes paragraphNumber (for itmize-enviorement % startParagraph Starts and stops a paragraph % stopParagraph % paragraphHeading{} Defines the margin-heading of that paragraph % crossref{}[] common command for internal references \definenumber[paragraphNumber] \setuphead[chapter,section,subsection,subsubsection][after={\resetnumber[paragraphNumber]}] \def\presentheadnumber {\doifelse{\headnumber[section]}{0}% {\headnumber[chapter]}% {\headnumber[section]}% } \def\paragraphMark[#1] {\expanded{\textreference[#1]{\presentheadnumber/\getnumber[paragraphNumber]}}} \define\getParagraphNumber {\incrementnumber[paragraphNumber]% \inothermargin{\color[grey]% {\tfx\getnumber[paragraphNumber]~}} } \definestartstop[paragraph] [before= {\blank[medium]\incrementnumber[paragraphNumber]% \inothermargin{\color[grey]% {\tfx\getnumber[paragraphNumber]~}}}, after={\blank[medium]}] \def\paragraphHeading#1% {\inmargin{#1}% } \def\crossref#1[#2]% {\color[grey]{#1 \in[#2]}% } \protect \stopmodule \endinput___ 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___
Re: [NTG-context] currentheadnumber / doif.. problem
hm.. it still executes always the else-part of the doifelse-function (Untested) \def\presentheadnumber% {\doifelse{\headnumber[section]}{0}% ^^ {\headnumber[chapter]}% {\headnumber[section]}% } ___ 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___
Re: [NTG-context] currentheadnumber / doif.. problem
On Tue, 25 Sep 2007, Peter Schorsch wrote: hm.. it still executes always the else-part of the doifelse-function Can you create a minimum example to play with? Aditya ___ 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___
Re: [NTG-context] currentheadnumber / doif.. problem
Hi Peter Date: Mon, 10 Sep 2007 01:21:26 +0200 From: Peter Schorsch [EMAIL PROTECTED] Subject: [NTG-context] currentheadnumber / doif.. problem To: ntg-context@ntg.nl Hi, I tried to get the full present heading-number. If I am using currentnumber I am getting back only the last part of the heading-number. So I tried do implement a function like this: ... I don't have much time to investigate properly but there should be a \complexheadnumber defined in core-sec which gives you what you need. This should be tied to \headnumber though, so if that doesn't work it may be to do with where or how you are using the command. Do you have a complete minimal example document? Duncan ___ 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___
Re: [NTG-context] currentheadnumber / doif.. problem
On Mon, 10 Sep 2007, Peter Schorsch wrote: Hi, I tried to get the full present heading-number. If I am using currentnumber the result is only the last part of the heading-number. So I tried do implement a function like this: (Untested) \def\presentheadnumber% {\doifelse{\headnumber[section]}{0}% ^^ {\headnumber[chapter]}% {\headnumber[section]}% } Aditya ___ 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___
[NTG-context] currentheadnumber / doif.. problem
Hi, I tried to get the full present heading-number. If I am using currentnumber the result is only the last part of the heading-number. So I tried do implement a function like this: \def\presentheadnumber% {\doifelse{\headnumber[section]}{}% {\headnumber[chapter]}% {\headnumber[section]}% } but always the else-part is executed. I also tried to use doifemptyelse, doifnumber etc.. but as soon i am using headnumber[...] only the else-part will be executed. Can anyone help me with this problem? Or am I going a complete wrong way? Thanks ___ 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___
[NTG-context] currentheadnumber / doif.. problem
Hi, I tried to get the full present heading-number. If I am using currentnumber I am getting back only the last part of the heading-number. So I tried do implement a function like this: \def\presentheadnumber% {\doifelse{\headnumber[section]}{}% {\headnumber[chapter]}% {\headnumber[section]}% } but always the else-part is executed. I also tried to use doifemptyelse, doifnumber etc.. but as soon i am using headnumber[...] only the else-part will be executed. Can anyone help me with this problem? Or am I going a complete wrong way? Thanks ___ 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___