Message Boards Message Boards

0
|
4559 Views
|
5 Replies
|
7 Total Likes
View groups...
Share
Share this post:

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

Anonymous User
Anonymous User
Posted 7 years ago

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.

POSTED BY: Anonymous User
5 Replies

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:

enter image description here

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'.

POSTED BY: Sander Huisman
Anonymous User
Anonymous User
Posted 7 years ago

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.

POSTED BY: Anonymous User
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...

POSTED BY: Sander Huisman
Anonymous User
Anonymous User
Posted 7 years ago

Thanks again.

POSTED BY: Anonymous User

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]

enter image description here

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract