Code Examples

Here, you can find all code examples from the second edition of the LaTeX Cookbook. The code for the second edition is at

Click a chapter title to open the page with all chapter examples. Some examples have their own page for the gallery and are also clickable.

1. Exploring Various Document Classes

  1. Writing a short text
  2. Developing a thesis
  3. Designing a book
  4. Creating a presentation
  5. Designing a curriculum vitae
  6. Writing a letter
  7. Producing a leaflet
  8. Building a large poster

2. Tuning the Text

  1. Improving justification and hyphenation
  2. Adding margin notes
  3. Putting text into a colorful box
  4. Converting numbers to words
  5. Visualizing the layout
  6. Visualizing boxes of letters and symbols
  7. Typesetting in a grid
  8. Absolute positioning of text
  9. Adding drop caps
  10. Fitting text to a shape
  11. Creating a pull quote

3. Adjusting Fonts

  1. Using standard font commands
  2. Choosing a document font
  3. Locally switching to a different font
  4. Printing font tables
  5. Importing just a single symbol of a font
  6. Writing bold mathematical symbols
  7. Getting sans-serif mathematics
  8. Writing double-stroke letters like on a blackboard
  9. Enabling the searching and copying of ligatures
  10. Suppressing ligatures
  11. Adding a contour

4. Creating Tables

  1. Designing a legible table
  2. Positioning tables
  3. Merging cells
  4. Splitting a cell diagonally
  5. Adding footnotes to a table
  6. Aligning numeric data
  7. Coloring a table
  8. Importing data from an external file

5. Working With Images

  1. Including images with optimal quality
  2. Customizing images
  3. Adding a frame to an image
  4. Cutting an image to get rounded corners
  5. Shaping an image like a circle
  6. Drawing over an image
  7. Aligning images
  8. Arranging images in a grid
  9. Stacking images

6. Creating Graphics

(click for full sample chapter)

  1. Building smart diagrams
  2. Constructing a flowchart
  3. Growing a tree
  4. Building a bar chart
  5. Drawing a pie chart
  6. Drawing a Venn diagram
  7. Putting thoughts into a mind map
  8. Generating a timeline

7. Creating Beautiful Designs

  1. Adding a background image
  2. Creating beautiful ornaments
  3. Preparing pretty headings
  4. Printing a calendar
  5. Mimicking keys and menu items
  6. Arranging topics like a puzzle
  7. Building a word cloud

8. Contents, Lists and Bibliographies

  1. Tuning table of contents, lists of figures and tables
  2. Creating a bibliography
  3. Adding a glossary
  4. Creating a list of acronyms
  5. Producing an index

9. Optimizing PDF Files

  1. Using hyperlinks
  2. Adding metadata
  3. Including copyright information
  4. Inserting comments
  5. Producing fillable forms
  6. Optimizing the output for ebook readers
  7. Removing white margins
  8. Combining PDF files
  9. Creating an animation

10. Advanced Mathematics

  1. Quick-start for beginners
  2. Fine-tuning a formula
  3. Automatic line-breaking in equations
  4. Highlighting in a formula
  5. Writing theorems and definitions
  6. Drawing a commutative diagram
  7. Plotting functions in two dimensions
  8. Plotting in three dimensions
  9. Drawing geometry pictures
  10. Doing calculations

11. Science and Technology

  1. Typesetting an algorithm
  2. Printing a code listing
  3. Programming with Lua
  4. Creating graphs
  5. Writing quantities with units
  6. Drawing Feynman diagrams
  7. Writing chemical formulas
  8. Drawing molecules
  9. Representing atoms
  10. Drawing molecular orbital diagrams and atomic orbitals
  11. Printing a customized periodic table of elements
  12. Constructing electrical circuits

12. Getting Support on the Internet

  1. Exploring available LaTeX resourceson the web
  2. Utilizing web forums effectively
  3. Crafting high-quality questions
  4. Creating minimal working examples

13. Using Artificial Intelligence with LaTeX

  1. Getting started with ChatGPT
  2. Getting answers to LaTeX questions
  3. Improving your content
  4. Generating code