
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

On Wed, 28 Jun 2006, Mojca Miklavec wrote:
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.
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

Aditya Mahajan wrote:
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.
(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

On 6/28/06, Taco Hoekwater wrote:
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.
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 ;).
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

On Thu, 29 Jun 2006, Mojca Miklavec wrote:
Or use some more catcode trickery to ensure that - is equivalent to \mathematics{-} ;)
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)
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?
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

Mojca Miklavec wrote:
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

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

Taco Hoekwater wrote:
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 -----------------------------------------------------------------

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

Mojca Miklavec wrote:
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 }%

On 7/1/06, Taco Hoekwater wrote:
OK. I thought so :(
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.
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.
Thanks!
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.)
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

Mojca Miklavec wrote:
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

On 7/2/06, Taco Hoekwater wrote:
;) great. You solved two problems now ;)
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!
Oh, great!
But it's nevertheless nice ;) I never saw it (probably because I didn't read and write enough of TeX sources). Mojca

Mojca Miklavec wrote:
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

Mojca Miklavec wrote:
I did not follow the thread closely but can it help you http://wiki.contextgarden.net/Pseudo_Small_Caps ? vit
participants (6)
-
Aditya Mahajan
-
Hans Hagen
-
Mojca Miklavec
-
Taco Hoekwater
-
Thomas A. Schmitz
-
Vit Zyka