Make Contents
Introduction | Customizing a Table of Contents |
Creating a Table of Contents | Creating a Table of Contents Programmatically |
Introduction
The Make Contents palette enables you to generate a table of contents for any notebook or group of notebooks.
You can format your table of contents in any of three predefined styles:
- Simple — this style lists all the entries without page numbers or any special formatting. A simple table of contents is like an outline. It is useful for checking that your topics are in the right order before generating a table of contents in one of the other two styles.
- Book — this style resembles a table of contents in a typical book, with each topic and subtopic on a separate line.
- Condensed — this style combines multiple subtopics on the same line to achieve a more compact appearance.
Creating a Table of Contents
To create a table of contents:
1. For a single notebook, open the notebook and make it the currently selected notebook. For multiple notebooks, open the Make Project dialog box and load the project file for your project. (If you have not already created a project file, see "Creating a Project File" to learn how.)
2. Open the Make Project dialog box.
3. Click Paginate to assign page numbers to the source notebook(s). You can skip this step if you have paginated the notebooks previously or are creating a simple table of contents that does not contain any page numbers.
4. Click either Make Simple Contents, Make Book Contents, or Make Condensed Contents, depending on which style of table of contents you want to create.
It may take a few moments for the evaluation to be completed, depending on the size of the source notebook(s). The newly generated table of contents appears on the screen and is saved in the same directory as the source notebook.
Note: The Wolfram System automatically adds cell tags to the source notebook(s) and saves all changes. It is therefore advisable to make a backup copy of your notebook(s) before generating a table of contents.
Customizing a Table of Contents
The buttons at the bottom of the palette let you specify options to customize various features of the table of contents. To set the value of an option, click the button bearing the name of that option. This brings up a dialog box displaying the current value of the option. You can edit the text and click Apply for the changes to take effect. Click OK to close the dialog box.
- Paginate calculates page numbers for the source notebook(s). The page numbers are saved as TaggingRules in the notebook. By default, the first notebook has starting page number 1.
- Clear Cell Tags removes the automatically generated cell tags in the source notebook(s). If you remove the cell tags, the hyperlinks in the table of contents will take you to the start of the notebook instead of to a specific topic.
- SelectedCellStyles lets you specify the cell styles that should be included in the table of contents. The default setting is SelectedCellStyles->{"Title","Section","Subsection","Subsubsection"}.
Creating a Table of Contents Programmatically
The Wolfram System kernel refers to any open notebook via an expression of the form NotebookObject[fe,id], where fe specifies the front end in which the notebook is open and id is a unique serial number for the notebook.
The command Notebooks[] returns a list of notebook objects corresponding to all notebooks currently open in the front end.
This assigns the variable nb to represent the first notebook object in the list.
Alternatively, you can identify a notebook by specifying the name and location of the notebook file. You can use the ToFileName function to construct a string specifying the full pathname of the file.
This loads the AuthorTools package.
This generates a table of contents for the notebook. The table of contents is saved in the same directory as the source notebook.
The second argument of the function specifies the format of the table of contents. You can choose from three different formats: "Simple", "Book", or "BookCondensed". (See the "Introduction" of this tutorial for more information on these formats.)
Note: The MakeContents command inserts cell tags into the source notebook and automatically saves the changes. If you do not want your source notebook modified, you should keep a separate copy as a backup.
If you are going to generate a table of contents in any format other than "Simple", you should first use Paginate. This function calculates the page numbers for the specified notebook and stores them as TaggingRules in the notebook.
The following command generates a table of contents in the "Book" format.
The option SelectedCellStyles determines which cells in the notebook are included in the table of contents. The default setting is SelectedCellStyles->{"Title","Section","Subsection","Subsubsection"}. The following command generates a table of contents in the "Book" format that includes only title, section, and subsection cells.