summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/spbmark/spbmark.tex
blob: a8f74d041b2de8b94711863f388f937de8843c2c (plain)
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
\documentclass[load-preamble+]{cnltx-doc}

\usepackage{spbmark,siunitx}
\usepackage[noto]{newtxmath}
\setcnltx
  {
    package           = spbmark,
    title             = the spbmark package,
    version           = v1.2B,
    date              = 2021/12/16,
    authors           = Qu Yi,
    info              = Customize superscript and subscript,
    email             = q1jx@foxmail.com,
    url               = https://github.com/texl3/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},
    pre-output        = {\parindent = 0em}
  }

\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}}}
\newsplitarg{\splitoarg}{[}{]}
\newsplitarg{\splitmarg}{\{}{\}}
\newsplitarg{\splitdarg}{(}{)}
\makeatother

\begin{document}

\section{Macro package options}
\label{sec:macro package options}
The following macro package options will redefine the scripts 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 offsets and format of the \cs{spbset} global setting.
  \opt{both}\Default!
  The values of \option{text} and \option{math} two options are \code{true} at the same time.
  \opt{all}\Default!
  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}[\oarg{kv list}\splitoarg{height}{depth}\marg{content}\oarg{kv list}]
  This is a superscript output command. The two \meta{kv list} are equivalent.
  \command{sub}[\oarg{kv list}\splitoarg{height}{depth}\marg{content}\oarg{kv list}]
  This is a subscript output command. The two \meta{kv list} are equivalent.
  \command{supersub}[\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.
\end{commands}

The optional parameter \splitmeta{height}{depth} generally does not need to be used. The \meta{height} and \meta{depth} are separated by commas. Only the front part indicates the \meta{height} of the superscript or subscript, and only the back part indicates the \meta{depth}.

The options common to \meta{kv list} of the three commands are as follows. They can be used in \meta{key-value list} for the \cs{spbset} command. If \option{vshift}, \option{hshift} and \option{cmd} are used in the \cs{spbset} command, it is set according to the type of the previous nearest command.
\begin{options}
  \keyval{vshift}{fixed length}\Default{0pt}
  Vertical shift of superscript or subscript. Represents the vertical distance \option{vsep} between superscript and subscript in the superscript and subscript commands.
  \keyval{hshift}{fixed length}\Default{0pt}
  Horizontal shift of superscript or subscript. Represents the common shift in the superscript and subscript commands.
  \keyval{cmd}{format cmds}\Default
  The format command 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.
  \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 or subscript.
\begin{options}
  \keyval{spvshift}{fixed length}\Default{0pt}
  Extra vertical shift of the superscript. 
  \keyval{sphshift}{fixed length}\Default{0pt}
  Extra horizontal shift of the superscript.
  \keyval{sbvshift}{fixed length}\Default{0pt}
  Extra vertical shift of the subscript.
  \keyval{sbhshift}{fixed length}\Default{0pt}
  Extra horizontal shift of the subscript.
  \opt{nohshift}\Default!
  Cancel the horizontal offset of superscript and subscript at the same time.
  \opt{novshift}\Default!
  Cancel the vertical offset of superscript and subscript at the same time.
  \keyval{spcmd}{format cmds}\Default
  Control the format of superscript, the last command in the code can take an argument, which is a superscript.
  \keyval{sbcmd}{format cmds}\Default
  Control the format of subscript, the last command in the code can take an argument, which is a subscript.
\end{options}

If \option{sphshift} is positive, the superscript or subscript moves to the right, and if it is negative, it moves to the left. However, for superscript, if \option{spvshift} is positive, the superscript moves up, and if spvshift is negative, it moves down. For subscripts, if \option{spvshift} is positive, the subscript moves down, and if spvshift is negative, it moves up.

The following list of keys control the format of superscript and subscript.
\begin{options}
  \keyval{spbhshift}{fixed length}\Default{0pt}
  Extra vertical shift of the superscript and the subscript.
  \kvsplit{spbcmd}{super cmds}{sub cmds}\Default
  Control the format of superscript or 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.
  \keyval{vsep}{fixed length}\Default{0.3ex}
  The distance between superscript and subscript, its default value is \code{0.3ex}.
  \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 offset is negative, the starting point is at the right end of the mark.
\begin{example}
\spbset{spbcmd={\ttfamily,\color{blue}}}
A\super[vshift=0.2ex,hshift=0.2em,cmd=\textcolor{red}]{exam}B \\
$A\sub[cmd=\mathsf,mode=math]{exam}B$ \\
A\supersub[vsep=0.3ex,halign=c]{examsuper}{sub}B \\
A\super{c}[vshift=5pt,hshift=-1.5pt]B\sub[vshift=5pt,hshift=-1pt]{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[vshift=-1pt]{2}} \\
\qty[mode=text]{30}{A\supersub[hshift=1pt,cmd=\color{red}]{b}{c}} \\
\spbset{sbhshift=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 shift 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 offsets 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 offset.

\nocite{*}

\end{document}