Next Meeting: January 6: Social gathering Next Installfest: TBD Latest News: Nov. 18: Club officer elections Page last updated: 2002 Jul 12 23:12
Re: [vox-tech] TeX question: writing a robust fraction macro

# Re: [vox-tech] TeX question: writing a robust fraction macro

Henry,

A few generic things to start
* suggest using a unique-ish name
* looks like you assumed the arguments would be single characters,
e.g., 1/2, 3/4, etc.  might want to make it more generic by wrapping
the arguments, when used, with braces
* what you propose is more commonly referred to as a slanted fraction

I think you're making two assumptions:
1) Usage:  fractions should be written in numeral form (rather than
spelled out)
2) Typographic:  when the surrounding text is italicized, the fraction
should be, too

Regarding 1, it depends on the usage guide under which one is
operating.  For example, the IEEE Computer Society has fairly
specific information regarding the use of in-line fractions, preferring
built-up fractions of the form 1/2 (using a forward slash).  Other
usage guides suggest spelling our fractions in prose, e.g. one-half,
fifteen-sixteenths, etc.  So, I suggest understanding what your
domain accepts and/or requires.

Regarding 2, I believe the correct term for what you are trying
to produce is a "vulgar fraction," that is, a fraction that appears
almost as a single character in the applicable font.  Even if
I'm wrong on this, you've enter the realm of subtle typographic
issues by trying to "improve" latex.  Here's the obvious
example:  latex doesn't change the typeface of inline math when
the surrounding text is emphasized.  Accordingly, I suggest
you dig up some typography info on the web or in a book
and try to identify the "proper" form of this style of fraction
for the usage you have.  A few things come to mind:  proper
angle of the "slash"; proper form of the "slash"; vertical and
horizontal placement of the numeral above and below; and,
of course, whether such a "symbol" should or should not
be italicized amid surrounding emphasis.

My current opinion (having blown a bit of time putting together
this note) is to leave well enough alone.  In other words, don't
worry about the italic issue--even latex doesn't bother with that
(see Test 7).  Furthermore, I bet most of the time you should just
spell such fractions out.  But, if you really want or need a slanted
fraction, I think the myslantfrac macro below looks just fine.

Good luck.

shawn.

--

\documentclass[12pt]{article}
\def\myfrac#1#2{
$^{#1}\!\!/\!\!_{#2}$
}
\def\myfracb#1#2{
\raisebox{0.3ex}{\footnotesize{#1}}%
$\!/\!\!$%
\raisebox{-0.3ex}{\footnotesize{#2}}
}
\def\myslantfrac#1#2{
\hbox{$\,^{#1}\!/_{#2}$}
}
\begin{document}
Test 1: \myfrac{12}{34} more stuff \\
Test 2: \myfracb{12}{34} more stuff \\
{\em Test 3: \myfrac{12}{34} more stuff} \\
{\em Test 3b: \myfracb{12}{34} more stuff} \\
Test 4: \myslantfrac{12}{34} more stuff \\
{\em Test 5: \myslantfrac{12}{34} more stuff} \\
Test 6: $12/34$. \\
{\em Test 7: $12/34$ 12/34 more stuff} \\
{\em Test 8: $aa/bc$ more stuff} \\
Test 9: $aa/bc$ more stuff \\
\end{document}

On Friday 12 July 2002 04:35 pm, Henry House wrote:
> I'm trying to write a robust macro for literary-style fractions, in which
> the numerator is superscript and the denominator is subscript around a
> slanted line, not a strait line as in $\frac{1}{2}$. I came with:
>
> 	\def\frac#1#2{
> 		$^#1\!\!/\!\!_#2$
> 	}
>
> which is fine except that the fraction is always set in roman even in an
> italic block. I tried again:
>
> 	\def\frac#1#2{
> 		\raisebox{0.3ex}{\footnotesize{#1}}%
> 		\$\!/\!\!%
> 		\raisebox{-0.3ex}{\footnotesize{#2}}
> 	}
>
> except that there is now too much space between the denominator and the
> line when set in roman and too little in italic.
>
> I would appreciate any ideas on how to improve this.

_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech