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
On
7/22/2017 3:58 AM, Henri wrote:
On Fri, 2017-07-21 at 11:25 +0000, 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
___________________________________________________________________________________