summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/fouridx/fouridx.dtx
blob: 54ddce209fa37d27a048edf2c3353fa9e4515581 (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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
% \iffalse meta comment
% File: fouridx.dtx Copyright (C) 2008, 2013 Stefan Karrmann
% \fi
%
% \iffalse
%
%<*package>
\def\fileversion{2.00}
\def\filedate{2013/11/21}
%</package>
%<*driver>
\documentclass{ltxdoc}
\usepackage[latin1]{inputenc}
\IfFileExists{fouridx.sty}{\usepackage{fouridx}
 \let\fouridxSTYfound\active}{\GenericWarning{fouridx.dtx}{Package
 file fouridx.sty not found (Documentation will be messed up!^^J^^A
 Generate fouridx.sty by (La)TeXing fouridx.ins, process
 fouridx.dtx again)^^J}\stop}
\usepackage{longtable}
\title{The \texttt{fouridx} package\thanks{This file has version 
    \fileversion\ last revised \filedate.}}
\author{Stefan Karrmann\\\texttt{s.karrmann at web.de}}
\date{File Date \filedate, Printed \today}
\newlength{\tempdima}%
\makeatletter
\renewenvironment{table}[1][]{%
  \@float{table}[#1]%
  \centering%
  \setlength{\tempdima}{\abovecaptionskip}%
  \setlength{\abovecaptionskip}{\belowcaptionskip}%
  \setlength{\belowcaptionskip}{\tempdima}%
  }{%
\end@float
}
\makeatother
\EnableCrossrefs
\CodelineIndex
\DoNotIndex{\def,\edef,\let,\newcommand,\newenvironment,\newcounter}
\DoNotIndex{\setcounter,\space,\if,\else,\fi,\empty,\@empty,\ifx,\fi}
\DoNotIndex{\ifnum,\fi,\expandafter}
\CodelineNumbered
\RecordChanges
\CheckSum{138}
\begin{document}
 \DocInput{fouridx.dtx}
\end{document}
%</driver>
% \fi
%
% \changes{1.00}{2008/03/27}{Used leftidx.dtx as a template for the
%   English documentation}%
% \changes{2.00}{2013/11/21}{Bug fixed when line break happens
%   directly at the fouridx command. Thanks to Tilman Schr\"oder.
%   Respect math styles and enables nested calls.}%
%
% \maketitle
% \begin{abstract}
% \noindent
% This package enables left subscripts and superscripts in math mode.
% These subscripts and superscripts are automatically raised for better
% fitting to the symbol they belong to. This is done in such a way that
% the left and right subscripts and superscripts are set on the same line,
% respectivly.
% \end{abstract}
%
% \tableofcontents
%
% \section*{Copyright}
% Copyright 2007, 2013 Stefan Karrmann.
%
% This program can be redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt; either
% version 1 of the License, or any later version.
%
% \section{Introduction}
% 
% In mathematical equations, it is sometimes necessary to use indices
% (subscript or superscript) that are positioned at the left side of a
% symbol. 
% In tensor mathematics, for instance, some notations use a transponed
% sign at the left side of the symbol:
% \begin{eqnarray*}
% \fourIdx{\mathrm{t}}{}{}{}{\left(A_{ij}\right)} &=&
% \left(A_{ji}\right)
% \end{eqnarray*}
% 
% For symbols with a normal character height, this can be reached by
% simply put the indices without an own symbol:
% 
% \noindent
% \begin{minipage}[c]{0.79\linewidth}
% \leavevmode\begin{verbatim}
% ${_1^2}a_3^4$
% \end{verbatim}
% \end{minipage}
% \begin{minipage}[c]{0.19\linewidth}
% ${_1^2}a_3^4$
% \end{minipage}
% 
% \noindent
% Is the symbol larger, this leads to unsatisfactory results:
% 
% \noindent
% \begin{minipage}[c]{0.79\linewidth}
% \leavevmode\begin{verbatim}
% ${^1_2}\left(\frac{1}{b}\right)^3_4$
% \end{verbatim}
% \end{minipage}
% \begin{minipage}[c]{0.19\linewidth}
% ${^1_2}\left(\frac{1}{b}\right)^3_4$
% \end{minipage}
% 
% \noindent
% If the subscripts on the left and right side are of different height or
% the left subscripts and superscripts are of different width,
% the result is also unsatisfactory:
% 
% \noindent
% \begin{minipage}[c]{0.79\linewidth}
% \leavevmode\begin{verbatim}
% ${^{(k)}_n}A^x_{\overline x\vert}$
% \end{verbatim}
% \end{minipage}
% \begin{minipage}[c]{0.19\linewidth}
% ${^{(k)}_n}A^x_{\overline x\vert}$
% \end{minipage}
% 
% \noindent
% A better output can be reached by using the package |fouridx.sty|:
% 
% \noindent
% \begin{minipage}[c]{0.79\linewidth}
% \leavevmode\begin{verbatim}
% $\fourIdx{1}{2}{3}{4}{\left(\frac{1}{b}\right)}$
% \end{verbatim}
% \end{minipage}
% \begin{minipage}[c]{0.19\linewidth}
% $\fourIdx{1}{2}{3}{4}{\left(\frac{1}{b}\right)}$
% \end{minipage}
% 
% \noindent
% \begin{minipage}[c]{0.79\linewidth}
% \leavevmode\begin{verbatim}
% $\fourIdx{(k)}{n}{x}{\overline x\vert}A$
% \end{verbatim}
% \end{minipage}
% \begin{minipage}[c]{0.19\linewidth}
% $\fourIdx{(k)}{n}{x}{\overline x\vert}A$
% \end{minipage}
% \subsection{Old bugs/regression}{
% \newcommand{\fourIdxOld}[5]{%
%    \setbox1=\hbox{\ensuremath{^{#1}}}%
%    \setbox2=\hbox{\ensuremath{_{#2}}}%
%    \setbox5=\hbox{\ensuremath{#5}}%
%    \hspace{\ifnum\wd1>\wd2\wd1\else\wd2\fi}%
%    \ensuremath{\copy5^{\hspace{-\wd1}\hspace{-\wd5}#1\hspace{\wd5}#3}%
%                      _{\hspace{-\wd2}\hspace{-\wd5}#2\hspace{\wd5}#4}%
% }}
% \def\exA{\fourIdxOld 12345}
% \begin{tabular}[c]{llcc}
% Error & version & old & actual \\
% \hline
% math style ignored & 1.00 & \(1_{\exA}\) & \(1_{\fourIdx12345}\) \\[1ex]
% \hline
% hang over at left after line breaks & 1.00 &\rule[-3ex]{0cm}{7ex}
% \begin{minipage}{2cm}\noindent\strut\rule{1pt}{2ex}Start of
% line\hfil\break\exA
% \end{minipage}
% &
% \begin{minipage}{2cm}\noindent\rule{1pt}{2ex}Start of
% line\hfil\break$\fourIdx12345$
% \end{minipage} \\[1ex]
% \hline
% wrong positions if nested & 1.00 & \rule{0cm}{5ex}
% $\vert\fourIdxOld{\fourIdxOld{1}{2}34{51}}{2}{3x}{4}{\fourIdxOld{1}{2}{3}{4}{52}}\vert$
% &
% $\vert\fourIdx{\fourIdx{1}{2}34{51}}{2}{3x}{4}{\fourIdx{1}{2}{3}{4}{52}}\vert$
% \\[1ex]
% \hline
% \end{tabular}
% }
% \subsection{Comparison with sideset}
% The command sideset from the amsmath package has similiar functionality.
% It requires that the central box is a math operator an it typesets the
% left super- and subscript left aligned while fourIdx uses right
% alignment. Which suits better depends on the purpose.
% \section{Usage of the package}
% 
% One command is provided by the package.
% 
% \DescribeMacro{\fourIdx}%
% The \cs{fourIdx} command has the syntax
% \cs{fourIdx}\marg{left superscript}\marg{left subscript}%
% \marg{right superscript}\marg{right subscript}\marg{symbol}.
% This command typesets the symbol \meta{symbol} with indices on the
% left and on the right side.
% Example:
%
% \noindent 
% \begin{minipage}[c]{0.79\linewidth}
% \leavevmode\begin{verbatim}
% $\fourIdx1234{\left(\frac{1}{b}\right)}$
% \end{verbatim}
% \end{minipage}
% \begin{minipage}[c]{0.19\linewidth}
% $\fourIdx1234{\left(\frac{1}{b}\right)}$
% \end{minipage}
% 
% \noindent
% You may omit left or right indices by using empty arguments.
%
% The next example shows the same in the different mathematical
% styles:
% \def\asdf{\fourIdx1234{\left(\frac1b\right)}}%
% \begin{displaymath}
% \displaystyle\asdf\quad\textstyle\asdf\quad
% \scriptstyle\asdf\quad\scriptscriptstyle\asdf
% \end{displaymath}
% 
% \StopEventually{\PrintChanges \PrintIndex}
%
% \section{The implementation}
% \iffalse
%<*package>
% \fi
% Heading of the package:
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{fouridx}[\filedate\space v\fileversion\space Four indices]
%    \end{macrocode}
% \begin{macro}{\fourIdx}
% \changes{2.00}{2013/11/21}{Bug fix at line breaks, nested calls, and math
% styles}%
% \changes{1.00}{2008/03/27}{Implementation simplyfied}%
% Command for left and right indices.
%    \begin{macrocode}
\newcommand{\fourIdx}[5]{%
   \ensuremath{\mathchoice%
      {{\setbox1=\hbox{$\scriptstyle{#1}$}%
       \setbox2=\hbox{$\scriptstyle{#2}$}%
       \setbox5=\hbox{$\displaystyle{#5}$}%
       \hspace*{\ifnum\wd1>\wd2\wd1\else\wd2\fi}%
       \copy5^{\scriptstyle\hspace{-\wd1}\hspace{-\wd5}#1\hspace{\wd5}#3}%
             _{\scriptstyle\hspace{-\wd2}\hspace{-\wd5}#2\hspace{\wd5}#4}%
      }}% display
      {{\setbox1=\hbox{$\scriptstyle{#1}$}%
       \setbox2=\hbox{$\scriptstyle{#2}$}%
       \setbox5=\hbox{$\textstyle{#5}$}%
       \hspace*{\ifnum\wd1>\wd2\wd1\else\wd2\fi}%
       \copy5^{\scriptstyle\hspace{-\wd1}\hspace{-\wd5}#1\hspace{\wd5}#3}%
             _{\scriptstyle\hspace{-\wd2}\hspace{-\wd5}#2\hspace{\wd5}#4}%
      }}% text
      {{\setbox1=\hbox{$\scriptscriptstyle{#1}$}%
       \setbox2=\hbox{$\scriptscriptstyle{#2}$}%
       \setbox5=\hbox{$\scriptstyle{#5}$}%
       \hspace*{\ifnum\wd1>\wd2\wd1\else\wd2\fi}%
       \copy5^{\scriptscriptstyle\hspace{-\wd1}\hspace{-\wd5}#1\hspace{\wd5}#3}%
             _{\scriptscriptstyle\hspace{-\wd2}\hspace{-\wd5}#2\hspace{\wd5}#4}%
      }}% script
      {{\setbox1=\hbox{$\scriptscriptstyle{#1}$}%
       \setbox2=\hbox{$\scriptscriptstyle{#2}$}%
       \setbox5=\hbox{$\scriptscriptstyle{#5}$}%
       \hspace*{\ifnum\wd1>\wd2\wd1\else\wd2\fi}%
       \copy5^{\scriptscriptstyle\hspace{-\wd1}\hspace{-\wd5}#1\hspace{\wd5}#3}%
             _{\scriptscriptstyle\hspace{-\wd2}\hspace{-\wd5}#2\hspace{\wd5}#4}%
      }}% scriptscript
}}
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%</package>
% \fi
% \Finale