ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* "nicefrac" LaTeX package equivalent?
@ 2002-04-11  7:48 Daniel Pittman
  2002-04-14 20:47 ` Hans Hagen
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Pittman @ 2002-04-11  7:48 UTC (permalink / raw)


I have tried to find some predefined code in ConTeXt to do the
equivalent of the 'nicefrace' package for LaTeX. This, basically,
involves typesetting a fraction as:

    1/
    /2

This is scaled down somewhat to make it fairly close to the size of the
surrounding text and positioned such that the spacing between the
numbers and the dividing slash is quite tight.

I can do this myself using raise, lower and kern operations, but it
would be nicer and (presumably) much more reliable if written by someone
who knew more about TeX character layout than I do.

I only have a need for this in running text, incidentally, and don't
care at all about math mode. 

        Daniel

-- 
Here with a Newsgroup, where we talk of Quoste,
  A Cup of Coffee and a Slice of Toast;  
    The Bits flow Eastward in the Packet Stream:
  Who is the Poster, pray, and who the Post? 
        -- Omar Kyahham


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: "nicefrac" LaTeX package equivalent?
  2002-04-11  7:48 "nicefrac" LaTeX package equivalent? Daniel Pittman
@ 2002-04-14 20:47 ` Hans Hagen
  2002-04-15  9:02   ` Patrick Gundlach
                     ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Hans Hagen @ 2002-04-14 20:47 UTC (permalink / raw)
  Cc: ntg-context

At 05:48 PM 4/11/2002 +1000, Daniel Pittman wrote:
>I have tried to find some predefined code in ConTeXt to do the
>equivalent of the 'nicefrace' package for LaTeX. This, basically,

hm, dunno packages that well -) does this mean that one macro has a whole 
package?

>involves typesetting a fraction as:
>
>     1/
>     /2
>
>This is scaled down somewhat to make it fairly close to the size of the
>surrounding text and positioned such that the spacing between the
>numbers and the dividing slash is quite tight.
>
>I can do this myself using raise, lower and kern operations, but it
>would be nicer and (presumably) much more reliable if written by someone
>who knew more about TeX character layout than I do.

well, let me show you a couple of tricks then, see below:

>I only have a need for this in running text, incidentally, and don't
>care at all about math mode.

This is text mode anyway, so take your choice:

\def\textfrac#1#2%
   {\hbox{\high{\tx#1\kern-.25em}/\low{\kern-.25em\tx#2}}}

test \textfrac{1}{2} test \textfrac{123}{456} test

\def\textfrac#1#2%
   {\hbox{\high{\tx#1}\hbox to \zeropoint{\hss/\hss}\low{\tx#2}}}

test \textfrac{1}{2} test \textfrac{123}{456} test

\def\textfrac#1#2%
   {\dontleavehmode
    \hbox
      {\setbox0\hbox{/}%
       \setbox2\hbox{\txx57}%
       \raise\ht0\hbox{\lower\ht2\hbox{\txx#1}}%
       \hbox to \zeropoint{\hss/\hss}%
       \lower\dp0\hbox{\raise\dp2\hbox{\txx#2}}}}

test \textfrac{1}{2} test \textfrac{123}{456} test

Now, if you really want to see something nice, say \showmakeup before the 
calls to this macro -)

What do others think? Which one is the nicest for default (i opt for the 
(as usual best) third one, so that one goes into core-mis.tex and will end 
up in the documentation void -)

Hans

-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
                        information: http://www.pragma-ade.com/roadmap.pdf
                     documentation: http://www.pragma-ade.com/showcase.pdf
-------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: "nicefrac" LaTeX package equivalent?
  2002-04-14 20:47 ` Hans Hagen
@ 2002-04-15  9:02   ` Patrick Gundlach
  2002-04-16 12:10     ` Hans Hagen
  2002-04-15 14:22   ` Daniel Pittman
  2002-04-15 16:38   ` James H. Cloos Jr.
  2 siblings, 1 reply; 7+ messages in thread
From: Patrick Gundlach @ 2002-04-15  9:02 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 1013 bytes --]

Hi,

> hm, dunno packages that well -) does this mean that one macro has a whole
> package?

sometimes there are two or even more macros inside a packge! But that is 
the way LaTeX is: a small kernel with no changes in the last decade and a 
great number of additional stuff which is packed in packages. So you 
sometimes have pages of \usepackage{...} statements :)

> What do others think? Which one is the nicest for default (i opt for the
> (as usual best) third one, so that one goes into core-mis.tex and will
> end up in the documentation void -)

well, I don't like any of those. The spacing in the last two is too tight. 
The first one is kind of ok, but I'd choose a smaller / 

