Format as a fraction without interpreting it as a mathematical fraction?

There’s a way (Superscript[]) I can format as a superscript without Mathematica interpreting it as a power. I’d like to do the same thing with fractions: Format as a fraction without Mathematica interpreting it as a mathematical fraction. Overscript[] comes close, but it doesn’t draw the line.

You can define your own formatting like so:

ClearAll[pseudofraction]
Format[pseudofraction[x_, y_]] := FractionBox[x, y] // DisplayForm

or

Format[pseudofraction[x_, y_]] := FractionBox[x, y, Beveled -> True] // DisplayForm

when you want it beveled. Then

total = pseudofraction[3, 4] + 4

will be displayed as:

It looks like a fraction but it is internally not stored as a fraction:

FullForm[total]

gives:

Plus[4, pseudofraction[3, 4]]

Note that when you copy-paste it from a notebook, then it will be interpreted as a fraction, as that is the default meaning of a ‘fraction box’.

Thanks so much. I was saving boxes as a last resort, because the Mathematica docs gave me the impression boxes are difficult, but your demonstration shows they’re straightforward, not difficult.

How did you know Beveled is an option for FractionBox? It’s not documented under FractionBox.

Options[FractionBox]

gives:

{AllowScriptLevelChange -> True, BaseStyle -> {}, Beveled -> False, 
 DefaultBaseStyle -> {}, DenominatorAlignment -> Center, 
 FractionLine -> Automatic, MultilineFunction -> Automatic, 
 NumeratorAlignment -> Center, Overhang -> 0.25}

Note that all of them might not be implemented yet…

Thanks again.

In hindsight, you could also do it like this:

ClearAll[pseudofraction]
Format[pseudofraction[x_, y_, opts___]] := FractionBox[x, y, opts] // DisplayForm
pseudofraction[2, 3] + 4 + pseudofraction[2, 3, Beveled -> True]