How to dynamically modify the Table of Contents?

The Table of Contents (TOC) in your ebook or publication can be modified at runtime thanks to HEScript.

This topic explains you how you can show and hide TOC items at runtime. For instance, you want to display some TOC items only if the publication works in Registered mode.

Associating HEScript functions to TOC items

In the TOC editor, you have a property named “Visibility HEScript Function“:


This property can point to a Boolean HEScript function that defines whether the TOC entry is visible or not.

The syntax should be: [scriptname].[booleanfunctionname]

When the publication loads the TOC, if a TOC item is associated to a Boolean function, the latter is executed. If its result is True, the TOC item is displayed; otherwise, if the result is False, the TOC item is hidden.

To refresh the TOC, you can use the RefreshTOC HEScript built-in macro.


This sample hides TOC items if the publication works in Trial mode, and shows them if it is in Registered mode.

1) Go to the Script Manager, edit the “UserMain” script and copy/paste the following code:

function HideItIfTrial: Boolean;
// Returns False to hide the TOC item if HEPubRegistered is set to 1 (Registered) 
Result := GetGlobalVar("HEPubRegistered", "0") = "1"; 

2) Close the script editor, go to the Table of Contents page and choose the TOC item you want:

Toc hide it

Enter the reference to the script function: UserMain.HideItIfTrial or select it with the “…” button. Press Enter to save changes.

3) Make sure you have enabled the option to make a Trial publication and compile it.

Introduction to Scripting

Table of Contents

Using the Script Manager

Script Function Reference

Copyright G.D.G. Software 2019. All rights reserved