When compiling for a .mobi file, I want to dynamically create a Table of Contents using my chapter titles and simultaneously use Custom Meta-Data to dynamically insert PNG files as chapter titles for the chapters themselves.
Is this possible?
Thank you for your assistance.
Yes, you should be able to do something like this. You would need to set up a few elements in order to automate it, but once you did you would be able to specify the name of the PNG file right from the Inspector for that chapter.
- First, create a custom meta-data field called “Chapter Image” (or whatever you like, but I will reference it by that name in these notes). Custom meta-data is set up in the Project/Meta-Data Settings… menu command, last tab.
- Next, load up your compile settings with File/Compile…, and click on the Formatting compile option pane.
- Depending on whether you started with a template, or are using a preset like the “E-book” starter, you may already have some chapter formatting set up. I’ll assume the “E-book” starter, and you’re using folders for chapters. So I would click on the “Folder Level 1+” row in the upper half, and see an example of the chapter heading below.
- Click the Section Layout… button, first tab.
- In the Suffix filed, press Return once so you get a paragraph symbol, and then type in: <$img:<$custom:Chapter Image>>. That’s a compound placeholder tag. You can think of it as working inside out. First the compiler will examine the folder’s “Chapter Image” custom meta-data field and print the result. So for example if the first chapter has an image assigned called “stained glass”, the interim result would be: <$img:stained glass>. Then the compiler evaluates that placeholder, and inserts the first image from the Binder it encounters with the name ‘stained glass’. You of course won’t see anything in the preview area when you click Okay, because none of this has happened yet.
- For now, hold down the Option key, and click the Save button, which will replace the Compile button.
Okay that’s all you need to do for set up. To test it, drop a PNG into the binder somewhere, anywhere is fine, remember it’s just the first picture by that name. Click on a the first chapter title item (again, I used a folder in my example), and then open the Inspector and switch to the custom meta-data view (the dogtag icon), and type in the name of the picture in the provided box. Do a quick compile; you should see the picture placed between the chapter title and the beginning of the first scene.
You know, I might have read you incorrectly the first time around. You’re wanting pictures for ToC entries? I don’t think you’ll be able to use Scrivener for that. You could definitely get a list of PNG files in the ToC page by setting up your own, and you can even cross-reference to individual chapter’s custom meta-data (by creating a Scrivener Link on the custom placeholder), but you can’t actually hyperlink the image that resulted from that, and besides I don’t know how widely supported that kind of link is anyway within Mobi. It seems to work better with the Fire, but Paperwhite and older e-Ink models are just going to magnify a picture you tap on.
Hi, Amber - Thank you very much for your time and effort on this. I greatly appreciate your detailed reply.
I’ve been working on this problem for several days. Still don’t have an optimal solution yet.
It seems when I use the Custom Meta-Data fields, then Scrivener will not output a TOC that contains my chapter titles. Still working on it.
Well like I say, the simple production of a graphic file from another document’s meta-data field is possible. In the initial advice that I provided, I was mistaken in thinking you wanted some kind of little special glyph after each chapter, and so in that context the <$custom…> placeholder needn’t have anything special done to it because it is technically located “inside” the Binder item generating that section, and thus pulls that chapter’s image preference.
However the solution is still very similar. The main difference is that since you are referencing data from another file entirely (the ToC override binder file) you need to select the <$custom…> part of the image placeholder tag and use the Edit/Scrivener Link/ sub-menu to link the text of the placeholder tag back to the item that contains the data you are wanting to reference.
I’ve created a simple working demonstration of a ToC with a small graphic after each entry.
The ToC override file is in the lower split, and the upper split has one of the chapter folders selected, demonstrating the reference to the image name in its custom meta-data field.
Thank you very much. The demonstration you created is quite helpful and greatly appreciated.
My intention is to use regular chapter titles, such as “How I Learned to Argentine Tango”, in the custom TOC, and use custom images for the chapter titles in the chapters themselves.
I will examine more closely what you’ve created in the demonstration and review all of your comments, and attempt to identify the specific Compile parameters that will allow me to do what I’m planning (if it’s possible).
Okay, then one thing to take a look at is the fact that a prefix or suffix can completely replace a title. You do not need the “Title” checkbox to be turned on in order for them to work. Thus an image code in the prefix or suffix field, and no “Title” checkbox for that row would just print a picture at the start of the chapter.