is now part of CreativePro.com!

Formatting Fractions

17

by Ben Richardson

Formatting fractions can be quite easy when you’re using high-quality OpenType fonts. Just select the fraction text and choose Open Type > Fractions from the Character panel menu.

20140731-fraction4

20140731-fraction5

But when you are working on something like textbook or a cookbook, you can easily have dozens (or hundreds) of fractions to set. And then it can be far too time-consuming and tedious to do the job manually. Unfortunately, you can’t just select all the text and switch on the Fractions option because whole numbers, slashes, periods, and commas might be treated as parts of fractions. Luckily, there is a way to automate the job to finish it in a matter of minutes, no matter how long your document/book might be. And that is to use GREP styles.

Using GREP Styles for Fraction Formatting

You can apply the OpenType fractions option to your whole document at once using GREP Styles, which basically work like the Find/Change feature, but within a style. To do this, start by opening the Paragraph Styles panel (Type > Paragraph Styles), then right-click the appropriate style and choose Edit.

Fractions tutorial_Page_2_Image_0001

Select GREP Style in the left-hand menu, and click on New GREP Style.

Fractions tutorial_Page_2_Image_0002

Where it says Apply Style, click on [None] twice then choose New Character Style from the menu.

Fractions tutorial_Page_3_Image_0001

Select OpenType Features in the left-hand menu.

Fractions tutorial_Page_3_Image_0002

Name your new Character Style, enable the Fractions option, and click OK to go back to the Paragraph Style window.

Fractions tutorial_Page_4_Image_0001

To create a GREP style to find fractions, you need to set the To Text field appropriately. Since \d stands for any digit, \d/\d will make it search for digit/digit. That means this will work for 1/2 but not 12/9, for example. In order to turn 12/9 into a fraction, you’ll need \d+/\d+, as the plus sign stands for “one or more” digits. However, \d+/\d+ will format whole numbers too, resulting in mixed numbers like 1½ being turned into 11/2. Enter either \d/\d or \d+/\d+, depending on what type of fractions you’re working with.

Fractions tutorial_Page_4_Image_0002

By clicking OK and closing the Paragraph Style window, all the fractions within that style will be formatted automatically.

Fractions tutorial_Page_5_Image_0001

One thing to keep an eye on are dates written in numerical form, such as 12/12/2014, as they might be considered fractions. If this happens, you can create another GREP style to search for them and apply a separate character style to remove fraction formatting. Have your Date GREP style search for \d+/\d+/\d+ and have it remove OpenType fractions (deselect the Fractions checkbox). Also, make sure that the Date GREP style appears below the Fraction GREP style in the panel, since InDesign applies GREP styles in the order in which they are listed.

date and fraction grep styles

Using Fonts Without OpenType Fraction Support

Now that you’ve saved some time by automating this formatting process, you might wonder what to do with fonts that don’t support fractions. If there’s a whole document you need to set up in this font, you might want to consider downloading an InDesign script or plug-in that will take care of this for you. There are several available online that are free, and some Pro versions even recognize dates and leave them alone. Blatner Tools has some powerful features for handling fractions. And if you face this issue very often, it might be a good idea to invest in a full-featured OpenType font that includes fractions, as it will save you a lot of time.

If you just need one or two fractions in a display font, you can use this simple trick.

Select the first number and click on the superscript button in the character menu.

Fractions tutorial_Page_5_Image_0002

Then select the second number and click on the subscript button in the same menu.

Fractions tutorial_Page_6_Image_0001

The subscript option will probably put the number too low, so shift the baseline in the character menu.

Fractions tutorial_Page_6_Image_0002

You might want to also play with kerning and replace the standard slash character with a true fraction bar (Shift+Option+1 on Mac; Shift+Alt+1 on Windows) to make a good-looking fraction. It depends on the font you’re using.

Fractions tutorial_Page_7_Image_0001

As you can see, both GREP styles and the baseline shift tricks are easily applicable and not very complex. Fractions can make your job a bit hard sometimes, but hopefully this tutorial will help with that.

Editor’s Note: Also check out our resource page on GREP here.

***

