public
Last active

  • Download Gist
sscript.tex
TeX
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
%% the following is needed for the stolen code to work
\newdimen\scratchdimen
\newdimen\zeropoint\zeropoint=0pt
\newbox\scratchbox
 
\def\fontexheight{\fontdimen5 }
\def\mathsubnormal{\fontdimen16 }
\def\mathsupnormal{\fontdimen14 }
\def\strutheight{0pt}
\def\strutdepth{0pt}
 
\long\def\firstofoneargument#1{#1}
\long\def\gobbleoneargument#1{}
 
\long\def\doif#1#2%
{\edef\stringa{#1}%
\edef\stringb{#2}%
\ifx\stringa\stringb
\expandafter\firstofoneargument
\else
\expandafter\gobbleoneargument
\fi}
 
\let\dontleavehmode\quitvmode
\let\unexpanded\relax
\let\dosingleempty\relax
\let\tx\sevenrm
 
%% below, almost, unchanged ConTeXt code
 
%D \macros
%D {low, high, lohi}
%D
%D Although \TEX\ is pretty well aware of super- and
%D subscripts, its mechanism is mainly tuned for math mode.
%D The next few commands take care of script texts both modes.
%D
%D \startbuffer
%D The higher\high{one goes} the lower\low{one drops}, or\lohi{yes}{no}?
%D \stopbuffer
%D
%D \typebuffer
%D
%D \getbuffer
%D
%D Note the different placement of \type {\lohi}, where we
%D need a bit more space. The implementation looks a bit
%D fuzzy, since some \type {\fontdimen}'s are involved to
%D determine the optimal placement.
 
\def\dodohighlow
{\ifx\fontsize\empty
\ifmmode
\ifnum\fam<0 \tx \else \holamathfont \fi
\else
\tx
\fi
\else
\tx
\fi}
 
\def\dohighlow#1#2#3#4#5% todo, named fontdimens
{\dontleavehmode
\bgroup
\scratchdimen\ifdim\fontexheight\textfont2=1ex #2\textfont2\else #3ex\fi
\advance\scratchdimen #4ex
\kern.1ex
\setbox\scratchbox\hbox{#1\scratchdimen\hbox{\dodohighlow#5}}%
\ht\scratchbox\strutheight
\dp\scratchbox\strutdepth
\box\scratchbox
\egroup}
 
\unexpanded\def\high{\dohighlow\raise\mathsupnormal{.86}{0}}
\unexpanded\def\low {\dohighlow\lower\mathsubnormal{.48}{0}}
 
% \unexpanded\def\lohi#1#2%
% {\dontleavehmode
% \hbox
% {\setbox4=\hbox{\dohighlow\lower\mathsubnormal{.48}{.1}{#1}}%
% \setbox6=\hbox{\dohighlow\raise\mathsupnormal{.86}{.1}{#2}}%
% \ifdim\wd4<\wd6
% \wd4=\zeropoint\box4\box6
% \else
% \wd6=\zeropoint\box6\box4
% \fi}}
 
\unexpanded\def\lohi
{\dosingleempty\dolohi}
 
\def\dolohi[#1]#2#3%
{\dontleavehmode
\hbox
{\setbox4\hbox{\dohighlow\lower\mathsubnormal{.48}{.1}{#2}}%
\setbox6\hbox{\dohighlow\raise\mathsupnormal{.86}{.1}{#3}}%
\doif{#1}{left}
{\ifdim\wd4<\wd6
\setbox4\hbox to \wd6{\hss\box4}%
\else
\setbox6\hbox to \wd4{\hss\box6}%
\fi}%
\ifdim\wd4<\wd6
\wd4=\zeropoint\box4\box6
\else
\wd6=\zeropoint\box6\box4
\fi}}
 
%D You can provide an optional keyword \type {left}, in which
%D case the super and subscripts will be aligned in a way that
%D permits placement at the left of a word (which means that
%D it will be right aligned).
%D
%D \startbuffer
%D \lohi{aha}{ah} test \lohi{aha}{ah} test
%D \lohi[left]{aha}{ah} test \lohi[left]{aha}{ah} test
%D \lohi{aha}{ah} test\lohi{aha}{ah} test
%D \lohi[left]{aha}{ah}test \lohi[left]{aha}{ah}test
%D \stopbuffer
%D
%D \typebuffer
%D
%D \getbuffer
 
%% test
 
A\lohi[]{xy}{abxx}
\lohi[left]{xy}{abxx}A
A\low{xy} A\high{xy}
\bye

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.