Book Image

LaTeX Cookbook

By : Stefan Kottwitz
Book Image

LaTeX Cookbook

By: Stefan Kottwitz

Overview of this book

LaTeX is a high-quality typesetting software and is very popular, especially among scientists. Its programming language gives you full control over every aspect of your documents, no matter how complex they are. LaTeX's huge amount of customizable templates and supporting packages cover most aspects of writing with embedded typographic expertise. With this book you will learn to leverage the capabilities of the latest document classes and explore the functionalities of the newest packages. The book starts with examples of common document types. It provides you with samples for tuning text design, using fonts, embedding images, and creating legible tables. Common document parts such as the bibliography, glossary, and index are covered, with LaTeX's modern approach.You will learn how to create excellent graphics directly within LaTeX, including diagrams and plots quickly and easily. Finally, you will discover how to use the new engines XeTeX and LuaTeX for advanced programming and calculating with LaTeX. The example-driven approach of this book is sure to increase your productivity.
Table of Contents (19 chapters)
LaTeX Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Importing data from files


It can be very handy to get the data for the row entries from an external file. Actually, this can be done in a few lines.

How to do it...

We will load the datatool package, let it import data from a comma separated data file, sort it, and print it:

  1. Store your data in the same folder as your main tex document. Here, we will use the data from the last recipes, unsorted within a text file:

    Distribution,Hits
    Zorin,85
    Debian,1582
    CentOS,1171
    elementary,899
    Arch,1040
    Mint,2364
    openSUSE,1334
    Ubuntu,1838
    Mageia,1219
    Fedora,1262
  2. Start with a document class, such as article, and load the booktabs package for improved tabular layout, and the datatool package for data handling:

    \documentclass{article}
    \usepackage{booktabs}
    \usepackage{datatool}
  3. With these datatool commands, load the data from the file and sort it:

    \DTLloaddb{Linux}{linux.csv}
    \DTLsort{Hits=descending}{Linux}
  4. Start the document and set up a tabular environment:

    \begin{document}
    \begin{tabular}{rlr}
      & Distribution...