Ben Richardson is director of Acuity Training an IT training business based in Guildford, UK and is sharing some of the tips that delegates have found more useful from their InDesign classes.

  • Dwayne says:

    What’s your next step to delete the space between the whole number and the fraction itself? The space should not be there, as the fraction should be closed up to the whole number.

    That’s why I normally search and replace in word for the fractions and put french quotes around them. Then when I import into InDesign, I search for the fractions within french quotes and replace with the my fraction character style. And then delete the french quotes. That’s so that space is not there.

    • I would do three things in addition to the above GREPs to solve the space between the whole number and the fraction:

      1) In the style called “Date”, edit the character style and under Advanced Character Formats, set the Horizontal Width to 100%; and then

      2) Make an additional style (e.g. close gaps) and the ONLY thing to make in this Character style is again under Advanced Character Formats, set the Horizontal Width to 1%.

      3) Edit the paragraph style to include a new GREP style that applies the “close gaps” style to the following: (?<=\d)\s(?=\d+/\d+)

      Make sure that this particular GREP style is the bottom-most one (i.e. the Date one should be above it).

      I'm a big believer in not post-processing artwork if I can avoid it, considering that much of my work uses Data Merge straight to PDF rather than to another InDesign file, so if it will be processed correctly the first time, this will mean no double-handling of the artwork.

  • Aaron Gray says:

    I use Dan Rodney’s Proper Fraction script (https://www.danrodney.com/scripts/properfraction.html), since I have fonts that I work with that are not Open Type, and I even have a keyboard shortcut saved for it since I use it so much.
    To locate each fraction that I need to run the script on, I use a saved Find/Change GREP query: (?<=\d )(?<!\d)(?<!/)\d+/(?!11)(?!0)(?!9)\d{1,3}(?!/)(?!\d)
    This finds only fractions that come after a number and a space, because my company's style is to keep standalone fractions at full size. So, it would find the "1/2" in "1 1/2".
    Then, after I've converted them all, I use another saved Find/Change GREP query to remove all the spaces between the number and the fraction: (?<=\d) (?=(?<!\d)(?<!\x{2044})\d+\x{2044}(?!11)(?!0)(?!9)\d{1,3}(?!\x{2044})(?!\d))
    Can't remember how I came up with these saved searches, but I'm sure it was probably from something on InDesignSecrets.com!

  • Dwayne says:

    Thanks, Colin.

    @Aaron: I use the proper fraction script as well. Though many of the book designers and publishers are using more and more open type fonts, they still use postscript some fonts, and all the fractions are not available. The proper fraction script is a lifesaver.

  • But Aaron, your GREP doesn’t find fractions that don’t have a leading whole number. Like, it won’t find “15/16”. Your pubs only have fractions that follow a whole number?

  • Anne says:

    I cannot seem to find any help in formatting fractions in the proper (standard?) way. As a math teacher the accepted style would be to place the numerator ABOVE the denominator and not on the same line only separated by a slash. Having the numbers in the correct place is essential for properly arranging equations… is this possible? Is there an easy way to do this?

    • Daniel says:

      Hey Anne.

      I have exactly the same question. I’m wondering if you’ve found a solution? The fractions with the forward slash are really not acceptable as fractions, especially for primary school kids. Thanks.

  • Scott McGill says:

    Or you could just copy and paste from Word into Indesign, and it works with any font. Simples.

  • Oleh Melnyk says:

    here is my modification [code](?&lt;!/|\S)\d+/\d+(?!/)(?=\s|[[:punct:]])[/code] – will not screw up dates like (10/12/2015) or web url (like site.com/11/12); will work for fractions separated with spaces on both sides, or if paragraph starts with the fraction, or if punctuation mark right after the fraction

  • Gary says:

    Another save! Your website helped me big-time today with 3 great tips for automating numbering and fractions on a big cookbook. Thanks!

  • Marsh says:

    I’m making a recipe book in indesign and really stuck on the fractions- When doing GREP to fractions all numbers are becoming small, for example if its “11/2 cups flour” the 1 before the half is becoming small too. Any solutions?

  • Civi B says:

    Hi Marsh.
    I’m working on a recipe book too. The font I use doesn’t support open type, and anyway, I find it unacceptable to be limited to 1/4, 1/2 and 3/4. So I created character styles for the top number, slash and bottom number. The following greps also ensure that just one number gets superscripted so I don’t get 11/2.
    superscript \d(?=/\d)
    slash (?<=\d)⁄(?=\d)
    subscript (?<=\d/)\d
    I make sure to type the correct slash (shift-option 1) and it needs a style sheet because I give it negative tracking.

    Since I find the whole number before the fraction comes a bit close, and I certainly don't want to type a space,
    I have a fourth style sheet for the number before the fraction, with positive tracking. But I need to assign that style sheet manually.
    Does anyone know how to write a grep command for the number before a fraction? I'd really appreciate it!

  • >