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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
\documentclass[load-preamble+]{cnltx-doc}
\usepackage{spbmark,siunitx,pifont,hologo}
\usepackage[noto]{newtxmath}
\setcnltx
{
package = spbmark,
title = the spbmark package,
version = v1.42,
date = 2022/10/15,
authors = Qu Yi,
info = Customize superscript and subscript,
email = toquyi@163.com,
url = https://github.com/texno3/spbmark,
abstract =
{
\pkg*{spbmark} provides three commands \cs{super}, \cs{sub} and \cs{supersub} to improve the layout of superscript and subscript which can be adjusted the relative position and format, and can be used in text and math mode.
},
color-scheme = blue,
title-format = \huge\bfseries\scshape,
add-frame-options = {innerleftmargin = 2em},
listings-options = {numbers = none,gobble = 2},
pre-output = {\parindent = 0em},
before-skip = \smallskipamount,
after-skip = \smallskipamount
}
\makeatletter
\newcommand{\splitmeta}[2]{\meta{#1}\texttt{,}\meta{#2}}
\newcommand{\newsplitarg}[4][\splitmeta]
{
\newcommand{#2}[2]
{\code{\textcolor{argument}{#3\textnormal{#1{##1}{##2}}#4}}}
}
\newcommand{\kvsplit}[3]
{
\item\code{\option{#1}\cnltx@isvalue\splitmarg{#2}{#3}}
\cnltx@checkdefault{\hfill\newline}
}
\newsplitarg{\splitoarg}{[}{]}
\newsplitarg{\splitmarg}{\{}{\}}
\newsplitarg{\splitdarg}{(}{)}
\newnote{\newtag}[1][New]{\textcolor{red}{\ding{73}\ #1}}
\renewcommand{\emph}[1]{\textcolor{red}{#1}}
\makeatother
\begin{document}
\section{Macro package options}
\label{sec:macro package options}
The following macro package options will redefine the script commands of the \LaTeX{} kernel. If you do not specify the values of boolean options, they default to \code{true}.
\begin{options}
\keybool{text}\Default{false}
\cs{textsuperscript} and \cs{textsubscript} are equivalent to the \cs{super} and \cs{sub} commands.
\keybool{math}\Default{false}
\cs{sp} and \cs{sb} are equivalent to the \cs{super} and \cs{sub} commands.
\keybool{foot}\Default{false}
The format of the footnote mark match the superscript global move and format settings.
\opt{both}
The values of \option{text} and \option{math} two options are \code{true} at the same time.
\opt{all}
The values of \option{text}, \option{math} and \option{foot} three options are \code{true} at the same time.
\begin{example}[code-only]
\usepackage[both]{spbmark}
\usepackage[text,foot=true]{spbmark}
\end{example}
\end{options}
\section{User commands}
There are currently three commands to set superscript and subscript. Their format can be set temporarily using the optional parameters of the command, or set globally using a key-value list, see section \ref{sec:global control interface}.
\begin{commands}
\command{super}[\sarg\oarg{kv list}\marg{content}\oarg{kv list}]
This is a superscript output command. The two \meta{kv list} are equivalent.
\command{sub}[\sarg\oarg{kv list}\marg{content}\oarg{kv list}]
This is a subscript output command. The two \meta{kv list} are equivalent.
When the horizontal movement distance of the marker is \emph{non-negative}, since the \cs{super} and \cs{sub} commands put the marker in a horizontal box, the horizontal position is staggered when using superscript and subscript \emph{consecutively}, which is a different mechanism than the sequential use of \code{\^{}} and \code{\_} symbols in math mode. The following three commands save the width of the previous marker, use it for negative move of the \option{hmove} option of the next marker, and provide the corresponding alignment.
It should be noted that the following commands should save the longer width of the marker, that is, the longer width of the marker in the front, the shorter width of the marker in the back. This is due to the fact that horizontal movement uses a negative distance to leave the marker in a zero-width box state.
\command{llastwd}\newtag%
Save the width of the previous marker and provide left alignment. This is actually the width of the previous marker, and is the same as the value of \cs{rlastwd} after the next command is used.
\command{clastwd}\newtag%
Save the width of the previous marker and provide center alignment.
\command{rlastwd}\newtag%
Save the width of the previous marker and provide right alignment. Actually this is the width of the next marker.
\begin{example}
A\super{bcd}\sub{e}B \\
A\super{bcd}\sub[hmove=-\llastwd]{e}B \\
A\sub{e}\super{bcd}[hmove=-\llastwd]B \\
A\super{bcd}\sub[hmove=-\clastwd]{e}B \\
A\super{bcd}\sub[hmove=-\rlastwd]{e}B \\
\end{example}
\command{supersub}[\sarg\oarg{kv list}\marg{super cont}\marg{sub cont}\oarg{kv list}]
This is a command that outputs both superscript and subscript at the same time. You can also use the shorter command \cs{spb} instead of it. The two \meta{kv list} are equivalent.
\command{superwd}
Save the width of the superscript in the previous super-subscript command.
\command{subwd}
Save the width of the subscript in the previous super-subscript command.
\command{maxwd}
Save the maximum width of superscript and subscript in the previous super-subscript command. That is, it is the larger of the \cs{superwd} and \cs{subwd} commands.
If horizontally move is negative and its absolute value is \emph{less} than the maximum width of the marker, then the marker overlaps the subsequent text. To avoid this use the command with the \emph{asterisk} parameter or adjust the horizontal distance with the marker length commands.
\begin{example}
\spbset{spvmove=5pt,vsep=1.8ex,spcmd=\color{blue}}
A\super[hmove=-8pt]{super}B \\
A\supersub[hmove=-8pt]{examsuper}{sub}B \\
A\super*[hmove=-8pt]{super}B \\
A\supersub*[hmove=-8pt]{examsuper}{sub}B \\
A\super[hmove=-8pt]{super}\hspace{\dimexpr(\llastwd-8pt)}B \\
A\supersub[hmove=-8pt]{examsuper}{sub}\hspace{\dimexpr(\maxwd-8pt)}B
\end{example}
\command{defspbstyle}[\marg{style name}\marg{kv list}]
Defines the style of the superscript or subscript used for the \option{style} option.
\command{spbifmath}[\marg{math code}\marg{text code}]
In some cases, \code{math} or \code{text} output modes require different code for format or move. This command can be used when using the \code{match} option or changing the output mode locally, whitch should be used in the move or format options. It can switch the corresponding code according to different output modes.
\command{spbshortkv}[\marg{short opt}\marg{key value}]\newtag%
Converts any existing key-value pair to a shorthand option. The value of key \code{\#1} indicates that the shorthand option needs to be assigned a value.
\begin{example}
\spbshortkv{x}{sphmove=#1}
\defspbstyle{fancy}{sbcmd=\color{blue},mode=math}
\spbshortkv{mysb}{style=fancy}
A\super[x=2pt]{b} \\
A\sub{b}[mysb]
\end{example}
\end{commands}
The options common to \meta{kv list} of the three commands are as follows. They can also be used in \meta {key-value list} of the \cs{spbset} command. In this situation, in addition to \option{style} and \option{mode}, they will be set according to the type of the previous most recent command.
\begin{options}
\keyval{vmove}{fixed length}\Default{0pt}
Vertical move of superscript or subscript. Represents the extra vertical distance \option{vsep} between superscript and subscript in super-subscript command. The vertical movement starts at the marker horizontal baseline position.
\keyval{hmove}{fixed length}\Default{0pt}
Horizontal move of superscript or subscript. Represents the \emph{common} move of superscript and subscript in super-subscript command. The starting point for horizontal movement is to the left of the marker. Moved values can be expressed mathematically:
\begin{example}
A\super{b}[vmove=0.4ex+4pt/2,hmove=2pt*3-11.5pt] \\
A\supersub[vsep={3pt,6pt-2bp}]{examsuper}{sub}
\end{example}
\keyval{cmd}{format cmds}
The format commands of superscript or subscript. The last command can take a parameter, which accepts superscript or subscript. Represents the format of superscript and subscript in the superscript and subscript commands.
\keyval{cmd+}{format cmds}
Add code to the previous global superscript or subscript format commands.
\keyval{height}{fixed length}
The distance between the superscript or subscript baseline and the previous line. It is recommended that the superscript adjusts the height and the subscript adjusts the depth.
\keyval{depth}{fixed length}
The distance between the superscript or subscript baseline and the next line.
\keyval{style}{style name}
Use the \meta{style name} defined by the \cs{defspbstyle} command to make it work global or local.
\keychoice{mode}{text,math,match}\Default{match}
The mode of superscript or subscript output can be \code{text} or \code{math} mode. The \code{match} option automatically matches output modes according to the current mode.
\end{options}
\section{Global control interface}
\label{sec:global control interface}
\begin{commands}
\command{spbset}[\marg{key-value list}]
\pkg*{spbmark} uses the \cs{spbset} command to control the global default format of superscript and subscript. These options also apply to \meta{kv list} of the above commands. The values set by it will be overwritten by the optional parameters of the superscript and other commands.
\end{commands}
The following list of keys control the format both of superscript \emph{or} subscript.
\begin{options}
\keyval{spvmove}{fixed length}\Default{0pt}
Extra vertical move of the superscript.
\keyval{sphmove}{fixed length}\Default{0pt}
Extra horizontal move of the superscript.
\keyval{sbvmove}{fixed length}\Default{0pt}
Extra vertical move of the subscript.
\keyval{sbhmove}{fixed length}\Default{0pt}
Extra horizontal move of the subscript.
\opt{nohmove}
Cancel the horizontal move of superscript and subscript at the same time.
\opt{novmove}
Cancel the vertical move of superscript and subscript at the same time.
\keyval{spcmd}{format cmds}
The format commands of superscript. The last command in the code can take an argument, which is a superscript.
\keyval{spcmd+}{format cmds}
Add code to the previous global superscript format commands.
\keyval{sbcmd}{format cmds}
The format commands of subscript. The last command in the code can take an argument, which is a subscript.
\keyval{sbcmd+}{format cmds}
Add code to the previous global subcript format commands.
\keyval{spheight}{fixed length}
The distance between the superscript baseline and the previous line.
\keyval{spdepth}{fixed length}
The distance between the superscript baseline and the next line.
\keyval{sbheight}{fixed length}
The distance between the subscript baseline and the previous line.
\keyval{sbdepth}{fixed length}
The distance between the subscript baseline and the next line.
\end{options}
If \option{sphmove} is positive, the superscript or subscript moves to the right, conversely it moves to the left. The positive direction of vertical offset of subscript and superscript is opposite. For superscript, if \option{spvmove} is positive, the superscript moves up, conversely it moves down. For subscript, if \option{spvmove} is positive, the subscript moves down, conversely it moves up.
The following list of keys control the format of superscript \emph{and} subscript.
\begin{options}
\keyval{spbhmove}{fixed length}\Default{0pt}
Extra vertical move of the superscript and the subscript.
\kvsplit{spbcmd}{super cmds}{sub cmds}
The format commands of superscript and subscript. The first part is in superscript format, and the latter part is in subscript format. They are separated by commas, or only the first part exists.
\kvsplit{spbcmd+}{super cmds}{sub cmds}
Add code to the previous global superscript and subscript format commands.
\keyval{spbheight}{fixed length}
The distance between the superscript baseline and the previous line.
\keyval{spbdepth}{fixed length}
The distance between the subscript baseline and the next line.
\kvsplit{vsep}{super move}{sub move}\Default{0.6ex}\newtag[Changed]%
The extra vertical distance between superscript and subscript. The front part is the movement amount of the superscript, and the latter part is the movement amount of the subscript. If only the front part means that both are vertically shifted by one-half of the current value.
\keychoice{halign}{l,c,r}\Default{l}
The alignment of superscript and subscript, which contains \code{l}, \code{c}, and \code{r} parameters respectively for left, center, and right alignment.
\end{options}
\section{Examples of use}
Here is a list of the three commands, please pay attention to the usage of optional parameters. Note when the horizontal move is negative, the starting point is at the right end of the mark.
\begin{example}
\defspbstyle{fancy}{cmd=\color{purple}}
\spbset{spbcmd={\spbifmath{\mathtt}{\ttfamily},\color{blue}}}
A\super[vmove=0.2ex,hmove=0.2em,cmd=\textcolor{red}]{exam}B \\
$A\sub[style=fancy,cmd+=\mathsf,mode=math]{exam}B$ \\
A\supersub[vsep=0.6ex,halign=c]{examsuper}{sub}B \\
A\super{c}[vmove=5pt,hmove=-5.5pt]B\sub[vmove=5pt,hmove=-5pt]{d}AB
\end{example}
It can also be used with the \pkg*{siunitx} package to output superscript and subscript in the unit:
\begin{example}
\unit[mode=math]{kg.m/s\super[vmove=-1pt]{2}} \\
\qty[mode=text]{30}{A\supersub[hmove=1pt,cmd=\color{red}]{b}{c}} \\
\spbset{sbhmove=2pt}\unit[mode=text]{A\sub{b}}
\end{example}
\pkg*{spbmark} also patches the footer markers for standard document class and \cls*{KOMA-Script}. You can format the footer markers by redefining the \cs{fnmarkfont} command. Note that extra horizontal move does not work with footnote markers.
\section{Developer commands}
If you need to use the original definitions of \cs{textsuperscript}, \cs{textsubscript}, \cs{sp} and \cs{sb} after using the \option{text} or \option{math} option, then you can use the following commands:
\begin{commands}
\command{spb@textsuperscript@save}[\marg{content}]
Save the original definition of the \cs{textsuperscript} command, output superscript in the text mode.
\command{spb@textsubscript@save}[\marg{content}]
Save the original definition of the \cs{textsubscript} command, output subscript in the text mode.
\command{spb@math@super@save}[\marg{content}]
Save the original definition of the \cs{sp} command, output superscript in the math mode.
\command{spb@math@sub@save}[\marg{content}]
Save the original definition of the \cs{sb} command, output subscript in the math mode.
\end{commands}
\section{Known issues}
At present, the vertical and horizontal move are effective for the unit commands in the \pkg*{siunitx} macro package. However, due to the special mechanism that the decimal point is not recognized correctly because it's converted to a space in the \cs*{unit} command, it's recommended to use \code{pt} as the unit of move.
\nocite{*}
\end{document}
|