ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* small caps italic and font switching inside math
@ 2006-06-28 17:44 Mojca Miklavec
  2006-06-28 18:33 ` Aditya Mahajan
  2006-06-28 18:54 ` Thomas A. Schmitz
  0 siblings, 2 replies; 18+ messages in thread
From: Mojca Miklavec @ 2006-06-28 17:44 UTC (permalink / raw)


Hello,

I have to tiny questions:

1. How do I get small caps [bold] italic (except with the
\definedfont[ec-lmxxx])?

2. I defined \molecule to be
    \def\molecule#1{$\rm#1$},
an usage example would be:
    \molecule{HSO_4^{-}}
But how should I modify this it so that it would also work properly
with examples such as:

{\bfa A story about \molecule{SF_6}}
{\scx A story about \molecule{SF_6}}
{\bsb A story about \molecule{SF_6}}

As a workaround I now keep hardcoding \molecule{\bsb SF_6}.

Thanks,
    Mojca

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

* Re: small caps italic and font switching inside math
  2006-06-28 17:44 small caps italic and font switching inside math Mojca Miklavec
@ 2006-06-28 18:33 ` Aditya Mahajan
  2006-06-28 18:56   ` Taco Hoekwater
  2006-06-28 18:54 ` Thomas A. Schmitz
  1 sibling, 1 reply; 18+ messages in thread
From: Aditya Mahajan @ 2006-06-28 18:33 UTC (permalink / raw)


On Wed, 28 Jun 2006, Mojca Miklavec wrote:

> Hello,
>
> I have to tiny questions:
>
> 1. How do I get small caps [bold] italic (except with the
> \definedfont[ec-lmxxx])?

No idea.

> 2. I defined \molecule to be
>    \def\molecule#1{$\rm#1$},

better use {\mathematics{\rm #1}} so that you can also write in 
equations.

> an usage example would be:
>    \molecule{HSO_4^{-}}
> But how should I modify this it so that it would also work properly
> with examples such as:
>
> {\bfa A story about \molecule{SF_6}}
> {\scx A story about \molecule{SF_6}}
> {\bsb A story about \molecule{SF_6}}
>
> As a workaround I now keep hardcoding \molecule{\bsb SF_6}.

Some catcode trickery might work. This is all I could manage.

% \def\molecule#1{\mathematics{ {\rm #1}}}

\bgroup
\catcode`\_=\active
\catcode`\^=\active
\gdef\activatelohi%
   {\catcode`\_=\active
    \def_{\low}
    \catcode`\^=\active
    \def^{\high}}

% This does not work. Why?
% \gdef\molecule#1{\activatelohi #1}

\glet\molecule=\activatelohi
\egroup



\starttext

  {\bfa A story about {\molecule SF_6}}
  {\scx A story about {\molecule SF_6}}
  {\bsb A story about {\molecule SF_6}}

\stoptext

Though this uses a different syntax than what you had.

I have not looked into it, but doesn't one of context's chem module 
fit this need?

Aditya

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

* Re: small caps italic and font switching inside math
  2006-06-28 17:44 small caps italic and font switching inside math Mojca Miklavec
  2006-06-28 18:33 ` Aditya Mahajan
@ 2006-06-28 18:54 ` Thomas A. Schmitz
  1 sibling, 0 replies; 18+ messages in thread
From: Thomas A. Schmitz @ 2006-06-28 18:54 UTC (permalink / raw)



On Jun 28, 2006, at 7:44 PM, Mojca Miklavec wrote:

> Hello,
>
> I have to tiny questions:
>
> 1. How do I get small caps [bold] italic (except with the
> \definedfont[ec-lmxxx])?
>
Mojca,

this is a bit more complicated than it sounds. Have a look at Adam's  
MyWay, section 4 explains how to do it.

Best

Thomas

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

* Re: small caps italic and font switching inside math
  2006-06-28 18:33 ` Aditya Mahajan
@ 2006-06-28 18:56   ` Taco Hoekwater
  2006-06-29  2:11     ` Mojca Miklavec
  0 siblings, 1 reply; 18+ messages in thread
