ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Macros which scan subscripts/superscripts in ConTeXt
@ 2020-06-26  0:43 Jairo A. del Rio
  2020-06-26  1:47 ` Aditya Mahajan
  0 siblings, 1 reply; 3+ messages in thread
From: Jairo A. del Rio @ 2020-06-26  0:43 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1133 bytes --]

Hi, list! I've seen the following in Stack Exchange:

https://tex.stackexchange.com/questions/503208/define-macro-that-scans-ahead-for-super-and-or-subscript-absorbs-them-and-mo

The answer is:

\documentclass{article}\usepackage{amsmath}\usepackage{xparse}
\NewDocumentCommand{\mymathsym}{e{^_}}{%
  x^{\mathrm{foo}\IfValueT{#1}{,#1}}_{\mathrm{bar}\IfValueT{#2}{,#2}}%}
\begin{document}
\begin{gather}\mymathsym \\\mymathsym^{\mathrm{extrasup}}
\\\mymathsym_{\mathrm{extrasub}}
\\\mymathsym^{\mathrm{extrasup}}_{\mathrm{extrasub}}
\\\mymathsym_{\mathrm{extrasub}}^{\mathrm{extrasup}}   \end{gather}
\end{document}

Such a macro contextually defines a behavior for a subscript and a
superscript even if they aren't displayed in a specific order, so

\mymacro_{a}^{b}

\mymacro^{b}_{a}


have the same output, even if the intended behavior is not the typical
one (I could redefine it so subscripts change colors, for instance).
Although I could just port the macro using xparse-generic because it
works in ConTeXt too, how to define a macro like that the ConTeXt way,
i.e., using only ConTeXt macros?

Thank you in advance.

Jairo :)

[-- Attachment #1.2: Type: text/html, Size: 6491 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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] 3+ messages in thread

end of thread, other threads:[~2020-06-26  8:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-26  0:43 Macros which scan subscripts/superscripts in ConTeXt Jairo A. del Rio
2020-06-26  1:47 ` Aditya Mahajan
2020-06-26  8:03   ` 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).