How to compile only text that has a style, not other text

Is it possible to compile only text in a document that has a certain style? I know I can delete text that has a certain style, but what if a document has a ton of text in it, but only 5 paragraphs that are assigned one or more styles. I only want those 5 paragraphs compiled to a Word doc. Anyone know how I can do this?

More detail: My Scrivener file has multiple documents, say each one is a chapter in my book. Each document has all my notes on that chapter at the bottom, and at the top of the document are the 5 final paragraphs of that chapter. Those 5 paragraphs are assigned a style I called “Body text.” There might also be a “Heading” style in the doc that is the title of the chapter. The rest of the text in the document, my notes, does not have a style assigned to it (it’s plain text, i.e., opt-cmd-0). All I want to do is export the Body text paragraphs and the Heading paragraphs from each document into a single Word doc. I’m using 3.3.6 on a Mac.

Thanks!

Excuse me for asking, but why did you put your notes in the Drafts documents in the first place? The Draft folder is called that for a reason, it is only meant for the output of the actual text, e.g. a book. And it is one of the strengths of Scrivener that it offers several other options for saving notes: For example, the Notes section in the Inspector, Comments, or you can designate a section in the Binder outside the Drafts folder for your notes (linked by document bookmarks).

If you need to keep the notes in the Drafts folder for some reason unknown to me, you should keep them in separate texts/documents. You can exclude these when compiling. You can do this manually. Or you can create a template for the notes with the Include for compilation checkbox unchecked. Or you can give them a label or a status or perhaps a custom metadata and set a compilation filter to exclude these items.

And by the way: Although it is possible, it is not recommended to use a style like “Body Text”. The body text should have “No style”, only deviations from it should have a style (like in html). And if you use the chapter headings in the binder, you don’t need a “Heading” style or a heading paragraph at all.

1 Like

Format / Style / Styles panel

In the styles panel, right clicking a style has a function to select all text of a specific style.
Copy/Paste your text to a new blank document. Do what you want to do with it afterwards.

That’s pretty much the only way.

Yes, you can do this with a bit of style magic in the compiler. What you want to do is set up a section layout that assigns a compile-time “Delete me” style to the main text of your documents. Because of the way styles layer, the styles you’ve applied within the project to the text will override the compile style, so in the end, only the unstyled text of the document will take this compile style. So that text then is deleted, per the style settings, and the other text remains.

  1. In File ▸ Compile, right-click the format you want to use as a base and choose Duplicate & Edit (or edit whatever one you’re already working on)
  2. Select Styles in the list on the left, then click the + button in the upper right and select Paragraph Style to make a new style for the compile format and give it a name (e.g. “Delete”)
  3. Tick the box for the top option on the right, Delete text of this style
  4. Select Section Layouts on the left. For whichever layouts you want to assign to the documents you described—that have styled text you want to preserve and then unstyled text that should be removed:
    1. Select the row in the table and make sure its box in the Text column is ticked
    2. Tick Override text and notes formatting at the bottom
    3. Click into the text in the format editor and then click the styles button on the left of the format bar and apply the “Delete” style created earlier
  5. Give the compile format a name and save it.
  6. In the main compile window, click Assign Section Layouts at the bottom of the middle pane and assign the layouts you just set up to the proper document section types

I’ve attached a sample project with a simple compile format that does this.
DeleteUnstyled.zip (103.2 KB)

Since you mention that you have the document titles included in the text itself and styled, you may not want to include other elements, but note that you could do so; nothing in this prevents you ticking the section layout’s Title option, for instance, and formatting that however you like, including applying a different style to it. You’re only assigning your “Delete” style to the main document text, so anything else you add to a section layout will still come out as normal.


All that said, I would in future encourage an approach more in line with what @suavito suggested above, keeping big blocks of notes in their own documents. You could still keep these in the Draft folder right beside the chapter text but toggling off their “include in Compile” setting; by viewing the Draft or potions of it in Scrivenings mode, you’d get a view similar to what you have now in the editor, with the chapter text followed by the notes, but by being separate documents, they’d be much easier to work with when compiling. Then you wouldn’t be reliant on a sort of backward approach to wrangling the styles, and you’d then be able to leave the real chapter text unstyled and handle all of that as part of the compile—perhaps similar to the approach above of applying a style at compile time, but without deleting the text. :wink:

There’s also no need to keep the notes documents together with the main text in the Draft folder just to view the together; with the Bookmarks pane in the inspector, you can drop links to any number of documents from anywhere in the project binder for reference and view the text in the inspector or in the split editor or copyholder.

2 Likes

Not sure that works under Windows (?)

I tried a couple of months ago and it wouldn’t delete the body text. IIRC

If my memory serves, the part where the body text takes the looks of the style works, but it reverts to default formatting when that style is ticked to be deleted from the resulting output. No text ends up deleted.

Ah, on a quick test it looks like it’s not, but that’s a bug and I’ll make sure it’s written up. It works on Mac, which the OP specified.

1 Like

Should wish-list a solo-style function…