| 1 |
% \iffalse |
| 2 |
% |
| 3 |
%<*internal> |
| 4 |
\begingroup |
| 5 |
%</internal> |
| 6 |
%<*batchfile> |
| 7 |
\input docstrip.tex |
| 8 |
\keepsilent |
| 9 |
\preamble |
| 10 |
_____________________________ |
| 11 |
The REALSCRIPTS package |
| 12 |
(C) 2010--2016 Will Robertson |
| 13 |
License information appended |
| 14 |
|
| 15 |
\endpreamble |
| 16 |
\postamble |
| 17 |
|
| 18 |
Copyright (C) 2010--2016 by Will Robertson <[email protected]> |
| 19 |
|
| 20 |
Distributable under the LaTeX Project Public License, |
| 21 |
version 1.3c or higher (your choice). The latest version of |
| 22 |
this license is at: http://www.latex-project.org/lppl.txt |
| 23 |
|
| 24 |
This work is "maintained" (as per LPPL maintenance status) |
| 25 |
by Will Robertson. |
| 26 |
|
| 27 |
This work consists of the file realscripts.dtx |
| 28 |
and the derived files realscripts.sty, |
| 29 |
realscripts.ins, and |
| 30 |
realscripts.pdf. |
| 31 |
|
| 32 |
\endpostamble |
| 33 |
\askforoverwritefalse |
| 34 |
\generate{\file{realscripts.sty}{\from{realscripts.dtx}{package}}} |
| 35 |
%</batchfile> |
| 36 |
%<batchfile>\endbatchfile |
| 37 |
%<*internal> |
| 38 |
\generate{\file{realscripts.ins}{\from{realscripts.dtx}{batchfile}}} |
| 39 |
\def\tmpa{plain} |
| 40 |
\ifx\tmpa\fmtname\endgroup\expandafter\bye\fi |
| 41 |
\endgroup |
| 42 |
%</internal> |
| 43 |
% |
| 44 |
% \begin{macrocode} |
| 45 |
%<*driver> |
| 46 |
\ProvidesFile{realscripts.dtx} |
| 47 |
%</driver> |
| 48 |
%<package>\ProvidesPackage{realscripts} |
| 49 |
%<*package> |
| 50 |
[2016/02/13 v0.3d Access OpenType subscripts and superscripts] |
| 51 |
%</package> |
| 52 |
% \end{macrocode} |
| 53 |
% |
| 54 |
%<*driver> |
| 55 |
\documentclass{ltxdoc} |
| 56 |
\usepackage{color,graphicx,metalogo,hologo,fontspec,realscripts} |
| 57 |
\linespread{1.05} % A bit more space between lines |
| 58 |
\frenchspacing % Remove extra space after punctuation |
| 59 |
\definecolor{niceblue}{rgb}{0.1,0.2,1} |
| 60 |
\def\theCodelineNo{\textcolor{niceblue}{\sffamily\tiny\arabic{CodelineNo}}} |
| 61 |
\newcommand*\pkg[1]{\texttt{#1}} |
| 62 |
\begin{document} |
| 63 |
\DocInput{\jobname.dtx} |
| 64 |
\end{document} |
| 65 |
%</driver> |
| 66 |
% |
| 67 |
% \fi |
| 68 |
% |
| 69 |
% \errorcontextlines=999 |
| 70 |
% \makeatletter |
| 71 |
% |
| 72 |
% \GetFileInfo{\jobname.sty} |
| 73 |
% |
| 74 |
% \title{The \pkg{\jobname} package} |
| 75 |
% \author{Will Robertson} |
| 76 |
% \date{\filedate \qquad \fileversion} |
| 77 |
% |
| 78 |
% \maketitle |
| 79 |
% |
| 80 |
% \section{Introduction} |
| 81 |
% |
| 82 |
% OpenType fonts provide the possiblity of using specially-drawn glyphs for |
| 83 |
% subscript and superscript text. \LaTeX\ by default simply uses a smaller |
| 84 |
% font size, which is acceptable if the font has optical sizes. Most fonts |
| 85 |
% don't, however. |
| 86 |
% |
| 87 |
% If you are using the \pkg{fontspec} package\footnote{The \pkg{fontspec} package requires \XeLaTeX\ or \hologo{LuaLaTeX}.} to select OpenType fonts |
| 88 |
% (or other sorts of fonts with the necessary font features), then loading |
| 89 |
% this package will redefine the \cmd\textsuperscript\ and |
| 90 |
% \cmd\textsubscript\ commands that take advantage of the OpenType font |
| 91 |
% features. |
| 92 |
% |
| 93 |
% The \cs{textsubsuperscript}\marg{sub}\marg{super} command is |
| 94 |
% defined for typesetting superscripts above subscripts using the same |
| 95 |
% approach. For symmetry, \cs{textsupersubscript}\marg{super}\marg{sub} |
| 96 |
% is also provided. Options are available to specify the alignment of the sub- and super-scripts; see below. |
| 97 |
% |
| 98 |
% \section{Technical details} |
| 99 |
% |
| 100 |
% The old commands are defined in starred form (e.g., \cs{textsubscript*}) for cases where the new commands are not appropriate. |
| 101 |
% The functionality of the starred and non-starred commands can |
| 102 |
% also be accessed using the macros |
| 103 |
% \cmd\realsubscript, |
| 104 |
% \cmd\realsuperscript, |
| 105 |
% \cmd\fakesubscript, and |
| 106 |
% \cmd\fakesuperscript, in case another package (or you) |
| 107 |
% redefine the original \cmd\text\dots\ commands. |
| 108 |
% |
| 109 |
% This package will also patch the default \LaTeX\ footnote mechanism to |
| 110 |
% use \cs{textsuperscript} automatically. You may change the font used |
| 111 |
% to typeset the footnote numbers (by default it is the \cs{normalfont}) |
| 112 |
% by redefining \cs{footnotemarkfont}; e.g.: |
| 113 |
% {\par\qquad\verb|\renewcommand\footnotemarkfont|\marg{font switch}\par} |
| 114 |
% \noindent and users of \pkg{KOMA-Script} may use instead |
| 115 |
% {\par\qquad\verb|\setkomafont{footnotelabel}|\marg{font switch}\par} |
| 116 |
% \noindent where \meta{font switch} is a command such as \cs{sffamily} or a \pkg{fontspec} font defined with \cs{newfontfamily}. |
| 117 |
% |
| 118 |
% Beware of other packages, however, that change the footnote mechanism. (Usually by redefining \cs{@makefnmark}.) I can often work around or work with such packages so \pkg{realscripts} cooperates gracefully with them; please report any conflicts to me. |
| 119 |
% |
| 120 |
% \section{Examples} |
| 121 |
% |
| 122 |
% Here is an example using the `{\fontspec{Skia} Skia}' font of Mac\,OS\,X: (surrounded by `A' and `Z' for visual context) |
| 123 |
% |
| 124 |
% \begin{quotation}\color{niceblue} |
| 125 |
% \fontspec{Skia} |
| 126 |
% |\textsuperscript{…} | A \textsuperscript{abcdefghijklmnopqrstuvwxyz1234567890} Z\par |
| 127 |
% |\textsubscript{…} | A \textsubscript{abcdefghijklmnopqrstuvwxyz1234567890} Z |
| 128 |
% \end{quotation} |
| 129 |
% The original definitions are available in starred verions of the commands: |
| 130 |
% (compare this example to that above to see why using these features is often desirable) |
| 131 |
% \begin{quotation}\color{niceblue} |
| 132 |
% \fontspec{Skia} |
| 133 |
% |\textsuperscript*{…} | A \textsuperscript*{abcdefghijklmnopqrstuvwxyz1234567890} Z\par |
| 134 |
% |\textsubscript*{…} | A \textsubscript*{abcdefghijklmnopqrstuvwxyz1234567890} Z |
| 135 |
% \end{quotation} |
| 136 |
% When the font features are not available the commands will fall back on the standard technique of scaling down the text font: |
| 137 |
% (this is Mac\,OS\,X's `{\fontspec{Didot} Didot}') |
| 138 |
% \begin{quotation}\color{niceblue} |
| 139 |
% \fontspec{Didot} |
| 140 |
% |\textsuperscript{…} | A \textsuperscript{abcdefghijklmnopqrstuvwxyz1234567890} Z\par |
| 141 |
% |\textsubscript{…} | A \textsubscript{abcdefghijklmnopqrstuvwxyz1234567890} Z |
| 142 |
% \end{quotation} |
| 143 |
% But beware fonts that contain the necessary font features but lack the full repertoire of glyphs: (this is `{\fontspec{Adobe Jenson Pro}Adobe Jenson Pro}') |
| 144 |
% \begin{quotation}\color{niceblue} |
| 145 |
% \fontspec{Adobe Jenson Pro} |
| 146 |
% |\textsuperscript{…} | A {\textsuperscript{abcdefghijklmnopqrstuvwxyz1234567890}} Z\par |
| 147 |
% |\textsubscript{…} | A {\textsubscript{abcdefghijklmnopqrstuvwxyz1234567890}} Z |
| 148 |
% \end{quotation} |
| 149 |
% Finally, the `combined' commands. Note the dimension available |
| 150 |
% to add some extra space between the sub- and super-scripts, and |
| 151 |
% the optional argument for specifying alignment. |
| 152 |
% \begin{quotation}\color{niceblue} |
| 153 |
% \fontspec{Skia} |
| 154 |
% |\textsubsuperscript{…}{…} | |
| 155 |
% A {\textsubsuperscript{123456}{789}} Z\par\smallskip |
| 156 |
% |\setlength\subsupersep{2pt} | \subsupersep=2pt |
| 157 |
% A {\textsubsuperscript{123456}{789}} Z\par\smallskip |
| 158 |
% |\textsubsuperscript[c]{…}{…} | |
| 159 |
% A {\textsubsuperscript[c]{123}{456789}} Z\par\smallskip |
| 160 |
% |\textsubsuperscript[r]{…}{…} | |
| 161 |
% A {\textsubsuperscript[r]{123456}{789}} Z\par\smallskip |
| 162 |
% \end{quotation} |
| 163 |
% |
| 164 |
% \newpage |
| 165 |
% \part{Implementation of \textsf{\jobname}} |
| 166 |
%\iffalse |
| 167 |
%<*package> |
| 168 |
%\fi |
| 169 |
% This is the package implementation. |
| 170 |
% If you're only interested in the footnote redefinition, |
| 171 |
% skip ahead to Section~\ref{sec:fn} on page~\pageref{sec:fn}. |
| 172 |
% |
| 173 |
% \begin{macrocode} |
| 174 |
\RequirePackage{fontspec} |
| 175 |
\ExplSyntaxOn |
| 176 |
% \end{macrocode} |
| 177 |
% |
| 178 |
% \begin{macro}{\fakesubscript} |
| 179 |
% \begin{macro}{\fakesuperscript} |
| 180 |
% The old (`fake') methods. |
| 181 |
% Because \cs{textsubscript} is not defined in \LaTeXe, |
| 182 |
% we either define it from scratch along with \cs{textsuperscript} |
| 183 |
% (for consistency). |
| 184 |
% \begin{macrocode} |
| 185 |
\DeclareDocumentCommand \fakesubscript {m} { |
| 186 |
\@textsubscript{\selectfont#1} |
| 187 |
} |
| 188 |
\DeclareDocumentCommand \fakesuperscript {m} { |
| 189 |
\@textsuperscript{\selectfont#1} |
| 190 |
} |
| 191 |
% \end{macrocode} |
| 192 |
% \end{macro} |
| 193 |
% \end{macro} |
| 194 |
% |
| 195 |
% \begin{macro}{\textsubscript} |
| 196 |
% \begin{macro}{\textsubscript*} |
| 197 |
% \begin{macro}{\textsuperscript} |
| 198 |
% \begin{macro}{\textsuperscript*} |
| 199 |
% These commands are either defined to create fake or real sub-/super-scripts if they are starred or not, respectively. |
| 200 |
% \begin{macrocode} |
| 201 |
\RenewDocumentCommand \textsubscript {s} { |
| 202 |
\IfBooleanTF #1 \fakesubscript \realsubscript |
| 203 |
} |
| 204 |
\RenewDocumentCommand \textsuperscript {s} { |
| 205 |
\IfBooleanTF #1 \fakesuperscript \realsuperscript |
| 206 |
} |
| 207 |
% \end{macrocode} |
| 208 |
% \end{macro} |
| 209 |
% \end{macro} |
| 210 |
% \end{macro} |
| 211 |
% \end{macro} |
| 212 |
% |
| 213 |
% \begin{macro}{\realsubscript} |
| 214 |
% The new subscript command to use rich font features if possible. |
| 215 |
% \begin{macrocode} |
| 216 |
\DeclareDocumentCommand \realsubscript {m} { |
| 217 |
\fontspec_if_fontspec_font:TF { |
| 218 |
% \end{macrocode} |
| 219 |
% For OpenType fonts, the subscript feature (|subs|) is used, but if that doesn't |
| 220 |
% exist then the scientific inferior feature (|sinf|) is used on the assumption |
| 221 |
% that something's better than nothing. |
| 222 |
% \begin{macrocode} |
| 223 |
\fontspec_if_opentype:TF |
| 224 |
{ \fontspec_if_feature:nTF {+subs} |
| 225 |
{ {\addfontfeature{VerticalPosition=Inferior}#1} } |
| 226 |
{ \fontspec_if_feature:nTF {+sinf} |
| 227 |
{ {\addfontfeature{VerticalPosition=ScientificInferior}#1} } |
| 228 |
{ \fakesubscript{#1} } |
| 229 |
} |
| 230 |
} |
| 231 |
% \end{macrocode} |
| 232 |
% ATSUI fonts: |
| 233 |
% \begin{macrocode} |
| 234 |
{ \fontspec_if_aat_feature:nnTF {10} {2} |
| 235 |
{ {\addfontfeature{VerticalPosition=Inferior}#1} } |
| 236 |
{ \fakesubscript{#1} } |
| 237 |
} |
| 238 |
} |
| 239 |
% \end{macrocode} |
| 240 |
% Non-fontspec fonts: |
| 241 |
% \begin{macrocode} |
| 242 |
{ \fakesubscript{#1} } |
| 243 |
} |
| 244 |
% \end{macrocode} |
| 245 |
% \end{macro} |
| 246 |
% |
| 247 |
% \begin{macro}{\realsuperscript} |
| 248 |
% The new superscript command to use rich font features if possible. |
| 249 |
% \begin{macrocode} |
| 250 |
\DeclareDocumentCommand \realsuperscript {m} { |
| 251 |
\fontspec_if_fontspec_font:TF |
| 252 |
{ |
| 253 |
% \end{macrocode} |
| 254 |
% OpenType fonts: |
| 255 |
% \begin{macrocode} |
| 256 |
\fontspec_if_opentype:TF |
| 257 |
{ \fontspec_if_feature:nTF {+sups} |
| 258 |
{ {\addfontfeature{VerticalPosition=Superior}#1} } |
| 259 |
{ \fakesuperscript{#1} } |
| 260 |
} |
| 261 |
% \end{macrocode} |
| 262 |
% ATSUI fonts: |
| 263 |
% \begin{macrocode} |
| 264 |
{ \fontspec_if_aat_feature:nnTF {10} {1} |
| 265 |
{ {\addfontfeature{VerticalPosition=Superior}#1} } |
| 266 |
{ \fakesuperscript{#1} } |
| 267 |
} |
| 268 |
} |
| 269 |
% \end{macrocode} |
| 270 |
% Non-fontspec fonts: |
| 271 |
% \begin{macrocode} |
| 272 |
{ \fakesuperscript{#1} } |
| 273 |
} |
| 274 |
% \end{macrocode} |
| 275 |
% \end{macro} |
| 276 |
% |
| 277 |
% \section{Patching footnotes} |
| 278 |
% \label{sec:fn} |
| 279 |
% |
| 280 |
% \begin{macro}{\@makefnmark} |
| 281 |
% This is the command used to typeset the `footnote mark'. |
| 282 |
% Feel free to redefine it as necessary for your own purposes. |
| 283 |
% \begin{macrocode} |
| 284 |
\cs_set:Npn \@makefnmark { |
| 285 |
\mbox{\footnotemarkfont\textsuperscript{\@thefnmark}} |
| 286 |
} |
| 287 |
% \end{macrocode} |
| 288 |
% We define a \cs{footnotemarkfont} that is used to style |
| 289 |
% the number used for the footnote, which by default is |
| 290 |
% simply \cs{normalfont} (following \LaTeXe's default). |
| 291 |
% If \pkg{KOMA-Script} is |
| 292 |
% being used, we use their hook for the footnotemark font instead. |
| 293 |
% \begin{macrocode} |
| 294 |
\cs_if_exist:NTF \ftntm@font |
| 295 |
{ |
| 296 |
\cs_new:Npn \footnotemarkfont {\ftntm@font} |
| 297 |
} |
| 298 |
{ |
| 299 |
\cs_new:Npn \footnotemarkfont {\normalfont} |
| 300 |
} |
| 301 |
% \end{macrocode} |
| 302 |
% \end{macro} |
| 303 |
% |
| 304 |
% \section{sub+super} |
| 305 |
% |
| 306 |
% \begin{macro}{\textsubsuperscript} |
| 307 |
% \begin{macro}{\textsupersubscript} |
| 308 |
% Although the implementation below would be fine outside of this package too, |
| 309 |
% no point writing yet another small package. |
| 310 |
% \begin{macrocode} |
| 311 |
\DeclareDocumentCommand \textsubsuperscript {s O{l} mm} { |
| 312 |
\leavevmode |
| 313 |
\group_begin: |
| 314 |
\IfBooleanTF #1 |
| 315 |
{ |
| 316 |
\hbox_set:Nn \l_tmpa_box {\textsubscript*{#3}} |
| 317 |
\hbox_set:Nn \l_tmpb_box {\textsuperscript*{#4}} |
| 318 |
} |
| 319 |
{ |
| 320 |
\hbox_set:Nn \l_tmpa_box {\textsubscript{#3}} |
| 321 |
\hbox_set:Nn \l_tmpb_box {\textsuperscript{#4}} |
| 322 |
} |
| 323 |
\hbox_set:Nn \l_tmpa_box |
| 324 |
{ \box_move_down:nn \subsupersep {\box_use:N \l_tmpa_box} } |
| 325 |
\hbox_set:Nn \l_tmpb_box |
| 326 |
{ \box_move_up:nn \subsupersep {\box_use:N \l_tmpb_box} } |
| 327 |
\str_case:nnF {#2} |
| 328 |
{ |
| 329 |
{l}{\use_i:nnn} |
| 330 |
{c}{\use_ii:nnn} |
| 331 |
{r}{\use_iii:nnn} |
| 332 |
} |
| 333 |
{ |
| 334 |
\PackageWarning{realscripts}{ |
| 335 |
Unknown~alignment~option~`#2'. \MessageBreak |
| 336 |
One~ of~ `l',~ `c',~ `r',~ only |
| 337 |
} |
| 338 |
\use_i:nnn |
| 339 |
} |
| 340 |
% \end{macrocode} |
| 341 |
% Left aligned: |
| 342 |
% \begin{macrocode} |
| 343 |
{ |
| 344 |
\hbox_overlap_right:n { \box_use:N \l_tmpa_box } |
| 345 |
\hbox_overlap_right:n { \box_use:N \l_tmpb_box } |
| 346 |
\skip_horizontal:n { |
| 347 |
\dim_max:nn {\box_wd:N \l_tmpa_box} {\box_wd:N \l_tmpb_box} |
| 348 |
} |
| 349 |
} |
| 350 |
% \end{macrocode} |
| 351 |
% Center aligned: (for completeness) |
| 352 |
% \begin{macrocode} |
| 353 |
{ |
| 354 |
\dim_compare:nTF { \box_wd:N \l_tmpa_box > \box_wd:N \l_tmpb_box } |
| 355 |
{ |
| 356 |
\skip_horizontal:n { |
| 357 |
0.5\box_wd:N \l_tmpa_box-0.5\box_wd:N \l_tmpb_box |
| 358 |
} |
| 359 |
\box_use:N \l_tmpb_box |
| 360 |
\skip_horizontal:n { |
| 361 |
-0.5\box_wd:N \l_tmpa_box-0.5\box_wd:N \l_tmpb_box |
| 362 |
} |
| 363 |
\box_use:N \l_tmpa_box |
| 364 |
} |
| 365 |
{ |
| 366 |
\skip_horizontal:n { |
| 367 |
0.5\box_wd:N \l_tmpb_box-0.5\box_wd:N \l_tmpa_box |
| 368 |
} |
| 369 |
\box_use:N \l_tmpa_box |
| 370 |
\skip_horizontal:n { |
| 371 |
-0.5\box_wd:N \l_tmpb_box-0.5\box_wd:N \l_tmpa_box |
| 372 |
} |
| 373 |
\box_use:N \l_tmpb_box |
| 374 |
} |
| 375 |
} |
| 376 |
% \end{macrocode} |
| 377 |
% Right aligned: |
| 378 |
% \begin{macrocode} |
| 379 |
{ |
| 380 |
\skip_horizontal:n { |
| 381 |
\dim_max:nn {\box_wd:N \l_tmpa_box} {\box_wd:N \l_tmpb_box} |
| 382 |
} |
| 383 |
\hbox_overlap_left:n { \box_use:N \l_tmpa_box } |
| 384 |
\hbox_overlap_left:n { \box_use:N \l_tmpb_box } |
| 385 |
} |
| 386 |
\group_end: |
| 387 |
} |
| 388 |
\DeclareDocumentCommand \textsupersubscript {s O{l} mm} { |
| 389 |
\IfBooleanTF #1 |
| 390 |
{ \textsubsuperscript * [#2] {#4} {#3} } |
| 391 |
{ \textsubsuperscript [#2] {#4} {#3} } |
| 392 |
} |
| 393 |
% \end{macrocode} |
| 394 |
% |
| 395 |
% \begin{macrocode} |
| 396 |
\dim_new:N \subsupersep |
| 397 |
% \end{macrocode} |
| 398 |
% \end{macro} |
| 399 |
% \end{macro} |
| 400 |
% |
| 401 |
% Fin. |
| 402 |
% |
| 403 |
%\iffalse |
| 404 |
%</package> |
| 405 |
%\fi |
| 406 |
% |
| 407 |
% \Finale |
| 408 |
% |
| 409 |
% \typeout{*************************************************************} |
| 410 |
% \typeout{*} |
| 411 |
% \typeout{* To finish the installation you have to move the following} |
| 412 |
% \typeout{* file into a directory searched by XeTeX:} |
| 413 |
% \typeout{*} |
| 414 |
% \typeout{* \space\space\space realscripts.sty} |
| 415 |
% \typeout{*} |
| 416 |
% \typeout{*************************************************************} |
| 417 |
% |
| 418 |
\endinput |
| 419 |
|