\def\textfrac#1#2%
   {\hbox{\tx\high{#1\kern-.15em}\raise .2ex\hbox {/}\low{\kern-.15em#2}}}

 test \textfrac{1}{2} test \textfrac{123}{456} test

This also comes close to what my favourite typography book says. I don't 
know if the def is bulletproof against other fonts/setups. 

-- 
Viele Grüße, 

    Patrick Gundlach


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: "nicefrac" LaTeX package equivalent?
  2002-04-14 20:47 ` Hans Hagen
  2002-04-15  9:02   ` Patrick Gundlach
@ 2002-04-15 14:22   ` Daniel Pittman
  2002-04-15 16:38   ` James H. Cloos Jr.
  2 siblings, 0 replies; 7+ messages in thread
From: Daniel Pittman @ 2002-04-15 14:22 UTC (permalink / raw)


On Sun, 14 Apr 2002, Hans Hagen wrote:
> At 05:48 PM 4/11/2002 +1000, Daniel Pittman wrote:
>>I have tried to find some predefined code in ConTeXt to do the
>>equivalent of the 'nicefrace' package for LaTeX. This, basically,
> 
> hm, dunno packages that well -) 

I figured it might help if my description totally sucked. That way
people would know what I was aiming for and could check the original if
they cared that deeply about my little problems. ;)

> does this mean that one macro has a whole package?

Um, yeah, pretty much. It claims to take do a good job in math mode
also, though I don't know what values of "good" it uses in this context.

One of my main reasons for enjoying ConTeXt, not LaTeX, work so far has
been that, in ConTeXt, there are not twenty or thirty things like this
to do single macro jobs.

Ideas tend to either be solid, complete and in the distribution or
sufficiently simple to implement with the ConTeXt support code that it's
nice to write them.

[...]

>>I can do this myself using raise, lower and kern operations, but it
>>would be nicer and (presumably) much more reliable if written by
>>someone who knew more about TeX character layout than I do.
> 
> well, let me show you a couple of tricks then, see below:

Thanks for taking the time to share your knowledge. It's really very
nice of you. :)

[...]