From: Taco Hoekwater @ 2006-06-28 18:56 UTC (permalink / raw)


Aditya Mahajan wrote:
> On Wed, 28 Jun 2006, Mojca Miklavec wrote:
> 
> 
>>Hello,
>>
>>I have to tiny questions:
>>
>>1. How do I get small caps [bold] italic (except with the
>>\definedfont[ec-lmxxx])?
> 
> No idea.

Same for me. I know that theoreticallu something would be possible
using \Var and special typescripts, but I do not know how that is
supposed to be done in actual code.

> 
> Some catcode trickery might work. This is all I could manage.

This does not work well, because

	HSO\low{4}\high{-}

is not correct.

> % \def\molecule#1{\mathematics{ {\rm #1}}}
> 
> \bgroup
> \catcode`\_=\active
> \catcode`\^=\active
> \gdef\activatelohi%
>    {\catcode`\_=\active
>     \def_{\low}
>     \catcode`\^=\active
>     \def^{\high}}
> 
> % This does not work. Why?
> % \gdef\molecule#1{\activatelohi #1}

(For educational purposes only, it cannot be used by
Mojca this way because of the staggered scripts)

Your macro has already parsed the argument. This way

   \def\molecule#1{{\activatelohi \scantokens{#1}}}

it would work (because \scantokens re-evaluates the argument).

And this way it does not need etex, nor the \gdef:

   \def\molecule%
     {\bgroup
      \catcode`\_=\active \uccode`\~=`\_ \uppercase{\let~\low}%
      \catcode`\^=\active \uccode`\~=`\^ \uppercase{\let~\high}%
      \domolecule }%
   \def\domolecule#1{#1\egroup}
> 
> I have not looked into it, but doesn't one of context's chem module 
> fit this need?

   \usemodule[chemic]
   \let\molecule\chemical

It only gets the size right, not the boldnes. But it can be argued
that that is the correct behaviour anyways.

Cheers, taco

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

* Re: small caps italic and font switching inside math
  2006-06-28 18:56   ` Taco Hoekwater
@ 2006-06-29  2:11     ` Mojca Miklavec
  2006-06-29  5:13       ` Aditya Mahajan
  2006-06-29  7:24       ` Taco Hoekwater
  0 siblings, 2 replies; 18+ messages in thread
From: Mojca Miklavec @ 2006-06-29  2:11 UTC (permalink / raw)


On 6/28/06, Taco Hoekwater wrote:
> Aditya Mahajan wrote:
> > Some catcode trickery might work. This is all I could manage.
>
> This does not work well, because
>
>         HSO\low{4}\high{-}
>
> is not correct.

