(1)
\makeatletter
\def\harpoon#1{\vbox{\m@th\ialign{##\crcr
\rightharpoonfill\crcr\noalign{\kern-\p@\nointerlineskip}
$\hfil\displaystyle{#1}\hfil$\crcr}}}
\def\rightharpoonfill{$\m@th\smash-\mkern-7mu%
\cleaders\hbox{$\mkern-2mu\smash-\mkern-2mu$}\hfill
\mkern-7mu\mathord\rightharpoonup$}
\let\vec\harpoon
\makeatother
(2)
\makeatletter
\def\rightharpoonupfill@#1{\setboxz@h{$#1-\m@th$}\ht\z@\z@
$#1\m@th\mathord\rightharpoonup\mkern-6mu\cleaders
\hbox{$#1\mkern-2mu\copy\z@\mkern-2mu$}\hfill
\mkern-6mu\box\z@$}
\def\overrightharpoonup{\mathpalette\overrightharpoonup@}
\def\overrightharpoonup@#1#2{
\vbox{\ialign{##\crcr\rightharpoonupfill@#1\crcr
\noalign{\kern-\ex@\nointerlineskip}$\m@th\hfil#1#2\hfil$\crcr}}}
\let\vec\overrightharpoonup
\makeatother
(3)
% First the \vec command (the raisebox enlarges the box to avoid that
% the harpoon sticks together with underlength characters like "g" in
% the line above) :
\renewcommand*{\vec}[1]{\raisebox{0pt}[\height+.3ex][\depth]{$\overrightharpoonup{#1}$}}
% Now the \overrightharpoonup command:
\makeatletter
\def\rightharpoonupfill@#1{\m@th\setboxz@h{$#1\relbar$}\ht\z@\z@
$#1\copy\z@\mkern-6mu\cleaders
\hbox{$#1\mkern-2mu\box\z@\mkern-2mu$}\hfill
\mkern-6mu\mathord\rightharpoonup$}
\def\overrightharpoonup{\mathpalette{\overarrow@\rightharpoonupfill@}}
\makeatother
(3) gives problem of putting +.3ex and I dont understand why.
(1) works but (2) has better looking arrow. However, the post by Original Poster
of post (2) was never answered. He wanted shorter arrow of small size like the standard
\vec has a shorter arrow, but harpoon style, which is what I want. Furthermore, I would
like to understand this macro completely. I only know the template of macro like
\def\name#1#1#3{ where params #1 to #3 are used }
I know makeatletter and other are used to change its category code, but dont recall
why.
Would appreciate if a TeX guru can put some explanation of the commands used to understand operation of the macro and suggest the change needed to make the arrow shorter for a single letter which is what I mostly need it. Even if there is a solution in some package, this might be a good example to fully understand this macro as an introduction.
Thanks for help on macro and
David Stolarczyk
This makes a little tabular (\ialign) with the stretchy harpoon on
the first line, reduced space between lines (that stuff in \noalign)
and the character over which to place the on the second line (#1).
This is incorrect in that it enforces \displaystyle. It won't work
in subscripts.
> \def\rightharpoonfill{$\m@th\smash-\mkern-7mu%
> \cleaders\hbox{$\mkern-2mu\smash-\mkern-2mu$}\hfill
This is the stretchy part of the harpoon shaft. It is a minus
sign (\smash-ed so it has no height or depth) repeated (that's
what leaders are) as often as necessary to fill the required
space. The negative kerns are to make sure these signs
overlap without gaps. This also will not work in
subscripts as the minus sign is always in \textstyle. Or rather, it
produces a shaft of the same thickness as a textstyle minus
sign in all cases.
> \mkern-7mu\mathord\rightharpoonup$}
The shaft is followed by the harpoon tip. The negative -7mu kerns
(like seven successive \!) at beginning and end essentially force the
harpoon
to be at least 14mu long (I think).
.
> \let\vec\harpoon
> \makeatother
>
> (2)
> \makeatletter
> \def\rightharpoonupfill@#1{\setboxz@h{$#1-\m@th$}\ht\z@\z@
This requires amsmath package (where \setbocz@h is defined).
It loads the minus sign in box \z@ (0) and smashes it
> $#1\m@th\mathord\rightharpoonup\mkern-6mu\cleaders
> \hbox{$#1\mkern-2mu\copy\z@\mkern-2mu$}\hfill
> \mkern-6mu\box\z@$}
This places the right harpoon followed by a stretchy shaft. That is
completely incorrect it should be the reverse order. To correct this
exchange "\mathord\rightharpoonup" and "\box\z@" (but change
\box to \copy).
The argument #1 is the current style (e.g., \scriptstyle in a
subscript).
Thus the harpoon and the minus sign both shrink in subscripts.
> \def\overrightharpoonup{\mathpalette\overrightharpoonup@}
\mathpalette feeds the current style as the first argument of
\overrightharpoonup@.
> \def\overrightharpoonup@#1#2{
> \vbox{\ialign{##\crcr\rightharpoonupfill@#1\crcr
> \noalign{\kern-\ex@\nointerlineskip}$\m@th\hfil#1#2\hfil$\crcr}}}
#2 is the argument to \overrightharpoonup. We see again the
small tabular (\ialign). The difference between this and (1) is that
instead of a -1pt negative vspace we have -\ex@, which amsmath
calculates (and recalculates at various points). I do not know
precisely
what its intent is, but it tends to be used between accent-like things
and their their argument.
> \let\vec\overrightharpoonup
> \makeatother
>
> (3)
> % First the \vec command (the raisebox enlarges the box to avoid that
> % the harpoon sticks together with underlength characters like "g" in
> % the line above) :
> \renewcommand*{\vec}[1]{\raisebox{0pt}[\height+.3ex][\depth]{$\overrightharpoonup{#1}$}}
The +3ex requires the calc package, otherwise it will just
print somewhere.
> % Now the \overrightharpoonup command:
> \makeatletter
> \def\rightharpoonupfill@#1{\m@th\setboxz@h{$#1\relbar$}\ht\z@\z@
> $#1\copy\z@\mkern-6mu\cleaders
> \hbox{$#1\mkern-2mu\box\z@\mkern-2mu$}\hfill
> \mkern-6mu\mathord\rightharpoonup$}
> \def\overrightharpoonup{\mathpalette{\overarrow@\rightharpoonupfill@}}
> \makeatother
>
> (3) gives problem of putting +.3ex and I dont understand why.
> (1) works but (2) has better looking arrow.
Nonsense. (2) doeean't
> >
> > (3) gives problem of putting +.3ex and I dont understand why.
> > (1) works but (2) has better looking arrow.
>
> Nonsense. (2) doeean't
[Oops, I hit the wrong button.]
(2) doen't work at all. When corrected, it looks just like (3),
which I think places the harpoon too high.
[gotta go, more later.]
Dan
> However, the post by Original Poster
> of post (2) was never answered. He wanted shorter arrow of small size like the standard
> \vec has a shorter arrow, but harpoon style, which is what I want.
You cannot get the harpoon any shorter than the length produced by
\rightharpoonup alone. This is what one gets when -7mu is used in
place of -6mu in either (2, corrected) or (3). Actually, I prefer the
placement acheived by leaving the first one as -6mu and changing
the second one to -8mu.
It _is_ possible to get smaller harpoons by using \scriptstyle
or \scriptscriptstyle. Here's a modification of (2, corrected) that
uses the smallest existing harpoon (\scriptscriptstyle):
\def\rightharpoonupfill@#1{\setboxz@h{$\scriptscriptstyle-\m@th$}\ht\z@\z@
$\scriptscriptstyle\m@th\copy\z@\mkern-7mu\cleaders
\hbox{$\scriptscriptstyle\mkern-2mu\copy\z@\mkern-2mu$}\hfill
\mkern-7mu\mathord\rightharpoonup$}
\def\overrightharpoonup{\mathpalette\overrightharpoonup@}
\def\overrightharpoonup@#1#2{
\vbox{\ialign{##\crcr\rightharpoonupfill@#1\crcr
\noalign{\kern-\ex@\nointerlineskip}$\m@th\hfil#1#2\hfil$\crcr}}}
\let\vec\overrightharpoonup
> I know makeatletter and other are used to change its category code, but dont recall
> why.
When TeX sees a "\" it constructs the command name from either
the next character (if it is not a letter) or the longest unbroken
string
of letters that follows. Ordinarily, "@" is not a letter so, for
example,
"\z@" is the command "\z" followed by the character "@". TeX allows
one to change the category of character, and a convention has been
established to make @ a letter in .sty, .cls and .ltx files. The
purpose
is to keep a user from accidentally redefining internal commands.
One has to type \makeatletter to be able to use internal commands
(like \z@) or to modify them or to create ones of your own (like
\overrightharpoon@, above). One can hardly type \makeatletter
accidentally.
Dan
It works nice except that the harpoon has a tail sticking out. I got the calc package. Can I somehow calculate the width of the harpoon as a function of the width of the char it is sitting on?
For understanding the macro, is there a database or list somewhere to understand these commands. Plez see that I am trying to understand one macro THOROUGHLY so that I can help others on this forum like you can.
Here is the list of commands not clear to me:
\setboxz@h
\m@th$
\ht
\z@
\copy
\mkern-7mu
\cleaders
\hbox{} <-- horiz box like \vbox
\hfill <--
\mathord
\mathpalette
\vbox{}
\ialign
\crcr
\noalign{}
\ex@
\nointerlineskip
\hfil#1#2\hfil$
I want to understand this keyword by keyword and dissect the syntax. Thanks to anyone who can help.
David Stolarczyk
David Stolarczyk
\mathsurround=0pt
>\ht
>\z@
a dimen=0pt
>\copy
>\mkern-7mu
>\cleaders
>\hbox{} <-- horiz box like \vbox
>\hfill <--
>\mathord
>\mathpalette
>\vbox{}
>\ialign
>\crcr
>\noalign{}
>\ex@
pass (defined elsewhere in the solution?)
>\nointerlineskip
>\hfil#1#2\hfil$
the ones i've not marked will be explained in any good tex book. the
commonest recommendation is knuth's texbook (one word, confusingly
typeset), but i prefer tex by topic, which is out of print and freely
available on the net (donations accepted... ;-)
>I want to understand this keyword by keyword and dissect the
>syntax. Thanks to anyone who can help.
tex is a tricky language (as are most even moderately powerful macro
processor languages). starting by learning the workings of a
complicated macro is a recipe for huge time wasting.
--
Robin Fairbairns, Cambridge
Defined in amsmath.sty means \setbox0=\hbox, that is,
whatever brace group follows is stored in \box register 0
> \m@th$
Defined in plain tex and latex, it means \mathsurround=0pt.
This is used when we want to measure things in math and
avoid automatically added extra space. The value at the end
of the math mode is used on both left and right.
> \ht
Gets the height of a box. The height of \box 0 is \ht 0.
It requires an integer to follow.
> \z@
This is an abbreviation for 0pt. A distance of zero printer
points. TeX can also use distances as integers (every
dimension is converted to an integer number of a tiny
unit called scaled points (abbreviated sp). There are 72.27
pt in an inch and 65536 sp in one pt. Thus, \ht\z@\z@
means \ht 0=0pt.
> \copy
Must be followed by an integer. Places a copy of the
corresponding \box register it the current position, but
does not clear the register afterwards. \copy\z@
places a copy of \box 0, defined at the start.
> \mkern-7mu
Like \kern, but it only works in math mode with math
units (mu). This means to move the current point left
by seven math units. The value of a math unit changes
depending on the context (it shrinks in subscripts).
Strictly speaking, it is determined by font metrics, but
by convention it is 1/18 of the size of a \quad (10/18 pt
in most 10pt documents, 7/18 in subscripts, 5/18 in
subsubscripts).
> \cleaders
Takes whatever box follows and repeats it often enough
to fill out the space that occurs after it. Since boxes have
fixed length, it may not be possible for a whole number of
boxes to equal the required space. In that case TeX stops
when it is a fraction of a box short, and the "c" in \cleaders
says to center the result in the required space.
> \hbox{} <-- horiz box like \vbox
The contents are typeset as if in a paragraph, but no line
breaking is performed.
> \hfill <--
Calculate the required space to fill up the enclosing box.
In this example, it is part of an alignment, and the enclosing
box is the size of the character on the line below in the
alignment.
> \mathord
The \rightharpoonup is normally treated as a math relation,
the minus sign is a binary operation. Both those things (and
other things) imply certain spacing conventions. \mathord
says to treat the following math item (a single symbol or a list
in braces) as an ordinary character.
> \mathpalette
As I posted, this merely feeds the current math style to
the command that follows. That is
\mathpalette\X{arg}
becomes
\X\displaystyle{arg}% in a display
\X\textstyle{arg}% in inline math
\X\scriptstyle{arg}% in sub/superscripts
\X\scriptscriptstyle% in subsub/supersuperscripts.
> \vbox{}
Contents are typeset and handled as if in between
paragraphs. Bare text starts a paragraph, boxes are
stacked vertically. Alignments are required to be in
vertical mode.
> \ialign
Starts an alignment with certain initializations set.
Something like:
\normalbaselines, \everycr={}\halign
[You probably want to know what \halign means, too.]
> \crcr
Same as \cr: ends the current line of an alignment.
It also ends the preamble of an alignment.
Differs from \cr that if it immediately follows a \cr it is ignore
(where \cr\cr makes an empty extra line). This is used
where a user might conceivably type a \cr at the end of an
argument. It seems unlikely that \overrightharpoonup{x\cr}
would ever be typed, but who knows.
> \noalign{}
Contains vertical stuff inserted between the previous and
next line of an \halign.
> \ex@
A dimension calculated by amsmath.sty. It aims to change
depending on the current surrounding font size. It is 1pt if
that font size is 10pt, it increases with font size to
about 1.5pt in a 20pt region, and stays at 1.5pt for larger
sizes. It is less than 1pt for font sizes less than 10 pt, but
never gets below 0.5pt. It is used for vertical distances. One
can usually assume it is about a 1 pt.
> \nointerlineskip
Do not place the automatic vertical space added between lines.
> \hfil#1#2\hfil$
#1 is the style #2 is the object being accented. In a subscript
and \overrightharpoonup{x}, this will be
\hfil\scriptstyle x\hfil
the meaning of \hfil is to add space sufficient to fill the
enclosing box. In this case it is in an alignment, and that
box is either the width of the x or the width of the line above
(the \rightharpoonup). This centers the x with the harpoon.
It doesn't seem properly centered because the x is slanted
a bit.
>
> I want to understand this keyword by keyword and dissect the syntax.
> Thanks to anyone who can help.
You need a book that does such things. Get hold of
Victor Eikhout's "TeX by Topic" (free download) and also
(if you are really serious) buy Knuths "The TeXbook".
These will cover those topics you didn't ask about:
\hfill, \halign, and \cr, in particular.
Dan