> \def\textfrac#1#2%
>    {\dontleavehmode
>     \hbox
>       {\setbox0\hbox{/}%
>        \setbox2\hbox{\txx57}%
>        \raise\ht0\hbox{\lower\ht2\hbox{\txx#1}}%
>        \hbox to \zeropoint{\hss/\hss}%
>        \lower\dp0\hbox{\raise\dp2\hbox{\txx#2}}}}
> 
> test \textfrac{1}{2} test \textfrac{123}{456} test
> 
> Now, if you really want to see something nice, say \showmakeup before
> the calls to this macro -)

Very impressive, compared to the others -- it seems a much cleaner
layout, in the glue.

> What do others think? Which one is the nicest for default (i opt for
> the (as usual best) third one, so that one goes into core-mis.tex and
> will end up in the documentation void -)

The last looks the best for single digit figures, by far. It seems about
equivalent to the second last for the longer sequences, anyway.

Thanks,
        Daniel

-- 
An expert is a person who has made all the mistakes which can be made
in a very narrow field.
        -- Niels Bohr


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: "nicefrac" LaTeX package equivalent?
  2002-04-14 20:47 ` Hans Hagen
  2002-04-15  9:02   ` Patrick Gundlach
  2002-04-15 14:22   ` Daniel Pittman
@ 2002-04-15 16:38   ` James H. Cloos Jr.
  2 siblings, 0 replies; 7+ messages in thread
From: James H. Cloos Jr. @ 2002-04-15 16:38 UTC (permalink / raw)
  Cc: ntg-context

Just a thought:

Seems like it would be useful for any support for vulgar fractions to
make use of the fraction and fraction component glyphs in whatever
font is in use.

For cm and ec, there are enough design sizes that using a smaller font
for the numerator and denominator is reasonable.  MM fonts with optical
scales also allow for this.  But most fonts don't work nearly as well.

Expert fonts however contain all of the required components to produce
high quality results.  Some even have the correct kern pairs so that
just setting eg U+2075 U+2044 U+2087 (to use the unicode character values)
would produce a well set five-sevenths.  (The adobe ps names for those
characters/glyphs would be /fivesuperior /fraction /seveninferior.)

(As a side note, Unicode has both U+2044 FRACTION SLASH and U+2215
DIVISION SLASH; Adobe fonts use the same glyph for each character,
for compatability with wgl4....)

-JimC


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: "nicefrac" LaTeX package equivalent?
  2002-04-15  9:02   ` Patrick Gundlach
@ 2002-04-16 12:10     ` Hans Hagen
  2002-04-17  2:59       ` Daniel Pittman
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2002-04-16 12:10 UTC (permalink / raw)


Vulgar (i like that more than Nice) Fraction again:

So, i need to satisy everyone,

\chardef\vulgarfractionmethod=3

\definehspace[vulgarfraction][.25em] % [.15em]
\definesymbol[vulgarfraction][/]     % [\raise.2ex\hbox{/}]

\def\vulgarfraction#1#2%
   {\dontleavehmode
    \hbox
      {\def\vulgarfraction{vulgarfraction}%
       \ifcase\vulgarfractionmethod
         #1\symbol[\vulgarfraction]#2%
       \or
         \high{\tx#1\kern-\hspaceamount\vulgarfraction}%
         \symbol[\vulgarfraction]%
         \low{\kern-\hspaceamount\vulgarfraction\tx#2}%
       \or
         \high{\tx#1}%
         \hbox to \zeropoint{\hss\symbol[\vulgarfraction]\hss}%
         \low{\tx#2}%
       \or
         \setbox0\hbox{\symbol[\vulgarfraction]}%
         \setbox2\hbox{\txx57}%
         \raise\ht0\hbox{\lower\ht2\hbox{\txx#1}}%
         \hbox to \zeropoint{\hss\symbol[\vulgarfraction]\hss}%
         \lower\dp0\hbox{\raise\dp2\hbox{\txx#2}}%
       \fi}}

\ifx\vfrac\undefined \let\vfrac\vulgarfraction \fi

%D \starttabulate
%D \HL
%D \NC \bf method \NC \bf visualization \NC\NR
%D \HL
%D \NC 0 \NC \chardef\vulgarfractionmethod0\vulgarfraction{1}{2} \NC\NR
%D \NC 1 \NC \chardef\vulgarfractionmethod1\vulgarfraction{1}{2} \NC\NR
%D \NC 2 \NC \chardef\vulgarfractionmethod2\vulgarfraction{1}{2} \NC\NR
%D \NC 3 \NC \chardef\vulgarfractionmethod3\vulgarfraction{1}{2} \NC\NR
%D \HL
%D \stoptabulate

so, it's kind of configurable

Hans
-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
                        information: http://www.pragma-ade.com/roadmap.pdf
                     documentation: http://www.pragma-ade.com/showcase.pdf
-------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: "nicefrac" LaTeX package equivalent?
  2002-04-16 12:10     ` Hans Hagen
@ 2002-04-17  2:59       ` Daniel Pittman
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel Pittman @ 2002-04-17  2:59 UTC (permalink / raw)


On Tue, 16 Apr 2002, Hans Hagen wrote:
> Vulgar (i like that more than Nice) Fraction again:

I believe it's a more correct name, also. :)

[...]

>        \or % method 1
>          \high{\tx#1\kern-\hspaceamount\vulgarfraction}%
>          \symbol[\vulgarfraction]%
>          \low{\kern-\hspaceamount\vulgarfraction\tx#2}%

This reports the error:

systems        : begin file test at line 32
! Undefined control sequence.
<argument> \tx 1\kern -\hspaceamount 
                                     \vulgarfraction 
\dohighlow ...\scratchdimen \hbox {\dodohighlow #5
                                                  }}\ht \scratchbox \struthe...

\vulgarfraction ...\hspaceamount \vulgarfraction }
                                                  \symbol [\vulgarfraction ]...

\tabulatecontent ...method 1\vulgarfraction {1}{2}
                                                   \NC \NR \NC 2 \NC \charde...

\fulltabulatecontent ...ble }\fi \tabulatecontent 
                                                  \ifx \tabulatetailcontent ...

\processtabulate ...oksa \cr \fulltabulatecontent 
                                                  \crcr }}\ifnum \nofautotab...
l.43 \stoptabulate

?

[...]

> so, it's kind of configurable

It looks good, although I can't imagine (personally) why option 2 would
ever be used. It has the bad points of both 0 and 3 at the same time. ;)

Something you may want to do with your testing is run through the whole
range of fractions: 1/3 1/4 3/4 1/8 5/8 7/8

Those, out of the whole set of halves, thirds, quarters and eighths seem
to be the ones that react most oddly to the kerning and typesetting
technique.

        Daniel

-- 
Men love to wonder, and that is the seed of our science.
        -- Ralph Waldo Emerson, _Society and Solitude_


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-04-17  2:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-11  7:48 "nicefrac" LaTeX package equivalent? Daniel Pittman
2002-04-14 20:47 ` Hans Hagen
2002-04-15  9:02   ` Patrick Gundlach
2002-04-16 12:10     ` Hans Hagen
2002-04-17  2:59       ` Daniel Pittman
2002-04-15 14:22   ` Daniel Pittman
2002-04-15 16:38   ` James H. Cloos Jr.

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).