True, but if I'm aware of it, I can use \lohi{4}{$-$} if needed, which
works even better in some cases, see below. I converted the document
from LaTeX and I didn't came to the idea of using low and high
(perhaps just because that's "not possible" there).

> > % \def\molecule#1{\mathematics{ {\rm #1}}}

Thank you for the note. I would never use it inside formulas, but I
would never though about such interference in more complex definitions
either.

> > \bgroup
> > \catcode`\_=\active
> > \catcode`\^=\active
> > \gdef\activatelohi%
> >    {\catcode`\_=\active
> >     \def_{\low}
> >     \catcode`\^=\active
> >     \def^{\high}}
> >
> > % This does not work. Why?
> > % \gdef\molecule#1{\activatelohi #1}
>
> (For educational purposes only, it cannot be used by
> Mojca this way because of the staggered scripts)

To be honest: in the particular document I never use any stacking (so
this just perfectly suits my needs) except in one particular case: for
typesetting isotopes.

I completely forgot about the \lohi command which I never saw in
practice until now (at least the command itself is documented, but
there's no example and as can be reconstructed from the archives it
seems that Hans added added the option [left] for usage in chemistry).
Thank you, Hans! In the math mode I would have to use phantoms and
such befere being able to achive the same effect, so something like
$\rm _8^16O$ is "wrong" (ugly) anyway.

Taco and Aditya: thanks a lot for the pointers to \low and \high and
for showing me the trick. I appreciate the elegance of Taco's last
solution, although I would never have come to it (I didn't know that
something like that could work and I'm stil not quite sure what
miracle happens in the last step ;).

> Your macro has already parsed the argument. This way
>
>    \def\molecule#1{{\activatelohi \scantokens{#1}}}
>
> it would work (because \scantokens re-evaluates the argument).
>
> And this way it does not need etex, nor the \gdef:
>
>    \def\molecule%
>      {\bgroup
>       \catcode`\_=\active \uccode`\~=`\_ \uppercase{\let~\low}%
>       \catcode`\^=\active \uccode`\~=`\^ \uppercase{\let~\high}%
>       \domolecule }%
>    \def\domolecule#1{#1\egroup}


> > I have not looked into it, but doesn't one of context's chem module
> > fit this need?
>
>    \usemodule[chemic]
>    \let\molecule\chemical
>
> It only gets the size right, not the boldnes. But it can be argued
> that that is the correct behaviour anyways.

Not so long ago you argued that \alpha-sheet, \beta-helix,
\gamma-rays, ... should  be part of text flow (a reason why the el
companion encoding should have it), not a "mathematical thing". I have
a lot of simple formulas such as \molecule{SF_6} and they look
a-kind-of-ugly with a tiny script.

You could compare it to {\bf How to loose a guy in $10$ days}.

I have a strange feeling that handling fonts in math is rather
limited, but no knowledge how to fix anything (just remembering that I
still don't know how to properly switch to bold math with some other
fancy font except with dirty tricks).

I guess that it should be possible to remember the font before
switching to math and then switch to that font again, but that's all
black magic for me. A site on ConTeXt garden solves that for titles in
such a way that there's an additional command provided which also
appends bold to all the mathematics in titles, but that's useful for
titles only.

Mojca

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

* Re: small caps italic and font switching inside math
  2006-06-29  2:11     ` Mojca Miklavec
@ 2006-06-29  5:13       ` Aditya Mahajan
  2006-06-29  7:27         ` Taco Hoekwater
  2006-06-29  7:24       ` Taco Hoekwater
  1 sibling, 1 reply; 18+ messages in thread
From: Aditya Mahajan @ 2006-06-29  5:13 UTC (permalink / raw)


On Thu, 29 Jun 2006, Mojca Miklavec wrote:

> On 6/28/06, Taco Hoekwater wrote:
>> Aditya Mahajan wrote:
>>> Some catcode trickery might work. This is all I could manage.
>>
>> This does not work well, because
>>
>>         HSO\low{4}\high{-}
>>
>> is not correct.
>
> True, but if I'm aware of it, I can use \lohi{4}{$-$} if needed, which
> works even better in some cases, see below.

Or use some more catcode trickery to ensure that - is equivalent to 
\mathematics{-} ;)

> I converted the document from LaTeX and I didn't came to the idea of 
> using low and high (perhaps just because that's "not possible" 
> there).

Latex is not all that bad :) It has \textsuperscript and 
\textsubscript (though most people still write 29$^\text{th}$ June 
rather than 29\textsuperscipt{th} June)

> You could compare it to {\bf How to loose a guy in $10$ days}.
>
> I have a strange feeling that handling fonts in math is rather
> limited, but no knowledge how to fix anything (just remembering that I
> still don't know how to properly switch to bold math with some other
> fancy font except with dirty tricks).

