From: Wolfgang Schuster via ntg-context <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
Joel via ntg-context <ntg-context@ntg.nl>
Cc: Wolfgang Schuster <wolfgang.schuster.lists@gmail.com>
Subject: Re: How to let a macro check the previous value of #1 the last time the same macro was called?
Date: Sun, 9 Jan 2022 16:03:54 +0100 [thread overview]
Message-ID: <33fe5e11-b2ba-4e4c-4fa1-77ebb5c38b76@gmail.com> (raw)
In-Reply-To: <1050338993.1893942.1641737797345@mail.yahoo.com>
Joel via ntg-context schrieb am 09.01.2022 um 15:16:
> Is there a way for a macro to check the previous value of #1, the last
> time that same macro was called?
>
> Here is a minimum working example, pretending that `\previousvalue` is
> equal to #1 from the last time the same macro was called:
>
> [...]
To check is the current value differs from the last one you need a temp
macro where you store the current value at the end of your command to
check it in the next call.
\let\previousmymacro\empty
\define[1]\mymacro
{\edef\currentmymacro{#1}%
\ifx\previousmymacro\currentmymacro
same as last time
\else
it is different from last time
\fi
\let\previousmymacro\currentmymacro}
\starttext
\startlines
cat: \mymacro{cat}
cat: \mymacro{cat}
mouse: \mymacro{mouse}
mouse: \mymacro{mouse}
cat: \mymacro{cat}
\stoplines
\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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2022-01-09 15:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1050338993.1893942.1641737797345.ref@mail.yahoo.com>
2022-01-09 14:16 ` Joel via ntg-context
2022-01-09 15:03 ` Wolfgang Schuster via ntg-context [this message]
2022-01-10 8:52 ` Henning Hraban Ramm via ntg-context
2022-01-10 19:21 ` Wolfgang Schuster via ntg-context
2022-01-10 23:15 ` Henning Hraban Ramm via ntg-context
2022-01-11 4:22 ` Aditya Mahajan via ntg-context
2022-01-11 8:20 ` Hans Hagen via ntg-context
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=33fe5e11-b2ba-4e4c-4fa1-77ebb5c38b76@gmail.com \
--to=ntg-context@ntg.nl \
--cc=wolfgang.schuster.lists@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).