• No results found

Development of this package is organized at latex-underoverlap.googlecode.com.

N/A
N/A
Protected

Academic year: 2021

Share "Development of this package is organized at latex-underoverlap.googlecode.com."

Copied!
9
0
0

Bezig met laden.... (Bekijk nu de volledige tekst)

Hele tekst

(1)

The underoverlap package

Michiel Helvensteijn mhelvens+latex@gmail.com

February 3, 2013

Development of this package is organized at latex-underoverlap.googlecode.com.

I am happy to receive feedback there!

1 Introduction

TEX and L A TEX provide several commands for decorating parts of our equations—

to direct attention or to indicate some special meaning. For example:

\[ n \times x = \overbrace{x + \cdots + x}ˆn \]

n × x =

n

z }| {

x + · · · + x

I’m refering to the \overbrace, of course. You can even nest such commands:

\[ n \times x =

\overbrace{x + \underbrace{x + \cdots + x}_{n-2}{} + x}ˆn \]

n × x =

n

z }| {

x + x + · · · + x

| {z }

n−2

+ x

But they have an inherent limitation: they cannot overlap partially. For example, you cannot do the following out-of-the-box:

a +

x

z }| { b +

| {z }

y

c + d + e + f

That’s what this package is all about. It allows you to define new decorator com- mands that can partially overlap like this, as well as augment existing commands.

This document corresponds to underoverlap 0.0.1-r1, dated 2013/02/03.

(2)

2 Usage

hUOL decorator i {hnon-overlapping content i} [hoverlapping content i]

An hUOL decorator i is a decorator command prepared by this package, such as

\UOLoverbrace and \UOLunderbrace in the examples below.

If you never use the optional argument at all, they should behave exactly like the simple TEX commands \overbrace and \underbrace.

As far as the ‘current hUOL decorator i’ is concerned, the optional content is placed directly to the right of the mandatory content and both are decorated as a whole. But a subsequent hUOL decorator i will be expected directly following this one. Its decorator will cover also the optional content from the current command.

That’s how we can typeset the example from the introduction:

\[ a + \UOLoverbrace{b +}[c + d]ˆx \UOLunderbrace{+ e}_y + f \]

a +

x

z }| { b +

| {z }

y

c + d + e + f

The following hUOL decorator i commands are predefined by the package, with

\UOLoverbrace

\UOLunderbrace

\UOLoverline

\UOLunderline

obvious meaning:

• \UOLoverbrace

• \UOLunderbrace

• \UOLoverline

• \UOLunderline

Note that you are not limited to two overlapping decorators:

\[ a + \UOLoverbrace{b +}[c]ˆx \UOLunderbrace{+}[d]_y

\UOLoverbrace{+ e}ˆz + f \]

a +

x

z }| { b +

| {z }

y

c +

z

z }| { d + e + f

{hcommand sequencei} {hdefinition containing #1i}

\newUOLdecorator

Using this command you can create a new hUOL decorator i. The first argument is the desired command sequence and the second contains its definition.

Define it as if a simple \newcommand were used for a traditional decorator.

The package will automatically augment it to allow it to overlap. You can use #1 to stand for the content provided by the user. The \UOLoverline decorator, for example, was defined as follows:

\newUOLdecorator\UOLoverline{\overline{#1}}

(3)

But note that the result will not be satisfactory unless the decorator requires no horizontal space to be allocated other than for its content. For the commands listed above, this is no problem. But this may not be true for all native decorations.

For example, one may naively try to define a \UOLfbox command as follows:

\newUOLdecorator\UOLfbox{{%

\fboxsep=1.2pt \fboxrule=.8pt \fbox{$#1$}%

}}

To test it, we define the following command as well:

\newcommand\bigstrut{\vrule height 10pt depth 4pt width 0pt}

The result will look like this:

\[ a + \UOLfbox{b +c +}[d]ˆx \UOLfbox{\bigstrut + e}ˆy + f \]

a +

x

b + c +

y

d + e + f

The spacing is incorrect because \fbox allocates horizontal space for itself in addition to the space for its content and our package cannot take that into account.

We’ll have to correct for this manually:

\newUOLdecorator\UOLfbox{{%

\fboxsep=1.2pt \fboxrule=.8pt%

\kern-\fboxrule \kern-\fboxsep%

\fbox{$#1$}%

\kern-\fboxsep \kern-\fboxrule%

}}

\[ a + \UOLfbox{b +c +}[d]ˆx \UOLfbox{\bigstrut + e}ˆy + f \]

a +

x

b + c +

y

d + e + f

Much better!

Note that subscripts / superscripts will be placed directly below / above the content, even if the original decorator did not support that.

{hcommand sequencei}

\UOLaugment

This command can augment an existing native decorator command to allow over-

lapping with its original name:

(4)

\UOLaugment\overline

\UOLaugment\overbrace

\[ a + \overline{b +}[c + d] \overbrace{\bigstrut + e}ˆy + f \]

a + b +

y

z }| { c + d + e + f

Note, however, the following assumptions on the original command:

• It should not be a native TEX command such as \underline. Augmenting

\underline like this actually seems to work fine, but the TEX specification can give us no guarantees about its behavior if we do.

• It should originally only support one standard mandatory argument. If it already supported optional arguments or other code structures then that behavior will be lost after augmentation.

If these requirements are satisfied then the new command should be almost back- wards compatible. The exceptions being, of course, when you supply an optional argument or when it follows another hUOL decorator i that does. The other ex- ception is the behavior of subscripts and superscripts if the original decorator did not place them directly below / above the content.

Of course, you can manually correct for these exceptions, but be aware that backwards compatibility is not completely guaranteed if you simply augment a decorator without any other measures.

This package does not ‘pre-augment’ any commands.

{hcommand sequencei}

\UOLunaugment

Assuming that hcommand sequencei has been augmented by the \UOLaugment command, using \UOLunaugment reverses the effects and hcommand sequencei will once again have its original meaning.

3 Acknowledgements

I originaly read the following question on http://tex.stackexchange.com:

• http://tex.stackexchange.com/questions/12963

The commands of this package are partially based on the technique described by Herbert and the command definitions proposed by Martin Scharrer.

I got a lot of useful help from the answers to my own questions too:

• http://tex.stackexchange.com/questions/95786

• http://tex.stackexchange.com/questions/95897

Thanks in particular to David Carlisle and Hendrik Vogt.

(5)

4 Implementation

We now show and explain the entire implementation from underoverlap.sty.

4.1 Package Info

1 \NeedsTeXFormat{LaTeX2e}

2 \ProvidesPackage{underoverlap}[2013/02/03 0.0.1-r1

3 construct for partly overlapping math decorations]

4.2 Packages

These are the packages we’ll need.

4 \RequirePackage{etoolbox}

5 \RequirePackage{mathtools}

6 \RequirePackage{xparse}

4.3 Public Macros

\newUOLdecorator {hcontrol sequencei} {hdefinitioni}

This defines the macro hcontrol sequencei as a new decorator command that is capable of overlapping with others.

7 \NewDocumentCommand{\newUOLdecorator}{mm}{%

8 \newcommand{#1}[1]{#2}%

9 \UOLaugment{#1}%

10 }

\UOLaugment {hcontrol sequencei}

This augments the macro hcontrol sequencei to allow it to be overlapped.

11 \NewDocumentCommand{\UOLaugment}{m}{%

12 \cslet{\uol@oldcsname{#1}}{#1}%

13 \renewcommand{#1}{%

14 \ifbool{mmode}{%

15 \uol@construct{\csuse{\uol@oldcsname{#1}}}%

16 }{%

17 \csuse{\csuse{\uol@oldcsname{#1}}}%

18 }%

19 }%

20 }

\UOLunaugment {horiginal csi}

This unaugments the macro horiginal csi so it will once again have its original

meaning. This will only make sense if you’re previously augmented that command

(6)

21 \NewDocumentCommand{\UOLunaugment}{m}{%

22 \letcs{#1}{\uol@oldcsname{#1}}%

23 }

4.4 Private Macros

The content inside a decoration has three parts:

• A ‘left’ part that may overlap with the previous construct.

• A ‘middle’ part that does not overlap.

• A ‘right’ part that overlaps with the next construct.

Only the ‘middle’ and ‘right’ parts are passed as parameters throughout most of the following commands. The ‘left’ part is defined by the previous hUOL decorator i inside the \uol@overlap@content macro.

\uol@oldcsname {hcontrol sequencei}

Given a control sequence, this derives the corresponding ’old csname’ used by this package when augmenting it.

24 \newcommand{\uol@oldcsname}[1]{%

25 uol@old@\expandafter\@gobble\string#1%

26 }

\uol@construct {horiginal macroi} {hmiddlei} {hright i}

Scans ahead for subscript or superscript.

27 \NewDocumentCommand{\uol@construct}{mmO{}}{%

28 \let\uol@sup\empty%

29 \let\uol@sub\empty%

30 \@ifnextchar^{%

31 \uol@construct@sup{#1}{#2}{#3}%

32 }{%

33 \@ifnextchar_%

34 {\uol@construct@sub {#1}{#2}{#3}}%

35 {\uol@construct@final{#1}{#2}{#3}}%

36 }%

37 }

\uol@construct@sup {horiginal macroi} {hmiddlei} {hright i} ^ {hsuperscript i}

Processes superscript and scans ahead for subscript.

38 \def\uol@construct@sup#1#2#3^#4{%

39 \def\uol@sup{#4}%

40 \@ifnextchar_%

41 {\uol@construct@sup@sub{#1}{#2}{#3}}%

42 {\uol@construct@final {#1}{#2}{#3}}%

43 }

(7)

\uol@construct@sub {horiginal macroi} {hmiddlei} {hright i} _ {hsubscript i}

Processes subscript and scans ahead for superscript.

44 \def\uol@construct@sub#1#2#3_#4{%

45 \def\uol@sub{#4}%

46 \@ifnextchar^%

47 {\uol@construct@sub@sup{#1}{#2}{#3}}%

48 {\uol@construct@final {#1}{#2}{#3}}%

49 }

\uol@construct@sub@sup {horiginal macroi} {hmiddlei} {hright i} ^ {hsuperscript i}

Processes superscript and calls the ’final’ command.

50 \def\uol@construct@sub@sup#1#2#3^#4{%

51 \def\uol@sup{#4}%

52 \uol@construct@final{#1}{#2}{#3}%

53 }

\uol@construct@sup@sub {horiginal macroi} {hmiddlei} {hright i} _ {hsubscript i}

Processes subscript and calls the ’final’ command.

54 \def\uol@construct@sup@sub#1#2#3_#4{%

55 \def\uol@sub{#4}%

56 \uol@construct@final{#1}{#2}{#3}%

57 }

\uol@overlap@content This macro stores the ’overlapped’ part of the math content between two aug- mented macros. We make sure that it is empty at the beginning of a new equation.

58 \let\uol@overlap@content\@empty

\uol@construct@final {horiginal macroi} {hmiddlei} {hright i}

This command typesets the result and reserves space for the overlap.

59 \newcommand{\uol@construct@final}[3]{

The following block will set the visible ink of the decoration without visibly set- ting the content itself and without moving our current position (using \mathrlap).

60 \mathrlap{%

We do several things next. Using \mathop we allow any subscript and super- script to be positioned directly under or over the construct, even if the original command doesn’t natively support it.

We call the original command with #1 and make it initially invisible using

\phantom.

Using braces we provide the spacing most likely to be satisfactory. If it’s not,

(8)

61 \displaystyle%

62 \mathop{#1{\phantom{%

63 {\uol@overlap@content}{{}#2{}}{#3}%

64 }}}%

The following two lines set the subscript and superscript that we collected during the previous phases.

65 ^{\mathclap{\uol@sup}}%

66 _{\mathclap{\uol@sub}}%

67

}%

Next, we optionally print the debug-shadow (disabled right now).

68 %\mathrlap{\textcolor{green}{\uol@overlap@content#2#3}}%

The following code visibly typesets the ‘left’ and ‘middle’ parts of the content.

69 {\uol@overlap@content}{{}#2{}}%

We assume that the ‘right’ part (that overlaps with the next construct) will be visibly set by the following command, which will be its ‘left’ part. We store it in the \uol@overlap@content macro now.

70 \def\uol@overlap@content{#3}%

71

}

\UOLoverbrace

\UOLunderbrace

\UOLoverline

\UOLunderline

We predefine the following commands in a straightforward way:

72 \newUOLdecorator{\UOLoverbrace} {\overbrace {#1}}

73 \newUOLdecorator{\UOLunderbrace}{\underbrace{#1}}

74 \newUOLdecorator{\UOLoverline} {\overline {#1}}

75 \newUOLdecorator{\UOLunderline} {\underline {#1}}

Change History

0.0.1

General: initial version . . . . 1

0.0.1-r1

General: several improvements in the documentation . . . 1

Index

Numbers written in italic refer to the page where the corresponding entry is de- scribed; numbers underlined refer to the code line of the definition; numbers in roman refer to the code lines where the entry is used.

Symbols

\@empty . . . . 58

\@gobble . . . . 25

. . . . 30, 33, 40, 46 C

\cslet . . . . 12

D

\def . . 38, 39, 44, 45,

50, 51, 54, 55, 70

(9)

E

\empty . . . 28, 29

\expandafter . . . . 25 I

\ifbool . . . . 14 L

\let . . . . 28, 29, 58

\letcs . . . . 22 M

\mathclap . . . 65, 66

\mathop . . . . 62

\mathrlap . . . 60, 68 N

\NeedsTeXFormat . . . . 1

\newcommand . . . 8, 24, 59

\NewDocumentCommand . . . 7, 11, 21, 27

\newUOLdecorator . . . . . 7, 72–75

O

\overbrace . . . . 72

\overline . . . . 74 P

\phantom . . . . 62

\ProvidesPackage . . . 2 R

\renewcommand . . . . . 13

\RequirePackage . . . 4–6 S

\string . . . . 25 T

\textcolor . . . . 68 U

\underbrace . . . . 73

\underline . . . . 75

\uol@construct . . 15, 27

\uol@construct@final . . . 35, 42, 48, 52, 56, 59

\uol@construct@sub . . . . . 34, 44

\uol@construct@sub@sup . . . . 47, 50

\uol@construct@sup . . . . . 31, 38

\uol@construct@sup@sub . . . . 41, 54

\uol@oldcsname . . . . . 12, 15, 17, 22, 24

\uol@overlap@content . . . . 58, 63, 68–70

\uol@sub . 29, 45, 55, 66

\uol@sup . 28, 39, 51, 65

\UOLaugment . . . 9, 11

\UOLoverbrace . . . . . 72

\UOLoverline . . . . 74

\UOLunaugment . . . . . 21

\UOLunderbrace . . . . 73

\UOLunderline . . . . . 75

Referenties

GERELATEERDE DOCUMENTEN

• You must not create a unit name that coincides with a prefix of existing (built-in or created) units or any keywords that could be used in calc expressions (such as plus, fil,

[r]

This macro is part of a zero-length picture environment with basepoint at the lower left corner of the page (default) or at the upper left corner (package option ”texcoord”)..

In difference to other existing solutions, exceltex does not seek for making the creation of tables in LaTeX easier, but to get data from Spreadsheets into LaTeX as easy as

This package provides commands for vectors, matrices, and tensors with different styles (arrows as the L A TEX default, underlined, and

The output of your code is saved into the file provided as the second optional argument of \iexec (the default value is iexec.tmp ):. 6 Today is \iexec[date.txt]{date +\%e-\%b-\%Y |

gives a pattern table whose second column has width ‘width’ as a proportion of the page. The default value for this width

Numbers written in italic refer to the page where the corresponding entry is de- scribed; numbers underlined refer to the code line of the definition; plain numbers refer to the