The wrapping in \hbox is not that bad. A lot of math trickery happens 
inside a \hbox. The example on contextgarden 
(http://wiki.contextgarden.net/Bold_Math) is not too different from 
how bm.sty implements bold symbols in latex (which is the best bold 
math implementation in latex, AIUI). However, the \boldmath definition 
on contextgarden lacks

1. Use of pmb (poor man's bold) when a true bold character is not 
present. \boldsymbol{\sum} does not work.

2. Does not take care of the math spacing

\formula{ a \boldsymbol{=} a } does not look correct.

3. Does not take care of delimiters

\formula { \boldsymbol{\left(}\frac 1n\right)} does not work.

4. bm.sty goes into some trouble to define bold accents. So 
\bm{\hat}{a} produces a bold accent over a non-bold a. (I can not 
understand why would someone ever use that).

Hans, why is [boldmath] not defined by default in all the typescripts?


> I guess that it should be possible to remember the font before
> switching to math and then switch to that font again, but that's all
> black magic for me. A site on ConTeXt garden solves that for titles in
> such a way that there's an additional command provided which also
> appends bold to all the mathematics in titles, but that's useful for
> titles only.

It can be used everywhere. For example

\def\myrmbf{\boldmath\rm\bf}

{\myrmbf How to loose a guy in $10$ days}

It will be nice if one could write

\def\mybf{\boldmath\previousfont\bf}

Maybe what is needed is a \beforemathswitch token set. Then one could 
do

\appendtoks \boldmath to \beforemathswitch



Aditya

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

* Re: small caps italic and font switching inside math
  2006-06-29  2:11     ` Mojca Miklavec
  2006-06-29  5:13       ` Aditya Mahajan
@ 2006-06-29  7:24       ` Taco Hoekwater
  2006-06-29  7:30         ` Taco Hoekwater
  1 sibling, 1 reply; 18+ messages in thread
From: Taco Hoekwater @ 2006-06-29  7:24 UTC (permalink / raw)


Mojca Miklavec wrote:
>>
>>It only gets the size right, not the boldnes. But it can be argued
>>that that is the correct behaviour anyways.
> 
> Not so long ago you argued that \alpha-sheet, \beta-helix,
> \gamma-rays, ... should  be part of text flow (a reason why the el
> companion encoding should have it), not a "mathematical thing". I have
> a lot of simple formulas such as \molecule{SF_6} and they look
> a-kind-of-ugly with a tiny script.

So you noticed I was trying to weasly out of something, did you? ;-)

Taco

% The next macro only works as long as you code the subscripts
% before the superscripts!

\newbox\chemlowbox

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

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

\def\finishchem{\ifvoid\chemlowbox \else \low{\box\chemlowbox}\fi}

\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~{\finishchem \rawcharacter{\recurselevel}}}}%
    \catcode`\-=\active \uccode`\~=`\- \uppercase{\def~{--}}%
    \loggingall
    \domolecule }%

\def\domolecule#1{#1\finishchem\egroup}

\starttext

\molecule{HSO_4^{-}}

{\bfa A story about \molecule{SF_6}}
{\scx A story about \molecule{SF_6}}
{\bsb A story about \molecule{SF_6}}


\stoptext


> You could compare it to {\bf How to loose a guy in $10$ days}.
> 
> I have a strange feeling that handling fonts in math is rather
> limited, but no knowledge how to fix anything (just remembering that I
> still don't know how to properly switch to bold math with some other
> fancy font except with dirty tricks).
> 
> I guess that it should be possible to remember the font before
> switching to math and then switch to that font again, but that's all
> black magic for me. A site on ConTeXt garden solves that for titles in
> such a way that there's an additional command provided which also
> appends bold to all the mathematics in titles, but that's useful for
> titles only.
> 
> Mojca
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context

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

* Re: small caps italic and font switching inside math
  2006-06-29  5:13       ` Aditya Mahajan
@ 2006-06-29  7:27         ` Taco Hoekwater
  0 siblings, 0 replies; 18+ messages in thread
From: Taco Hoekwater @ 2006-06-29  7:27 UTC (permalink / raw)


Aditya Mahajan wrote:
> Maybe what is needed is a \beforemathswitch token set. Then one could 
> do
> 
> \appendtoks \boldmath to \beforemathswitch

Already present: \everymathematics

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

* Re: small caps italic and font switching inside math
  2006-06-29  7:24       ` Taco Hoekwater
@ 2006-06-29  7:30         ` Taco Hoekwater
  2006-06-29  9:11           ` Hans Hagen
  2006-07-01  3:50           ` Mojca Miklavec
  0 siblings, 2 replies; 18+ messages in thread
From: Taco Hoekwater @ 2006-06-29  7:30 UTC (permalink / raw)



Sorry, messed up something. New version followws:

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

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

\def\finishchem{\ifvoid\chemlowbox \else \low{\box\chemlowbox}\fi}

\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}}}}%
    \catcode`\-=\active \uccode`\~=`\- \uppercase{\def~{--}}%
    \domolecule }%

