15

I would like to have a \frac or mathpartir-style inference rule with a dotted rather than solid line, so that I can put fractions into inference rules without overloading horizontal bar.

The following example shows three possible steps towards this (ordered by increasing closeness to solution):

  1. genfrac, which allows me to customise the thickness of the line but not the stroke
  2. dotuline from the dashundergaps package, which allows dotted lines, but doesn't support proper fractional formatting
  3. custom inferrule using \mprset of mathpartir package, which claims to support dotted lines, but doesn't seem to space the dots properly.

Here are my attempts; I tried two different ways of customising inferrule.

\documentclass{article}

\usepackage{amsmath}
\usepackage{dashundergaps}

\begin{document}
\[\genfrac{}{}{1pt}{0}{a}{c+d}\]
\[{\dotuline{a}\atop c+d}\]
\[\mprset{fraction={\cdot\cdots\cdot}}\inferrule{a}{c+d}\]
\[\mprset{fraction={\cdot\hdotdot\cdot}}\inferrule{a}{C+D^{\beta}}\]
\end{document}

There is some discussion here but the proposed solution is to use dashundergaps. Since the width and vertical positioning of the dotted line are incorrect when compared with the behaviour of \frac, this cannot really be considered a solution.

Using mathpartir and customising inferrule seems like the simplest direction to explore, but the results are somewhat unpredictable. The first attempt above doesn't space out the dots properly; the second does, but changes the vertical placement of the line (so that the superscripted 'beta' character now intersects with the bar).

This may also be relevant.

3
  • Why reinvent the wheel?
    – user10274
    Commented Aug 19, 2013 at 11:06
  • @MarcvanDongen Good idea. I hadn't thought of trying to customise mathpar itself - generalised the question accordingly. However, although the mathpartir does indeed give an example of using mprset to use dotted lines, in practice that doesn't seem to work too well (sometimes the spacing of the dots is out, sometimes the dots seem to vary in size).
    – Roly
    Commented Aug 19, 2013 at 12:41
  • Added another mathpartir example to show my best attempt so far - using \hdotdot as the 'body' of the horizontal bar seems to lead to correct spacing, but now the vertical placement is out.
    – Roly
    Commented Aug 19, 2013 at 13:16

3 Answers 3

14

Here is my attempt, which uses \ooalign and \genfrac in the definition:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand\dotover{\leavevmode\cleaders\hb@xt@ .22em{\hss $\cdot$\hss}\hfill\kern\z@}
\newcommand{\dotfrac}[2]{
\ooalign{$\genfrac{}{}{0pt}{0}{#1}{#2}$\cr\dotover\cr}
}
\makeatother

\begin{document}

\[\varphi=\dfrac{1+\sqrt5}{2}\neq\dotfrac{1+\sqrt5}{2}\]

\end{document}

Result:

enter image description here


Update

Now with \mathchoice for different size!

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\dotfrac}[2]{
\mathchoice
{\ooalign{$\genfrac{}{}{0pt}{0}{#1}{#2}$\cr\leavevmode\cleaders\hb@xt@ .22em{\hss $\displaystyle\cdot$\hss}\hfill\kern\z@\cr}}
{\ooalign{$\genfrac{}{}{0pt}{1}{#1}{#2}$\cr\leavevmode\cleaders\hb@xt@ .22em{\hss $\textstyle\cdot$\hss}\hfill\kern\z@\cr}}
{\ooalign{$\genfrac{}{}{0pt}{2}{#1}{#2}$\cr\leavevmode\cleaders\hb@xt@ .22em{\hss $\scriptstyle\cdot$\hss}\hfill\kern\z@\cr}}
{\ooalign{$\genfrac{}{}{0pt}{3}{#1}{#2}$\cr\leavevmode\cleaders\hb@xt@ .22em{\hss $\scriptscriptstyle\cdot$\hss}\hfill\kern\z@\cr}}
}
\makeatother

\begin{document}
Display: 
\[\varphi=\frac{1+\sqrt5}{2}\neq\dotfrac{1+\sqrt5}{2}\]

Text:
\[\textstyle\varphi=\frac{1+\sqrt5}{2}\neq\dotfrac{1+\sqrt5}{2}\]

Script:
\[_{\varphi=\frac{1+\sqrt5}{2}\neq\dotfrac{1+\sqrt5}{2}}\]

Scriptscript:
\[_{_{\varphi=\frac{1+\sqrt5}{2}\neq\dotfrac{1+\sqrt5}{2}}}\]
\end{document}

Result:

enter image description here

3
  • 1
    Very nice. Why don't add \mathchoice to have all different sizes? Commented Aug 19, 2013 at 15:55
  • Great answer now, but I can't give you more than +1 ;-) Commented Aug 19, 2013 at 16:31
  • Perfect. Really improves the readability of my document, too.
    – Roly
    Commented Aug 19, 2013 at 17:57
9

One can typeset a fraction without bar and superimpose a dashed bar to it:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\dashdfrac}[2]{%
  {\sbox0{$\genfrac{}{}{0pt}{0}{#1}{#2}$}%
   \vphantom{\copy0}%
   \ooalign{%
     \hidewidth
     $\vcenter{\moveright\nulldelimiterspace
       \hbox to\wd0{%
         \xleaders\hbox{\kern.5pt\vrule height 0.4pt width 1.5pt\kern.5pt}\hfill
         \kern-1.5pt
       }%
     }$
     \hidewidth\cr
   \box0\cr}}%
}

\begin{document}
\[
\dashdfrac{a}{c+d}+\dashdfrac{1}{2}
\]
\end{document}

enter image description here

2
  • The first line of \ooalign contains the final height, the last line the final depth. Therefore I would add \phantom{\copy0}\cr as first line to get a correct bounding box for the whole expression. Commented Aug 19, 2013 at 16:21
  • @HeikoOberdiek You're right!
    – egreg
    Commented Aug 19, 2013 at 16:55
3

A First approach could be:

\documentclass{article}

\renewcommand\dotfill{\cleaders\hbox{.}\hfill}
\newlength{\numwidth}
\newlength{\denwidth}
\newlength{\corrwidth}

\newcommand{\dotfrac}[2]{%
\settowidth{\numwidth}{\hbox{$\displaystyle #1$}}
\settowidth{\denwidth}{\hbox{$\displaystyle #2$}}
\setlength{\corrwidth}{%
\ifdim\numwidth>\denwidth
  \numwidth
\else
  \denwidth
\fi
}
\displaystyle #1 \atop{\hbox to \corrwidth{\dotfill\hfil}\atop{\null\atop\displaystyle #2}}
}

\begin{document}
\[
\dotfrac{a}{b+c}
\]
\end{document}

Sample Output

3
  • This looks promising, thanks. Couple of questions: First, is it possible to have the vertical layout match that of dfrac? (There seems to be more vertical spacing, in particular above the line.) Second, when I embed your macro into a larger document, I get ! Undefined control sequence. <argument> \numwidth - any ideas? (I'm afraid I don't understand what your code is actually doing.)
    – Roly
    Commented Aug 19, 2013 at 12:46
  • Nice attempt, but something like \[\dotfrac{a}{b+c}\dfrac{a}{b+c}\] doesn't give the desired result... Commented Aug 19, 2013 at 13:51
  • Nice first attempt. However, you at least need different grouping for the \atops, e.g. {x \atop y}, otherwise subsequent math gets dragged in to part of the construction. Commented Aug 20, 2013 at 8:37

You must log in to answer this question.

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