www.flickr.com

Friday, October 13, 2006

LaTeX Tip: Typesetting Nice Fractions or How to Make xfrac Work

One reason that we all love LaTeX is that it does a beautiful job of typesetting mathematics, provided that you're in an equation environment. Unfortunately, the typesetting of mathematics in inline text does not always work well.

One major problem that can occur is that fractions set inline in text either forces some extra space above and below the line of text or fails to nicely follow the text's current formatting.

The solution is to use the xfrac package, a package that solves all the nasty typesetting issues for fractions. Unfortunately, xfrac doesn't work if it is installed in the default way. A little LaTeX expertise is needed to coerce it into working. The instructions to do so with a MikTeX installation follow (the instructions for other LaTeX installations should be very similar).
  1. Do a full update of using the MikTeX Update Wizard
  2. Install the xfrac package, either automatically by including it in a document or using the MikTeX Package Manager
  3. Get the LaTeX project repository download xbase.tgz, the base package for the experimental features (direct link to the file)
  4. From xbase.tgz, extract the file xbase.ins
  5. Run latex on xbase.ins (the exact command is latex xbase.ins)
  6. Copy the generated style files (template.sty, ldcsetup.sty, xparse.sty, and xparse.sty) to the appropriate places, such that we get:
    • C:\texmf\tex\latex3\template\template.sty
    • C:\texmf\tex\latex3\xparse\ldcsetup.sty
    • C:\texmf\tex\latex3\xparse\xparse.sty
    • C:\texmf\tex\latex3\xtools\xtools.sty
  7. Update the package index (the exact command is texhash)
Now, it is possible to set fractions nicely anywhere in a document with the command \sfrac{numerator}{denominator}. All the details of this command can be found in the xfrac documentation (PDF).

3 comments:

  1. Thank you! The issue was driving me nuts but your solution worked perfectly.

    ReplyDelete
  2. Somehow I managed to break my installation of latex trying to do this! Must have gone wrong somewhere!

    ReplyDelete
  3. Fixed MikTex and it all works great now!

    ReplyDelete