\def\domolecule#1{#1\finishchem\egroup}

\starttext
{\bf A test \variant[Caps] in small caps}

\molecule{HSO_4^{-}}
\molecule{H_2SO_4}

{\bfa A story about \molecule{SF_6}}
{\scx A story about \molecule{sf_6}}
{\bsb A story about \molecule{SF_6}}


\stoptext

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

* Re: small caps italic and font switching inside math
  2006-06-29  7:30         ` Taco Hoekwater
@ 2006-06-29  9:11           ` Hans Hagen
  2006-06-29  9:15             ` Taco Hoekwater
  2006-07-01  3:50           ` Mojca Miklavec
  1 sibling, 1 reply; 18+ messages in thread
From: Hans Hagen @ 2006-06-29  9:11 UTC (permalink / raw)


Taco Hoekwater wrote:
> Sorry, messed up something. New version followws:
>
> \newbox\chemlowbox
> \def\chemlow#1%
>    {\setbox\chemlowbox\hbox{{\switchtobodyfont[small]#1}}}
>
> \def\chemhigh#1%
>    {\ifvoid\chemlowbox \high{{\switchtobodyfont[small]#1}}%
>     \else \lohi[left]{\box\chemlowbox}{{\switchtobodyfont[small]#1}}\fi }
>
> \def\finishchem{\ifvoid\chemlowbox \else \low{\box\chemlowbox}\fi}
>
> \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}}}}%
>     \catcode`\-=\active \uccode`\~=`\- \uppercase{\def~{--}}%
>     \domolecule }%
>
> \def\domolecule#1{#1\finishchem\egroup}
>
> \starttext
> {\bf A test \variant[Caps] in small caps}
>
> \molecule{HSO_4^{-}}
> \molecule{H_2SO_4}
>
> {\bfa A story about \molecule{SF_6}}
> {\scx A story about \molecule{sf_6}}
> {\bsb A story about \molecule{SF_6}}
>
>   
i didt follow this thread, so i may be wrong, but doesn't the ppchtex 
(see manuals) module does that kind of stuff?

Hans


-- 

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

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

* Re: small caps italic and font switching inside math
  2006-06-29  9:11           ` Hans Hagen
@ 2006-06-29  9:15             ` Taco Hoekwater
  0 siblings, 0 replies; 18+ messages in thread
From: Taco Hoekwater @ 2006-06-29  9:15 UTC (permalink / raw)




Hans Hagen wrote:
> 
> i didt follow this thread, so i may be wrong, but doesn't the ppchtex 
> (see manuals) module does that kind of stuff?

It doesn't retain font styles (at least, I could not make it do that)

Taco

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

* Re: small caps italic and font switching inside math
  2006-06-29  7:30         ` Taco Hoekwater
  2006-06-29  9:11           ` Hans Hagen
@ 2006-07-01  3:50           ` Mojca Miklavec
  2006-07-01  6:52             ` Taco Hoekwater
  1 sibling, 1 reply; 18+ messages in thread
From: Mojca Miklavec @ 2006-07-01  3:50 UTC (permalink / raw)


On 6/29/06, Taco Hoekwater <wrote:
>
> {\bf A test \variant[Caps] in small caps}

Does this work on your computer? (I don't get any caps here.)

> \newbox\chemlowbox
> \def\chemlow#1%
>    {\setbox\chemlowbox\hbox{{\switchtobodyfont[small]#1}}}
>
> \def\chemhigh#1%
>    {\ifvoid\chemlowbox \high{{\switchtobodyfont[small]#1}}%
>     \else \lohi[left]{\box\chemlowbox}{{\switchtobodyfont[small]#1}}\fi }
>
> \def\finishchem{\ifvoid\chemlowbox \else \low{\box\chemlowbox}\fi}
>
> \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}}}}%
>     \catcode`\-=\active \uccode`\~=`\- \uppercase{\def~{--}}%
>     \domolecule }%
>
> \def\domolecule#1{#1\finishchem\egroup}
>
> \starttext
>
> \molecule{HSO_4^{-}}
> \molecule{H_2SO_4}
>
> {\bfa A story about \molecule{SF_6}}
> {\scx A story about \molecule{sf_6}}
> {\bsb A story about \molecule{SF_6}}
>
>
> \stoptext

Thanks for the magnificent macro! I replaced minus by $-$ and I had to
remove "[left]" because that one is only good for isotopes such as
"_8^16O" (I defined another command for them: they usually don't
appear in formulas anyway), \molecule{SO_4^{2+}} would be weird
otherwise.

It works perfect except in a single case: \title{\molecule{SF_6}}

But please do not lose too much time on it. I can still use explicit
\high and \low in titles (I didn't think about them before you two
reminded me about its existence and I'm very grateful for that).

> > i didt follow this thread, so i may be wrong, but doesn't the ppchtex
> > (see manuals) module does that kind of stuff?
>
> It doesn't retain font styles (at least, I could not make it do that)

Same here. I first had my own simple definition \def\molecule#1{$\rm
#1$}, but I didn't know how to change the font automatically.
\chemical{H_2O} is almost the same as the definition above (of course
the latter is much more powerful, but I only needed it for very simple
formulas). In general it's probably not a good idea to typeset the
formulas in bold and/or italic, but that was for some rather "special
occasion" (very simple formulas often being part of titles,
italic/bold text and so on, ...).

Mojca

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

* Re: small caps italic and font switching inside math
  2006-07-01  3:50           ` Mojca Miklavec
@ 2006-07-01  6:52             ` Taco Hoekwater
  2006-07-01 19:24               ` Mojca Miklavec
  0 siblings, 1 reply; 18+ messages in thread
From: Taco Hoekwater @ 2006-07-01  6:52 UTC (permalink / raw)


Mojca Miklavec wrote:
> On 6/29/06, Taco Hoekwater <wrote:
> 
>>{\bf A test \variant[Caps] in small caps}
> 
> Does this work on your computer? (I don't get any caps here.)

No it doesn't, it was a leftover from a failed experiment

> 
> Thanks for the magnificent macro! I replaced minus by $-$ and I had to

Does that really look better? You can have bold endashes, but
you will not get a bold minus.

> remove "[left]" because that one is only good for isotopes such as

ah. i misunderstood that.

> It works perfect except in a single case: \title{\molecule{SF_6}}

I had seen that, but not yet bothered to fix it. Still, it is
fairly easy to change the macro, try the version below.

It only moves a lone subscript because i like ions better
if the count and charge are aligned, and I also added an italic
correction. It is possible to get everything looking perfect
(of course), but that would require spending much more time
fine-tuning super- and sub scripts.

Positive ions look absolutely awful in latin modern btw. The
plus from CM is dead-ugly when used in this fashion.


Taco

\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}

\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 }%

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

* Re: small caps italic and font switching inside math
  2006-07-01  6:52             ` Taco Hoekwater
@ 2006-07-01 19:24               ` Mojca Miklavec
  2006-07-02  8:44                 ` Taco Hoekwater
  2006-07-03 11:25                 ` Vit Zyka
  0 siblings, 2 replies; 18+ messages in thread
From: Mojca Miklavec @ 2006-07-01 19:24 UTC (permalink / raw)


On 7/1/06, Taco Hoekwater wrote:
> Mojca Miklavec wrote:
> > On 6/29/06, Taco Hoekwater <wrote:
> >
> >>{\bf A test \variant[Caps] in small caps}
> >
> > Does this work on your computer? (I don't get any caps here.)
>
> No it doesn't, it was a leftover from a failed experiment

OK. I thought so :(

> >
> > Thanks for the magnificent macro! I replaced minus by $-$ and I had to
>
> Does that really look better? You can have bold endashes, but
> you will not get a bold minus.

emm ... I didn't think about that. And I don't notice any big
difference on the monitor to be honest. I'll use endash, but it
doesn't really matter that much.

> > It works perfect except in a single case: \title{\molecule{SF_6}}
>
> I had seen that, but not yet bothered to fix it. Still, it is
> fairly easy to change the macro, try the version below.

Didn't work in titles either (or I did something strange) :(
But If I write a couple of explicit \lohi-s, it will still be OK.

> It only moves a lone subscript because i like ions better
> if the count and charge are aligned, and I also added an italic
> correction.

Thanks!

> It is possible to get everything looking perfect
> (of course), but that would require spending much more time
> fine-tuning super- and sub scripts.

I don't need that perfect solution. The way it is now is already great.

> Positive ions look absolutely awful in latin modern btw. The
> plus from CM is dead-ugly when used in this fashion.

I may not bother about it - I can't redesign the font and I'll worry
about switching to some other font at the end if necessary, now it's
time to concentrate on content. (A pitty that Knuth wasn't a chemist
as well. The chemists would desperately need something similar for
chemistry what TeX offers for mathematics.)

> \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}
>
> \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 }%

I didn't really understand the \iffluor-part of the code ... but don't
bother too much.

Thanks a lot for the trickery again (I'm still impressed by the
\uppercase part),
    Mojca

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

* Re: small caps italic and font switching inside math
  2006-07-01 19:24               ` Mojca Miklavec
@ 2006-07-02  8:44                 ` Taco Hoekwater
  2006-07-02 11:59                   ` Mojca Miklavec
  2006-07-03 11:25                 ` Vit Zyka
  1 sibling, 1 reply; 18+ messages in thread
From: Taco Hoekwater @ 2006-07-02  8:44 UTC (permalink / raw)


Mojca Miklavec wrote:
> 
>>>It works perfect except in a single case: \title{\molecule{SF_6}}
>>
>>I had seen that, but not yet bothered to fix it. Still, it is
>>fairly easy to change the macro, try the version below.

Sorry, I thought you were talking about the spacing between F and 6.

> Didn't work in titles either (or I did something strange) :(
> But If I write a couple of explicit \lohi-s, it will still be OK.

Good, but it can be fixed, by changing the definition of
\domolecule to:

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

This re-tokenizes the argument (needed because it was grabbed
by \title already before \molecule had a chance to change the
catcodes.)


> I didn't really understand the \iffluor-part of the code ... but don't
> bother too much.

It is there to trigger a negative italic superscript correction
(TeX doesn't have a primitive for that :-))

> Thanks a lot for the trickery again (I'm still impressed by the
> \uppercase part),

That is actually a fairly standard trick, not something I invented

Greetings, Taco

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

* Re: small caps italic and font switching inside math
  2006-07-02  8:44                 ` Taco Hoekwater
@ 2006-07-02 11:59                   ` Mojca Miklavec
  2006-07-02 14:16                     ` Taco Hoekwater
  0 siblings, 1 reply; 18+ messages in thread
From: Mojca Miklavec @ 2006-07-02 11:59 UTC (permalink / raw)


On 7/2/06, Taco Hoekwater wrote:
> Mojca Miklavec wrote:
> >
> >>>It works perfect except in a single case: \title{\molecule{SF_6}}
> >>
> >>I had seen that, but not yet bothered to fix it. Still, it is
> >>fairly easy to change the macro, try the version below.
>
> Sorry, I thought you were talking about the spacing between F and 6.

;) great. You solved two problems now ;)

> > Didn't work in titles either (or I did something strange) :(
> > But If I write a couple of explicit \lohi-s, it will still be OK.
>
> Good, but it can be fixed, by changing the definition of
> \domolecule to:
>
> \def\domolecule#1%
>    {\expandafter\scantokens\expandafter
>          {\detokenize{#1\finishchem}}\egroup}
>
> This re-tokenizes the argument (needed because it was grabbed
> by \title already before \molecule had a chance to change the
> catcodes.)

Seems like understanding \expandafter would solve 90% of my problems.
I tried to understand that part in TeX book, but it's so cryptic (too
short) ... I understand the concept, but I'm not able to write the
code for it yet :(

Thanks!

> > I didn't really understand the \iffluor-part of the code ... but don't
> > bother too much.
>
> It is there to trigger a negative italic superscript correction
> (TeX doesn't have a primitive for that :-))

Oh, great!

> > Thanks a lot for the trickery again (I'm still impressed by the
> > \uppercase part),
>
> That is actually a fairly standard trick, not something I invented

But it's nevertheless nice ;) I never saw it (probably because I
didn't read and write enough of TeX sources).

Mojca

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

* Re: small caps italic and font switching inside math
  2006-07-02 11:59                   ` Mojca Miklavec
@ 2006-07-02 14:16                     ` Taco Hoekwater
  0 siblings, 0 replies; 18+ messages in thread
From: Taco Hoekwater @ 2006-07-02 14:16 UTC (permalink / raw)


Mojca Miklavec wrote:
> 
> 
> Seems like understanding \expandafter would solve 90% of my problems.
> I tried to understand that part in TeX book, but it's so cryptic (too
> short) ... I understand the concept, but I'm not able to write the
> code for it yet :(

The trick to \expandafter is that you (normally) write it backwards
until reaching a moment in time where TeX is not scanning an argument.

Say you have a macro that contains some stuff in it to be typeset by
\type:

   \def\mystuff{Some literal stuff}

Then you begin with

   \type{\mystuff}

but that obviously doesn't work, you want the final input to look like

   \type{Some literal stuff}



Since \expandafter expands the token that follows the after next token
-- whatever the next token is -- you have to insert it backwards across
the opening brace of the argument, like so:

   \type\expandafter{\mystuff}

But this wouldn't work, yet: you are still in the middle of an
expression (the \type expects an argument, and it gets \expandafter
as it stands).

Luckily, \expandafter *itself* is an expandable command, so you
jump back once more and insert another one:

    \expandafter\type\expandafter{\mystuff}

Now you are on 'neutral ground', and can stop backtracking.
Easy, once you get the hang of it.

Taco

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

* Re: small caps italic and font switching inside math
  2006-07-01 19:24               ` Mojca Miklavec
  2006-07-02  8:44                 ` Taco Hoekwater
@ 2006-07-03 11:25                 ` Vit Zyka
  1 sibling, 0 replies; 18+ messages in thread
From: Vit Zyka @ 2006-07-03 11:25 UTC (permalink / raw)


Mojca Miklavec wrote:
> On 7/1/06, Taco Hoekwater wrote:
>> Mojca Miklavec wrote:
>>> On 6/29/06, Taco Hoekwater <wrote:
>>>
>>>> {\bf A test \variant[Caps] in small caps}
>>> Does this work on your computer? (I don't get any caps here.)
>> No it doesn't, it was a leftover from a failed experiment

I did not follow the thread closely but can it help you
   http://wiki.contextgarden.net/Pseudo_Small_Caps
?

vit

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

end of thread, other threads:[~2006-07-03 11:25 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-28 17:44 small caps italic and font switching inside math Mojca Miklavec
2006-06-28 18:33 ` Aditya Mahajan
2006-06-28 18:56   ` Taco Hoekwater
2006-06-29  2:11     ` Mojca Miklavec
2006-06-29  5:13       ` Aditya Mahajan
2006-06-29  7:27         ` Taco Hoekwater
2006-06-29  7:24       ` Taco Hoekwater
2006-06-29  7:30         ` Taco Hoekwater
2006-06-29  9:11           ` Hans Hagen
2006-06-29  9:15             ` Taco Hoekwater
2006-07-01  3:50           ` Mojca Miklavec
2006-07-01  6:52             ` Taco Hoekwater
2006-07-01 19:24               ` Mojca Miklavec
2006-07-02  8:44                 ` Taco Hoekwater
2006-07-02 11:59                   ` Mojca Miklavec
2006-07-02 14:16                     ` Taco Hoekwater
2006-07-03 11:25                 ` Vit Zyka
2006-06-28 18:54 ` Thomas A. Schmitz

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