home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / text / tex / 9363 < prev    next >
Encoding:
Internet Message Format  |  1992-07-21  |  15.9 KB

  1. Path: sparky!uunet!darwin.sura.net!mips!pacbell.com!network.ucsd.edu!mvb.saic.com!info-tex
  2. From: herschor@math.mcgill.ca (Michael Herschorn)
  3. Newsgroups: comp.text.tex
  4. Subject: CRAMPED STYLES & solution to:fraction spacing default_rule_thickness.
  5. Message-ID: <9207211625.AA07444@Math.McGill.CA>
  6. Date: Tue, 21 Jul 92 12:25:00 EDT
  7. Organization: Info-Tex<==>Comp.Text.Tex Gateway
  8. X-Gateway-Source-Info: Mailing List
  9. Lines: 374
  10.  
  11.  
  12.  At the end of this submission you will find a solution to the
  13.  problem relating to the minimum separation between the numerator or
  14.  denominator of a fraction and the fraction bar, a question raised and
  15.  discussed in several postings last month. I would like
  16.  to begin with a more general problem which provides the tool
  17.  used for that solution.
  18.  
  19.  PART ONE:
  20.  
  21.  To measure typeset text from a math list in TeX, the material is
  22.  placed in an \hbox. One must then specify the style of
  23.  the text's "free state" inside the box. The horizontal dimension in
  24.  the free state is affected by "actions at infinity" (glue) and is
  25.  intrinsically uncertain; the height and depth are determined
  26.  "quasi-locally", and are fixed once TeX decides on the current style.
  27.  However, if an item is to be set in a cramped style, absent a TeX
  28.  command \cramp{}, how does one measure its height and depth?
  29.  
  30.  I have also felt a need for \cramp for aesthetic reasons when there
  31.  is a repetition of an expression close by the original in a line of
  32.  text, once in an uncramped style, and once in the corresponding
  33.  cramped style. As well, there is a not insignificant amount of space
  34.  that can be saved in a document with multiple occurrences of, e.g.,
  35.  ${\x}^{{\x}^{{\x}^{\cdot^{\cdot^{\cdot^{\x}}}}}}$, if this could
  36.  be set in a cramped style.
  37.  
  38.  I have most of the standard TeX references, but I haven't come across
  39.  any mention of the possibility of obtaining a cramped style "on
  40.  demand". Thus there may be some general interest in the preliminary
  41.  version of my <cramped.sty> macro, and I append it below.
  42.  
  43.  (I also haven't come across any discussion of a "feature" which turns
  44.  cramping off, viz., prefix the material which TeX would normally
  45.  cramp by an explicit style reminder. Compare, for example,
  46.  $\sqrt{X^2+Y^2}$ with $\sqrt{\textstyle X^2+Y^2}$. However, I doubt
  47.  that this is an intended feature since:
  48.  i) TeX is normally insensitive to redundant style commands, and from
  49.  the user's point of view, this is the way it should be; and,
  50.  ii) cramping will be turned off in midstream by an explicit style
  51.  command (e.g., $\sqrt{X^2+\textstyle Y^2} has X^2 in cramped style
  52.  and Y^2 in uncramped style).
  53.  I am completely out of my depth when it comes to understanding the
  54.  details of The Program, and please, no flames (not even for the
  55.  mixing of metaphors!), but it seems to me that this "feature"
  56.  is a result of the cramped_style calculation in section 702 of The
  57.  Program being ignored while section 703 updates only size-dependent
  58.  quantities.
  59.  Although I reserve my rights to priority for the "finder's fee"
  60.  mentioned in the Preface to The Program, I would like to hear the
  61.  opinions of gurus on the net.)
  62.  
  63. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  64. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  65. % cramped.sty    Preliminary version           July 21,1992
  66. %
  67. % Enables the typesetting of material in the cramped styles
  68. % D', T', S' and SS'.
  69. %
  70. % \cramp{<foo.bar>} will set <foo.bar> in the cramped version C' of
  71. % the current style C.
  72. %
  73. % \Cramp{\...style}{<foo.bar>} (where you specify the current style)
  74. % has been left accessible.
  75. %
  76. %
  77. % Author: Michael Herschorn
  78. %         Departmentof Mathematics and Statistics
  79. %         McGill University
  80. %         805 Sherbrooke Street West               Phone: 514-398-3825
  81. %         Montreal QC  CANADA  H3A 2K6               FAX: 514-398-3899
  82. %         email: herschor@gauss.math.mcgill.ca
  83. %
  84. % Please email me your comments and suggestions as well as informing
  85. % me directly of any bugs you may find.
  86. %
  87. %
  88. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  89. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  90. \catcode`@=11
  91. \def\cramp{\mathpalette\Cramp}%
  92. \def\Cramp#1#2{\setbox0=\hbox{$\m@th#1\cr@mp{#2}$}
  93.      \Ch@p#1 \dimen2=\the\ht0 \advance\dimen2 -\dimen0
  94.      \ht0=\the\dimen2 \box0}
  95. \def\cr@mp{\kern-\the\nulldelimiterspace\radical"380380}%
  96. \def\Ch@p#1{\ifx#1\displaystyle
  97.     \dimen0=\the\fontdimen5\textfont2
  98.     \advance\dimen0 -.75\dimen0
  99.     \advance\dimen0\the\fontdimen8\textfont3
  100.   \else
  101. %%    \ifx#1\textstyle
  102.     \dimen0=\the\fontdimen8\textfont3
  103.     \advance\dimen0 .25\dimen0
  104.  \fi}%%%%%%%%% If you have "variations" in family 3,
  105. %%%%%% comment out the preceding line and "uncomment"
  106. %%%%%% the 7 lines beginning with "%%".
  107. %%  \else
  108. %%    \ifx#1\scriptstyle\dimen0=\the\fontdimen8\scriptfont3
  109. %%    \advance\dimen0 .25\dimen0
  110. %%  \else \dimen0=\the\fontdimen8\scriptscriptfont3
  111. %%    \advance\dimen0 .25\dimen0
  112. %%  \fi\fi\fi}
  113. \catcode`@=12
  114. \endinput
  115. %%
  116. % end of file cramped.sty
  117. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  118. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  119.  
  120.  
  121.  PART TWO:
  122.  
  123.  
  124.  
  125.  Michael Downes <MJD@MATH.AMS.COM> (22 Jun 1992, Info-TeX@shsu.edu)
  126.  wrote:
  127.  
  128. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  129. +Dan Luecking wrote (19 Jun 1992, Info-TeX@shsu.edu):
  130. +
  131. +> Michael Barr posted a query a while back about the separation
  132. +> between the numerator/denominator of a fraction and the fraction bar.
  133. +>
  134. +> I have not seen a response, so having tried to understand the
  135. +> TeXbook on this point and made some headway in doing so I thought
  136. +> I might discuss the problem.
  137. +
  138. +> ... I have run into it several times and would like to know if
  139. +> anyone has defined a fraction making command to deal with it. One
  140. +> way is to insert a 0 width rule extending below the numerator and
  141. +> above the denominator, but I do not see a good to make this
  142. +> automatic. A way I have considered, but rejected, is to increase the
  143. +> relevant parameter, (something like \fontdimen8\textfont3=1pt
  144. +> instead of 0.4pt) and then define all \frac's using \above (in which
  145. +> the thickness of the rule is explicitly given). The problem is that
  146. +> default_rule_thickness is used in several internal calculations
  147. +> including the positioning of sub/superscripts.
  148. +>
  149. +> Does anybody have anything to say about this?
  150. +
  151. +  I have observed the same problem in Amer. Math. Soc. publications,
  152. +  although the examples I've happened to notice involved letters with
  153. +  descenders such as p and q, rather than vertical bars. Your analysis
  154. +  of the problem corresponds closely to what I found in some cursory
  155. +  investigations.
  156. +
  157. +  The problem seems to be slightly worse than you suggest---or maybe you
  158. +  just didn't bother to amplify on results of your experiments: The most
  159. +  significant drawback of the rejected solution of setting \fontdimen 8
  160. +  \textfont 3 to a larger value and using \above instead of \over is
  161. +  not the internal calculations you mention but the fact that the fraction
  162. +  bar thickness and the space around it are always dependent, even in
  163. +  \above, so that if we say $1\above.4pt 2$ the space around the
  164. +  fraction bar is calculated from the .4pt, not from \fontdimen 8 of
  165. +  \textfont 3, and we're back where we started from.
  166. +
  167. +> ... Is it worthwhile suggesting
  168. +> that a major macro package try do something about it? Have any done
  169. +> anything?
  170. +
  171. +  If my understanding of the problem is correct, it's impossible for a
  172. +  macro package to provide any reasonable solution. The only reasonable
  173. +  solution is to change TeX, the program. (And my definition of
  174. +  `reasonable' is pretty extreme when it comes to macro writing; I have
  175. +  done or contemplated doing things at the macro level that any
  176. +  `reasonable' programmer would consider unreasonable.)
  177. +
  178. +> Is there any real problem at higher resolutions (i.e., does
  179. +> everything look OK printed at 1000dpi)?
  180. +
  181. +  In my opinion, there is not enough space around the fraction bar in
  182. +  the problematic combinations (textstyle fractions, vertical bars,
  183. +  letters with descenders), even at high resolution. I'd rather have
  184. +  some control to adjust the space slightly.
  185. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  186.  
  187.  
  188.  The Grand Wizard made his design choices a.e. optimally, and I would
  189.  stick with his implementation of 15d in Appendix G of The  TeXbook.
  190.  Apparent differences between the letter-base levels in the numerators
  191.  and in the denominators of fractions in the same line spoil the
  192.  appearance of the line; shifting the numerator up or the denominator
  193.  down in a fraction with adequate clearance so as to match the letter-
  194.  base levels of another fraction in the line introduces ugly white
  195.  space.  The more I understand the problem, the better I like the GW's
  196.  balancing act.
  197.  
  198.  Nevertheless, as pointed out by Dan Luecking, Berthold K.P. Horn and
  199.  Michael Downes, it would have been nice to have a free parameter to
  200.  adjust in special circumstances. ("Just so you shouldn't need to
  201.  use it", as the Yiddish expression puts it.)
  202.  
  203.  Once we have <cramped.sty>, it becomes a simple hack to solve this
  204.  problem (and other similar ones). I wrote (and attach a copy of)
  205.  <spreadfraction.sty> as an illustration. (The coding is not elegant,
  206.  but it works.) It should be used only when absolutely necessary,
  207.  and even then, it should be used sparingly.
  208.  
  209. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  210. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  211. % spreadfraction.sty        Preliminary version           July 21,1992
  212. %
  213. % If used in a non-cramped context, \xfrac{#1}{#2}{#3} produces
  214. % {#1\over #2} exactly as TeX would, except that the minimum clearance
  215. % that will be tolerated between the numerator or denominator of this
  216. % fraction and the bar line is #3 times the default rule thickness.
  217. % (See Rule 15d in Appendix G of The TeXbook. TeX hardwires in
  218. % #3=3 in \displaystyle and #3=1 in the other styles; spreadfraction.sty
  219. % allows the use of arbitrary values. In other words, .phi. is replaced
  220. % by #3 times the default rule thickness, everything else is kept
  221. % constant.)
  222. %
  223. % In a cramped context, i.e., if the entire fraction is a Rad atom
  224. % (under a root sign), an Over atom (from \overline), in the denominator
  225. % of another fraction, is a subscript, or is a superscript to an
  226. % entity in cramped style, \xfracc{#1}{#2}{#3} should be used instead
  227. % of \xfrac{#1}{#2}{#3}. (I may automate the selection of \xfracc in a
  228. % future version; since spreadfraction.sty is intended for touch-up use,
  229. % I don't consider automation a priority (and it may be like putting a
  230. % tiara on a baglady!)).
  231. %
  232. % \Xfrac{\...style}{}{}{} (identical to \xfrac{}{}{}, except
  233. % that you specify the style) and \Xfracc{\...style}{}{}{} (DITTO),
  234. % have been left accessible to the user.
  235. %
  236. % To obtain a version of spreadfraction in which the minimum clearances
  237. % are #3 times the hardwired ones, declare \DEKtrue after inputting
  238. % spreadfraction.sty
  239. %
  240. %
  241. % Author: Michael Herschorn
  242. %         Departmentof Mathematics and Statistics
  243. %         McGill University
  244. %         805 Sherbrooke Street West               Phone: 514-398-3825
  245. %         Montreal QC  CANADA  H3A 2K6               FAX: 514-398-3899
  246. %         email: herschor@gauss.math.mcgill.ca
  247. %
  248. % Please email me your comments and suggestions as well as informing
  249. % me directly of any bugs you may find.
  250. %
  251. %
  252. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  253. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  254. \newif\ifDEK
  255. \input cramped.sty
  256. \catcode`@=11
  257. \def\xfrac#1#2#3{\M@thpalette\Xfrac{#1}{#2}{#3}}
  258. \def\M@thpalette#1#2#3#4{%
  259.        \mathchoice{#1\displaystyle{#2}{#3}{#4}}%
  260.         {#1\textstyle{#2}{#3}{#4}}%
  261.         {#1\scriptstyle{#2}{#3}{#4}}%
  262.         {#1\scriptscriptstyle{#2}{#3}{#4}}}
  263. \def\Xfrac#1#2#3#4{\ifx#1\displaystyle
  264.        \def\C@rr@ntF@nt{\textfont}
  265.         \let\@djSt@le=\textstyle
  266.          \L@rgeS@ze#1{#2}{#3}{#4}
  267.           \else
  268.            \ifx#1\textstyle \def\C@rr@ntF@nt{\textfont}
  269.             \let\@djSt@le=\scriptstyle
  270.              \N@rmalS@ze#1{#2}{#3}{#4}
  271.           \else
  272.            \ifx#1\scriptstyle
  273.             \def\C@rr@ntF@nt{\scriptfont}
  274.              \let\@djSt@le=\scriptscriptstyle
  275.               \N@rmalS@ze#1{#2}{#3}{#4}
  276.           \else
  277.             \def\C@rr@ntF@nt{\scriptscriptfont}
  278.              \let\@djSt@le=\scriptscriptstyle
  279.               \N@rmalS@ze#1{#2}{#3}{#4}
  280.            \fi
  281.          \fi
  282.        \fi}
  283. \def\L@rgeS@ze#1#2#3#4{\dimen1=\the\fontdimen8\textfont2
  284.               \dimen2=\the\fontdimen11\textfont2
  285.               \N@mer@tor#1{#2}{#3}{#4}}
  286. \def\N@rmalS@ze#1#2#3#4{%
  287.               \dimen1=\the\fontdimen9\C@rr@ntF@nt2
  288.               \dimen2=\the\fontdimen12\C@rr@ntF@nt2
  289.               \N@mer@tor#1{#2}{#3}{#4}}
  290. \def\N@mer@tor#1#2#3#4{%
  291.               \dimen3=\the\fontdimen22\C@rr@ntF@nt2
  292.               \dimen4=\the\fontdimen8\C@rr@ntF@nt3
  293.               \dimen5=#4\dimen4
  294.        \ifDEK\ifx#1\displaystyle\advance\dimen5 2\dimen5
  295.            \else
  296.          \fi
  297.            \else
  298.           \fi
  299.               \advance\dimen4 -.5\dimen4
  300.               \setbox1=\hbox{$\m@th\@djSt@le{#2}$}
  301.               \dimen0=\dimen1 \advance\dimen0 -\the\dp1
  302.               \advance\dimen0 -\dimen3
  303.               \advance\dimen0 -\dimen4
  304.        \ifdim\dimen5>\dimen0 \advance\dimen1 \dimen5
  305.               \advance\dimen1 -\dimen0
  306.               \D@nomin@tor#1{#3}
  307.            \else
  308.               \D@nomin@tor#1{#3}
  309.         \fi}
  310. \def\D@nomin@tor#1#2{%
  311.               \setbox2=\hbox{$\m@th
  312.               \@djSt@le\Cramp\@djSt@le{#2}$}
  313.               \dimen0=\dimen2 \advance\dimen0 \dimen3
  314.               \advance\dimen0 -\the\ht2
  315.               \advance\dimen0 -\dimen4
  316.         \ifdim\dimen5>\dimen0 \advance\dimen2 \dimen5
  317.               \advance\dimen2 -\dimen0 \Qu@ti@nt#1
  318.             \else
  319.              \Qu@ti@nt#1
  320.        \fi}
  321. \def\Qu@ti@nt#1{%
  322.          \ifdim\wd1<\wd2 \dimen9=\the\wd2
  323.                \setbox3=\hbox to \the\dimen9{%
  324.                $\m@th\hfil\box1\hfil$}
  325.                \setbox1=\box3  \dimen8=\dimen9
  326.          \else \dimen9=\the\wd1
  327.                \setbox3=\hbox to \the\dimen9{%
  328.                $\m@th\hfil\box2\hfil$}
  329.                \setbox2=\box3
  330.          \fi
  331.                \advance\dimen1 -\the\dp1
  332.                \advance\dimen1 -\dimen3
  333.                \advance\dimen1 -\dimen4
  334.                \dimen6=\dimen2 \advance\dimen6 -\the\ht2
  335.                \advance\dimen6 \dimen3
  336.                \advance\dimen6 -\dimen4
  337.                \kern\the\nulldelimiterspace
  338.                \raise-\the\dimen2 \hbox to\the\dimen9{%
  339.                \vbox{\box1\kern\the\dimen1\hrule
  340.                \kern\the\dimen6\box2}}
  341.                \kern\the\nulldelimiterspace}
  342. \def\Xfracc#1#2#3#4{\ifx#1\displaystyle
  343.         \let\@djSt@l@=\textstyle
  344.          \G@toResult{#1}{#2}{#3}{#4}
  345.       \else
  346.         \ifx#1\textstyle \let\@djSt@l@=\scriptstyle
  347.          \G@toResult{#1}{#2}{#3}{#4}
  348.       \else
  349.            \let\@djSt@l@=\scriptscriptstyle
  350.             \G@toResult{#1}{#2}{#3}{#4}
  351.            \fi
  352.         \fi}
  353. \def\G@toResult#1#2#3#4{%
  354.            \Xfrac#1{\Cramp\@djSt@l@{#2}}{#3}{#4}}
  355. \def\xfracc#1#2#3{\mathchoice
  356.       {\Xfrac\displaystyle{\Cramp\textstyle{#1}}{#2}{#3}}%
  357.       {\Xfrac\textstyle{\Cramp\scriptstyle{#1}}{#2}{#3}}%
  358.       {\Xfrac\scriptstyle{\Cramp%
  359.        \scriptscriptstyle{#1}}{#2}{#3}}%
  360.       {\Xfrac\scriptscriptstyle{\Cramp%
  361.           \scriptscriptstyle{#1}}{#2}{#3}}}
  362. \catcode`@=12
  363. \endinput
  364. %%
  365. %% end spreadfraction.sty
  366. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  367. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  368.  
  369.  I would appreciate comments and feedback by email and shall
  370.  summarize and post.
  371.  
  372.  
  373.  Michael Herschorn
  374.  
  375. ***********************************************************************
  376.  
  377.  Michael Herschorn                  email:herschor@gauss.math.mcgill.ca
  378.  Department of Mathematics and Statistics             fax: 514-398-3899
  379.  McGill University                                  phone: 514-398-3825
  380.  805 Sherbrooke Street West
  381.  Montreal QC CANADA  H3A 2K6
  382.  
  383. ***********************************************************************
  384.  
  385.