3

I'm trying to develop a command to typeset slanted fractions. I know about nicefrac and xfrac packages, have tried both, and disliked both. At the moment, in text mode I use \nicefrac with a bit of raising and lowering, because my aim is to get the numerator with the top line aligned with the top of the slash, and the denominator with the baseline aligned with the bottom of the slash. I've come up with this:

\documentclass[a4paper]{report}
\usepackage{amsmath,amsfonts,amssymb}
\newcommand{\Z}{\mathbb{Z}}
\usepackage{xparse}
\global\newcount\qwerty
\newcommand{\e}[1][2]{\ifnum#1>0
    \qwerty=0
    \loop\!\advance\qwerty by 1\ifnum\qwerty<#1\repeat
\else
    \qwerty=0
    \loop\,\advance\qwerty by 1\ifnum\qwerty<-#1\repeat
\fi}
\NewDocumentCommand{\xof}{mmO{7.8}O{-9.3}O{1}O{1}}
{\raisebox{#3pt}{$#1\e[#5]$}\bigg/\raisebox{#4pt}{$\e[#6]#2$}}
\usepackage{graphicx}
\newcommand{\scb}{\scalebox}
\usepackage{xfrac,nicefrac}

\begin{document}
\[\xof{\Z}{n\Z}\]
\[\xof{A}{I}[7.8][-9.3][1][2]\]
\[\xof{\scb{0.7}[0.7]{\(\xof{A}{I}\)\hspace{1pt}}}{\scb{0.7}[0.7]{\hspace{0.5pt}\(\xof{J}{I}\)}}[10][-7.5]\cong\xof{A}{\hspace{-1.2pt}J}.\]
\end{document}

enter image description here

All of that looks fine to my eyes. Parameters 1 and 2 are numerator and denominator, parameters 3 and 4 are the raising amount for the numerator and the lowering amount for the denominator respectively, both in pt, and the other two are numbers which get turned into as many \!s (i.e. 2->!!) for kerning between the numerator, the denominator and the slash. The point is having to manually regulate those parameters every time is rather annoying. So is there a way to get the alignment as described at the top done automatically?

PS I know you will tell me I shouldn't have a string of \!s. I've already been told so about one of \,s. It's just that sometimes it's handy to have discrete spacing. In any case I think I will abandon this in favor of parameters to pass to \hspace.

Update: I didn't know about the \thinskip, but I will certainly redefine the command adding its use, because it joins a continuous range of spaces and my eye's accustomedness to quantities of \!. As for the other comments, the point in this is not to have fractions, but rather quotients sets, which I regard as something rather different and write in a completely different way. As such, my aim is definitely not to save vertical space. That might be useful for inline fractions, but for that I have a totally different command which sort of adjusts \nicefrac. Well, here it is:

\newcommand{\of}[2]{\nicefrac{^{#1}}{_{#2}}}
\newcommand{\mf}[2]{^{#1}\scb{0.5}[1]{/}_{#2}}

either of these, though \of is decidedly nicer and of more common usage for me. So \xof is displayed formula only. No need to save space there. I agree that thus zoomed they don't look that nice, but that is probably because \bigg is too tall. On the other hand, \Big seemed too short to me when I tried it. Maybe I can try combining \left/ and \right. with something in the middle, \vphantom maybe. That's to be investigated. I HAVE tried \nicefrac and xfrac's \sfrac, and both looked bad to me. So don't tell me I «don't know about xfrac» when I have stated, and restate, I have tried it. Using fractions for quotient sets looks bad to me, otherwise I wouldn't be here. As for the supposedly related answers, this looks like a way to do what I'm doing here in text mode, and these commands I'm studying are for math mode, and this has one answer which aligns only the numerator and one which aligns neither so definitely not what I'm looking for.

7
  • 4
    Are you really sure they look fine? I'm not. The first is terrible, the others are worse. I guess you don't know about xfrac; I don't advocate “slanted fractions”, anyway. Those are simple fractions and should be treated as such: $\frac{A/I}{J/I}\cong A/J$ is as clear and typographically sound.
    – egreg
    Jul 25, 2014 at 21:37
  • 4
    The spacing here is really strange with far too much vertical separation for a slanted fraction, it's had to recognise them as fractions at all. The point of the slanted style is to take up less vertical space than a standard fraction Jul 25, 2014 at 22:22
  • 4
    There is no need to loop to make multiple \! that's just slow and inefficient. \! is \mskip-\thinmuskip so if you want 3 times that do \mskip-3\thinmuskip no need to do \!\!\! Jul 25, 2014 at 22:25
  • I hope the Update: addresses all your comments.
    – MickG
    Jul 26, 2014 at 9:05

1 Answer 1

2

Here I define \xof[]{}{} using a \stackinset. There is a single optional argument (defaults to 1ex) that defines the distance the numerator/denominator are horizontally pushed in from the outer edge of the \bigg/. It is to be used when the numerator/denominator are taller than \baselineskip.

The first 2 boxed examples in the MWE are to confirm that I have properly accounted for the widths of my laps. The next 3 examples are from the OP.

\documentclass{article}
\usepackage{mathtools,amssymb,stackengine}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\scb}{\scalebox}
\newcommand\xof[3][1ex]{\ensurestackMath{%
  \setbox0=\hbox{$#2$}%
  \setbox2=\hbox{$#3$}%
  \kern\wd0\kern-\dimexpr#1\relax%
  \stackinset{r}{#1}{b}{0pt}{\mathrlap{#3}}{%
    \stackinset{l}{#1}{t}{0pt}{\mathllap{#2}}{\bigg/}%
  }%
  \kern-\dimexpr#1\relax\kern\wd2%
}}
\fboxsep=.1pt
\begin{document}
\[
\fbox{$\xof{\Z}{n\Z}$}
\]
\[
\fbox{$\xof{xxxxxx\Z}{yyy\Z}$}
\]
\[\xof{\Z}{n\Z}\]
\[\xof{A}{I}\]
\[\xof[0.2ex]{\scb{0.7}{\(\xof{A}{I}\)\hspace{1pt}}}{\scb{0.7}{\hspace{0.5pt}\(\xof{J}{I}\)}}\cong\xof{A}{J}.\]
\end{document}

enter image description here

Here is an alternate version, in which the numerator and denominator are pushed up and down, respectively, if argument #1 is invoked, and in proportion to the value of #1.

\documentclass{article}
\usepackage{mathtools,amssymb,stackengine}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\scb}{\scalebox}
\newcommand\xof[3][1ex]{\ensurestackMath{%
  \setbox0=\hbox{$#2$}%
  \setbox2=\hbox{$#3$}%
  \kern\wd0\kern-\dimexpr#1\relax%
  \stackinset{r}{#1}{b}{\dimexpr#1-1ex}{\mathrlap{#3}}{%
    \stackinset{l}{#1}{t}{\dimexpr#1-1ex}{\mathllap{#2}}{\bigg/}%
  }%
  \kern-\dimexpr#1\relax\kern\wd2%
}}
\fboxsep=.1pt
\begin{document}
\[\xof{\Z}{n\Z}\]
\[\xof{A}{I}\]
\[\xof[0.2ex]{\scb{0.7}{\(\xof{A}{I}\)\hspace{1pt}}}{\scb{0.7}{\hspace{0.5pt}\(\xof{J}{I}\)}}\cong\xof{A}{J}.\]
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .