| 1 |
\documentclass[a4paper,article,oneside,10pt]{memoir} |
| 2 |
|
| 3 |
\usepackage[utf8]{inputenc} |
| 4 |
\usepackage[T1]{fontenc} |
| 5 |
\usepackage{babel} |
| 6 |
\usepackage{kpfonts,microtype} |
| 7 |
|
| 8 |
\usepackage{leftindex,listings,showexpl} |
| 9 |
|
| 10 |
\usepackage[hidelinks]{hyperref} |
| 11 |
|
| 12 |
\frenchspacing |
| 13 |
|
| 14 |
\newcommand\entrydescription[1]{% |
| 15 |
\textlangle\textrm{\textit{#1}}\textrangle |
| 16 |
} |
| 17 |
|
| 18 |
\catcode`<=\active |
| 19 |
|
| 20 |
\def<#1>{\entrydescription{#1}} |
| 21 |
|
| 22 |
\lstset{ |
| 23 |
language=[LaTeX]TeX, |
| 24 |
basicstyle=\ttfamily\small, |
| 25 |
commentstyle=\itshape\ttfamily\small, |
| 26 |
escapechar=@, |
| 27 |
alsoletter=\\, |
| 28 |
breaklines=true, |
| 29 |
breakindent={0pt}, |
| 30 |
captionpos=t, |
| 31 |
pos=r, |
| 32 |
tabsize=2, |
| 33 |
inputencoding=utf8, |
| 34 |
extendedchars=true, |
| 35 |
explpreset={numbers=none,}, |
| 36 |
} |
| 37 |
|
| 38 |
\newcommand\pkgleftindex{\texttt{leftindex}} |
| 39 |
|
| 40 |
\title{\pkgleftindex\ -- left indices with better spacing (v0.2$\beta$)} |
| 41 |
\date{\today} |
| 42 |
\author{Sebastian \O rsted (\href{mailto:[email protected]}{[email protected]})} |
| 43 |
|
| 44 |
\hypersetup{ |
| 45 |
pdfauthor={Sebastian \O rsted}, |
| 46 |
pdftitle={leftindex -- left indices with better spacing}, |
| 47 |
} |
| 48 |
|
| 49 |
\begin{document} |
| 50 |
|
| 51 |
\maketitle |
| 52 |
|
| 53 |
\noindent |
| 54 |
The package \pkgleftindex\ provides commands for typesetting left indices. |
| 55 |
Unlike any other similar package I know of, \pkgleftindex\ also indents the left superscript, producing much better spacing in general: |
| 56 |
\[ |
| 57 |
\leftindex^a_b{f} |
| 58 |
\qquad\text{(compare to $\leftindex[]^a_b{f}$)} |
| 59 |
. |
| 60 |
\] |
| 61 |
As \TeX\ provides no metrics for the indentation of left superscripts, |
| 62 |
the only way to accomplish this is to measure the negative indentation of the right subscript and then use that value. |
| 63 |
This works well for most symbols, with a few exceptions, which can be dealt with by |
| 64 |
supplying a few extra arguments. |
| 65 |
The package is a generalization of egreg's excellent code found at |
| 66 |
\begin{center} |
| 67 |
\url{https://tex.stackexchange.com/questions/557655/low-level-command-for-controlling-left-superscript-spacing/} |
| 68 |
\end{center} |
| 69 |
|
| 70 |
\chapter*{The commands} |
| 71 |
|
| 72 |
The main user-level command of~\pkgleftindex\ is called~\lstinline!\leftindex! and has |
| 73 |
the syntax |
| 74 |
\begin{lstlisting} |
| 75 |
\leftindex^{@<left superscript>@}_{@<left subscript>@}{@<symbol>@} |
| 76 |
\end{lstlisting} |
| 77 |
Both the arguments <left superscript> and <left subscript> |
| 78 |
are optional. Let us see it in action: |
| 79 |
\begin{LTXexample} |
| 80 |
$ \leftindex^a_b {f} $, |
| 81 |
$ \leftindex^t {X} $ |
| 82 |
$ \leftindex_b {J} $, |
| 83 |
$ \leftindex_v^u {\Pi} $, |
| 84 |
$ \leftindex{A} $, |
| 85 |
\[ |
| 86 |
\leftindex^1_0 { \int } |
| 87 |
f(x)\, dx |
| 88 |
\] |
| 89 |
\end{LTXexample} |
| 90 |
For the indentaiton of the left superscript, the package by default |
| 91 |
uses the negative indentation of the right subscript. This yields good results |
| 92 |
most of the time, as seen above. However, there are cases where this goes wrong, |
| 93 |
the most notable example being the Greek letter~$ \Gamma $ in many fonts (not in Computer Modern, though). Less serious examples arise with letters like $P$ and $L$: |
| 94 |
\begin{LTXexample} |
| 95 |
$ \Gamma^a_b $ |
| 96 |
vs. |
| 97 |
$ \leftindex^a_b {\Gamma} $, |
| 98 |
$ L^a_b $ |
| 99 |
vs. |
| 100 |
$ \leftindex^a_b {L} $, |
| 101 |
$ P^a_b $ |
| 102 |
vs. |
| 103 |
$ \leftindex^a_b {P} $ |
| 104 |
\end{LTXexample} |
| 105 |
To solve this issue, \lstinline!\leftindex! takes two |
| 106 |
additional, optional arguments: |
| 107 |
\begin{lstlisting} |
| 108 |
\leftindex[@<slanting phantom>@][@<height phantom>@] |
| 109 |
^{@<left superscript>@}_{@<left subscript>@}{@<symbol>@} |
| 110 |
\end{lstlisting} |
| 111 |
The package will then use the <slanting phantom> instead of the <symbol> to calculate the indentation of the superscript. The argument can be left empty, in which |
| 112 |
case the left superscript will not be indented at all, which is the right solution for the symbol~$ \Gamma $: |
| 113 |
\begin{LTXexample} |
| 114 |
$\leftindex[]^a_b {\Gamma}$, |
| 115 |
$\leftindex[I]^a_b {L}$, |
| 116 |
$\leftindex[I]^a_b {P}$ |
| 117 |
\end{LTXexample} |
| 118 |
By default, the <slanting phantom> is also used for calculating the height of the indices. |
| 119 |
If this is not the behaviour you want, you can supply an additional <height phantom>: |
| 120 |
\begin{LTXexample} |
| 121 |
$\leftindex[][\Bigg|]^a_b{x}$ |
| 122 |
\end{LTXexample} |
| 123 |
I doubt anyone will ever really need this much in practice, but the option is provided for completeness. |
| 124 |
|
| 125 |
Sometimes, having to include the symbol as a mandatory argument can be a burden. For these cases, I also provide the command~\lstinline!\LeftIndex! with the syntax: |
| 126 |
\begin{lstlisting} |
| 127 |
\LeftIndex[@<slanting phantom>@][@<height phantom>@] |
| 128 |
^{@<left superscript>@}_{@<left subscript>@} |
| 129 |
\end{lstlisting} |
| 130 |
Here, all arguments are optional. |
| 131 |
With this, we can do stuff like: |
| 132 |
\begin{LTXexample} |
| 133 |
$\LeftIndex^a_b \Gamma $, |
| 134 |
$\LeftIndex[]^a_b L $, |
| 135 |
$\LeftIndex[I]^a_b$, |
| 136 |
$\LeftIndex[I]^a_b$ |
| 137 |
\end{LTXexample} |
| 138 |
|
| 139 |
|
| 140 |
I also provide the more primitive, underlying command with four mandatory arguments: |
| 141 |
\begin{lstlisting} |
| 142 |
\manualleftindex{@<height phantom>@}{@<slanting phantom>@} |
| 143 |
{@<left superscript>@}{@<left subscript>@} |
| 144 |
\end{lstlisting} |
| 145 |
This one is mainly intended for use in commands and by other packages. |
| 146 |
Note that the arguments <height phantom> and <slanting phantom> have |
| 147 |
switched places compared to the commands \lstinline!\leftindex! and~\lstinline!\LeftIndex!. |
| 148 |
This is because <height phantom> is regarded as a ``more important'' |
| 149 |
argument than <slanting phantom> from an implementation point of view, |
| 150 |
but the user is probably less likely to change it. Therefore, |
| 151 |
the user-level commands \lstinline!\leftindex! and~\lstinline!\LeftIndex! have <slanting phantom> |
| 152 |
before <height phantom>. |
| 153 |
Note also that \lstinline!\manualleftindex! (like \lstinline!\LeftIndex!) does not take a <symbol>; |
| 154 |
you will have to write this yourself afterwards: |
| 155 |
\begin{LTXexample} |
| 156 |
$\manualleftindex{P}{I}{a}{b}$ |
| 157 |
vs. |
| 158 |
$\manualleftindex{P}{I}{a}{b} P$ |
| 159 |
\end{LTXexample} |
| 160 |
|
| 161 |
\end{document} |