Thanks for coming to InDesignSecrets.com, the world's #1 resource for all things InDesign!

Formatting Fractions

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 David Blatner’s article, 10 Things to Know About GREP. At the end of the post you can watch his lynda.com video demonstrating some of the same ideas for formatting fractions that are mentioned in this article.

***

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.

Tags
Related Articles
Comments

4 Comments on “Formatting Fractions

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

  2. I use Dan Rodney’s Proper Fraction script (http://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!

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>