tagging images for different compiles?

I have written an eBook that I’m also selling as print on demand. I’m not happy with having to maintain two documents for this in Papers, and am unhappy with a few other things in Papers as well—thus I’m now a Scrivener newbie (and loving it!)

Okay, so here is my issue. My e-version has several color images in it. For the paper version, I’m not including these. The e-version also has 2 color tables. For the print version I am using a black&white version of the table.

I’m wondering if there is a way to get Scrivener to use the color images when exporting to eBook, but ignore them and include the B&W versions for any other export.

From reading some stuff on the forum (and going thoroughly through the tutorial) I can’t find a way to do this. As far as I can tell, the best I can do is create a duplicate text item in my binder—one with images and one without— and just check and uncheck them manually to include or not include in the compile process. Any help is appreciated


You’re on the right track with the duplicate documents, but there’s no need to do it all the including manually, as the Compile dialogue has filter options to automate selection.

First you need to do some setting up.

  1. From the Project menu open Metadata settings.
  2. Click on the labels tab.
  3. Enter a Custom Title - something like Output
  4. Set up three labels - perhaps always, paper, epub, with friendly colours.
  5. Close the Meta-Data settings.
  6. Assign an Output status to each document, either in the inspector or by right clicking on the binder. A document you need for each compile route get always, ones for the paper publication get paper etc.

Once you’ve done that and you want to compile for paper, go to the Contents pane of the Compile dialogue. Below the file list there’s a ‘filter’ box: tick it. Now, set the filter to Exclude documents with Output as epub. That means the compile will Include files with all other Output settings, in this case always and paper. You should see the list of files change as you set the filter.

And when you want an epub, set the Exclude filter to paper.

This set of features came up just earlier today for another problem. I’d consider using Replacements in conjunction with image placeholder tags for this. Granted you don’t get a pretty image in the editor, but a placeholder is plain old text, and that means you can search for bits of it and replace them on the fly based on the preset. For example, a simple naming convention with “-bw”, “-rgb” (and maybe “-cmyk” if you’re doing traditional print) could be appended to the image filenames in the Binder. Then do something like this in the editor:


Finally, set the compiler to look for “%%” and replace it with “-bw” or “-rgb” depending upon the output. Scrivener will do so prior to scanning for graphics and inserting them, thus fetching the appropriate version for the media.

You could even simplify that further with an advanced replacement that uses stored info. Type in:


Search for:


Replace with:


Thanks so much for the replies. Amber, your way is a little more complicated, but if I am understanding it correctly, I would not need to maintain any duplicate Text files the way I would with the other version.

Just one more question— for the print version there are images that I am omitting from the compile all together. During the compile process, is there a way with this method to ignore the image (or the Replacements code) all together?

That is correct, what we would be essentially doing here is searching and replacing images on the fly whenever you compile. That is what using the text tag for images lets us do. So just as one document can say “Bob” or “Chuck” depending upon your search and replacement, there is no need to duplicate the document and have a “Chuck” or “Bob” version of it.

Sure, since you can search for the image tag as text and replace it with nothing, this would work. You would need some way of identifying these special cases so that when you compile to print they would not be handled.

[size=150]Sample File[/size]

image_replacers.zip (115 KB)

I have attached a sample project which demonstrates all of this. In the left split you’ll find the sample book test containing three image placeholders. These are using the custom placeholder that I proposed, rather than Scrivener’s native image syntax. This way you can disregard the compile implementation details completely while writing. It’s just a figure at this point, or maybe one that doesn’t print.

In the right split, you’ll find the graphics. Note how each graphic has “-rgb” or “-bw” appended to the name. The compiler will be adding that for you, so all you have to type in the editor is the main part of the image name, as shown in the editor.

Okay, now pop open the Compile panel and have a look at the Replacements compile option pane. I’ve left it in B&W mode. Try it now, just click “Compile” and examine the print preview. You should see images “One” and “Three”, but “Two” will be omitted entirely as requested by the ‘noprint’ variant typed into the editor.

If you wish, use the “Format As” compile drop-down to select “E-book (RGB)” from the “Project Formats” section. Compile that and you’ll see three colour images. Both the !fig and !fig_noprint commands will output in e-book mode.

All right, here is how it works in Replacements (looking at RGB first): the first line is as I’ve already described in the prior post. Scrivener searches for “!fig(” and when it finds it, it starts storing text into the “$@” until it reaches “)”. It then replaces everything it just encountered, placing whatever was stored into “$@” where requested.

The second line is basically identical to the first, save that it is looking for the ‘noprint’ version of the command. Both output identically when compiled, in other words.

Switch over to the Print (B & W) preset. The first line is very much the same—the only difference is the With column, which appends ‘-bw’ instead of ‘-rgb’.

The second command is a bit trickier. We can’t use the handy ‘$@’ code because that needs a With value, but we still need to match a variable amount of information between the parentheses. We need a wildcard, basically. RegEx mode gives us wildcards, so I’ve switched that on. Here is the contents of the Replace column:


Since parentheses are significant in RegEx, we put a \ in front of them to tell the search engine we definitely want ‘(’ and ‘)’ to a part of what we are looking for. The ‘.+?’ stuff in the middle is our wildcard. The \n on the end stands for a carriage return.

Since we are removing the figure completely, we don’t want an empty line left where it was. Including the carriage return removes that now empty line.

Naturally, this will only work if a carriage return immediately follows the image—in other words it assumes normal centre aligned images on their own lines.

So yeah, it’s a bit complicated to set up (though you may be able to just export these two presets I created and import them into your project, or copy and paste the replacements between the two project’s compile panes)—but note how easy it is to switch outputs now. You can just flip the mode with the “Format As” menu and forget about it. Meanwhile it is also pretty easy to type the figures into the editor while you are writing.

Thanks so much AmberV ! This is working great for me.

I have a question — how do I ensure center alignment. Is that from in the editor? My images seem to be left-aligned.

Another question, slightly off topic: For images like this I’m assuming it is best to add a width tag for the image size. I know the web so I know 100% is how to get the width to span the page, but I don’t think that works in Scrivener. I understand I can alter image size for print, but can images not scale for ePub and Mobi?

Right, any formatting you apply to the placeholder tag in the editor will be applied to the image (if applicable). So if you want extra spacing above and below it, you could apply paragraph spacing to the text tag in the editor and that would carry over.

Most e-book readers will size the image so that it fits into the width of the screen, so you do not have to worry too much about it. Some let you tap on the image to expand it, so if the image itself is larger than the display they can zoom in. Good for maps and such.

My general advice to people is to size the graphics as they should display, rather than doing so afterward in Scrivener. Using proper image editing software to do so will yield a better result in most cases. The modern trend is to work with real units rather than pixels. So if you want it to print 4.5" wide, you would set the image’s width to be 4.5" (potentially without even resampling it). But if working in pixels is more comfortable, you can do that with placeholder tags (see the manual for the details on that). However it would require tweaking the formula a bit here since right now it assumes that the only thing you type in between the parentheses is the image name. If you append the size info to that, you’ll end up with “<$img:SomeGraphic;w=400-bw>”. If you want to go that route I could make some suggestions, but like I say it’ll be better to use 300 DPI graphics with the dimensions already set in the graphic’s meta-data (using Photoshop, Acorn or similar). E-book vendors are recommending print resolution graphics for e-book publication now, but if you’d prefer to keep things small you’re already set up for having a high-res one way and low-res the other.