ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Taco's \molecule fails in mkiv
@ 2009-02-23 16:21 Mojca Miklavec
  2009-02-23 16:52 ` Wolfgang Schuster
  0 siblings, 1 reply; 5+ messages in thread
From: Mojca Miklavec @ 2009-02-23 16:21 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hello,

I did not try to analyze how the following macros work (they are too
complex), but they somehow fail in mkiv. (I don't need the "F"
kerning, so that portion of code may go away, but the macro itself is
very very handy.)

All I want is to have a macro that "converts" _{...} into \low{...}
and ^{...} into \high{...} (or possibly enable using both at the same
time).

\newbox\chemlowbox
\def\chemlow#1%
  {\setbox\chemlowbox\hbox{{\switchtobodyfont[small]#1}}}

\def\chemhigh#1%
  {\ifvoid\chemlowbox \high{{\switchtobodyfont[small]#1}}%
   \else \/\lohi{\box\chemlowbox}{{\switchtobodyfont[small]#1}}\fi }

\def\finishchem%
   {\ifvoid\chemlowbox \else
     \iffluor \fluorfalse \kern-.1em \fi\low{\box\chemlowbox}\fi}

% for "kerning" after F
\newif\iffluor

\unexpanded\def\molecule%
  {\bgroup
   \catcode`\_=\active \uccode`\~=`\_ \uppercase{\let~\chemlow}%
   \catcode`\^=\active \uccode`\~=`\^ \uppercase{\let~\chemhigh}%
   \dostepwiserecurse {65}{90}{1}
      {\catcode \recurselevel = \active
       \uccode`\~=\recurselevel
       \uppercase{\edef~{\noexpand\finishchem
                         \rawcharacter{\recurselevel}}}}%
   \uccode `\~=`\F \uppercase{\def~{\finishchem F\fluortrue}}%
   \catcode`\-=\active \uccode`\~=`\- \uppercase{\def~{--}}%
   %\loggingall
   \domolecule }%

\def\domolecule#1%
  {\expandafter\scantokens\expandafter
        {\detokenize{#1\finishchem}}\egroup}

\starttext
\molecule{CO_2}
\stoptext

Thanks for any hints,
    Mojca
___________________________________________________________________________________
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
___________________________________________________________________________________


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

end of thread, other threads:[~2009-02-24  0:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-23 16:21 Taco's \molecule fails in mkiv Mojca Miklavec
2009-02-23 16:52 ` Wolfgang Schuster
2009-02-23 17:14   ` Mojca Miklavec
2009-02-24  0:21     ` Wolfgang Schuster
2009-02-23 18:19   ` luigi scarso

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).