New "New from template" item from selected text

I’m not sure if this is already possible, but after writing with Markdown in a different editor and pasting the text into a Scrivener text file in the binder, I would love to be able to go through the document and quickly turn (e.g.) math blocks into equation items that I typically create by selecting “New from template” in my custom project. This would be somewhat like the existing “Append Selection to Document” feature, but instead of sending the text to an existing document, it would send it to a newly created binder item.

UPDATED: For an illustration of what I’m looking for, see this post below.

One way I can do this manually is to use the “Import and split” option and, with that, the “Split into sections by finding separators in the text” option. Then I can manually make all mathblocks, which will then be their own section, into my custom equation section type. But that’s a lot of trouble to go through. A quick “New 'New from Template” item" from selected text option would be much easier.

“Append Selection to Document” allows you to create a new document as the destination. And if the destination document is in your previously designated Templates folder, then poof the new document will become a template.

Thanks. But I don’t want the new document to become a template . I want it to become a new document in my binder that is of the preexisting template’s type.

You can assign default templates to specific folders. Create/select the folder, then use the Documents → Default Template for Subdocuments menu. Use this folder as the destination for your newly created equation document. Once the document is created, you can move it wherever you want.

Thanks. I think it’ll be easier for me to do what I describe in the last paragraph of the original post above. But I’d still love the ability to quickly create a new item from selected text, sort of like how one can create a new text by choosing “split at selection”.

That ability already exists. See my first post.

If your equation “template” only involves assigning a Section Type or other metadata, that’s easy to do in bulk, for instance in the Outline view. If it includes some kind of special formatting – I’m guessing not, since it’s Markdown – then you would want to use a Document Template instead.

I guess I’m not being clear enough. See the pics below. The first one shows a single document with plain text. In the middle there is a math block. The second and third pics show what I’d like to be able to do. I’d like to be able to highlight a selection of text, in this case the math block. And then I’d like to quickly be able to create a new binder item from an existing template whose text is the text I selected.

Does that make sense? And is that already doable as easily as I am saying I’d like to be able to do it? If I’m following, your solution is to Append selection to the existing template, and then move the new item back up higher in the binder where the other composition text files are. But that solution requires me to move around the binder more than I’d like to have to do, and it preserves the selected text in the original text document. I don’t want that text to be in two places.

Create the folder where you want your math blocks to go.

Assign the desired Document Template as the default template for that folder.

Select text, ‘Append Selection to (New) Document,’ where the math folder is the destination for the new document.

Once Scrivener creates the new document, it will return you to the original document with the same text selected, so just hit the Delete key to get rid of it.

If you want to put the math blocks in random locations, rather than in a single folder, then yes, moving them will take additional steps. Whether you view this as “harder” than creating a document full of mathblocks and splitting them up is really up to you.

I guess key to the tradeoff is deciding what you want the equation template to do. If you’re just assigning a Section Type, as I said, it’s probably easier to create the document in place and use the Outliner to bulk-assign the Equation Section Type.

For the specific behavior in screenshot 3, what about Documents → Split? Then use the Inspector to assign the Equation Section Type.

Again, this approach doesn’t assign a template ™, but it’s otherwise the simplest way to achieve what your screenshot suggests you want.

1 Like

Thanks for the clarification on the goal. Using a few of Scrivener’s features, you may be able to get what you’re after, not with a single command but perhaps more streamlined than what you’ve been doing. It depends a bit on what you need to preserve from the document template. As I understand it, the goal is:

  1. Highlight some existing text and separate it from the surrounding text as its own document, but within the same flow of text–essentially turning the original single document into three (pre-math, math, and post-math)
  2. Keep the original flow of text visible in the editor, so what was a single document is now still shown together in Scrivenings view
  3. The new math document should be based on an existing document template

For the last point, the method I’m suggesting here will not apply any formatting from the document template to the math text you’re using to create the new document; the selected math text will be appended to any default text in the template using its original formatting. (You described it as “plain text” but Scrivener is a rich text editor, even if you’ve given it an appearance of a plain-text environment, so the text does have formatting that will go along with it when it’s turned into a new document.) So if you created the template document with some formatted placeholder text, for instance, that is pre-selected when you use New From Template so that new text you type takes on that formatting, that would not apply in this case. The placeholder text and its formatting would stay as a paragraph in the new document and the math snippet would not overwrite it.

If that’s all right, and what you’re after from the template is its metadata, title, unique icon, etc. then this may work for you:

  1. In Scrivener ▸ Preferences click Behaviors, then Drag & Drop and tick the option to Delete text dragged to other areas.

  2. View your text in Scrivenings from the start by selecting the parent container in the binder—e.g. in your example screenshot, you’d select the Manuscript folder, even though there’s only one document within it.

  3. With the parent container selected and focus in the binder, choose Documents ▸ Default Template for Subdocuments ▸ and select the math document template you want.

    This is going to affect all new documents you create in this folder, so it’s probably a temporary setting for while you’re doing this editing pass and separating out your math chunks. After you’re finished, reset this to the default Text.

  4. In the editor, place the cursor before the math segment you want to make its own document and choose Documents ▸ Split ▸ at Selection (or ⌥⌘K with the keyboard).

  5. Now, select the math text and drag the selection into the binder just above the new document created from the split.

The dragged text will become a new document in the binder using the set template and will be removed from the original document; it will remain visible in the Scrivenings editor in its place between the preceding and following text.

1 Like

Here’s another approach that would accomplish what you looking to do without too much ado:

  1. Press ⌘X to cut the equation text.
  2. Press the shortcut to split at the cursor point and probably just hit Esc to terminate rename. Hit to select the first segment.
  3. Use Project ▸ New From Template ▸ (equation). We get a new item as a sibling below the current.
  4. ⌃⇥ to shift over to the editor.
  5. ⌘V (or ⇧⌥⌘V) to paste what we cut in step 1.

The nice thing about this approach is that it is fully keyboard and menu command accessible, meaning automation like Keyboard Maestro (Mac) or AutoHotKey (Win) can step in and make this pretty much “one click”.

Now as to the feature request itself: the problem as I see it is that there are multiple things going on here that do not have a native single-click solution (let alone all at once):

  • We are splitting the text twice, both before and after the selection range, resulting in three items.
  • One of the items does not split in the fashion it ordinarily would (inheriting the attributes of the item it was split from), but instead adopts attributes from something else in the binder (a template).

The problem isn’t so much that your idea isn’t addressing something useful—I definitely see what you are going for here—but rather that I’m having a hard time thinking of an elegant solution to addressing how any of the above happens with any more elegance (or less keyboard/clicking events) than the existing methods.

A three-way split? Sure, though it might be a mouthful to try and explain the result in a menu command, that is at least conceivable—and such things really do need to be explained well since this is one of those few things you can do in the editor that you can’t always as easily undo.

But how to have one (or more, I guess?) of the three split items “know” that it should import metadata attributes from a particular other binder item or template? Sure you’re thinking of the middle document being split off in this particular use case, but why not the first or third, or even all three? And how do we designate which item to pull attributes from?

Further, there are complications with using a template to stuff existing text into, or to in other words, apply a template to an existing item. What happens if the template has sample text in it already? I suppose we append or prepend it (neither is clearly better to my mind), but that will probably require further action on your part to clean up the result.

You might think metadata is more straight-forward, but is it? In this case here, there might be important attributes about the item we’re splitting off from that we might want retained. Should we split normally, so synopses and notes and keywords and other ephemera get applied to split 2 and 3, and the overwrite anything conflicting that the template assigns?

And what is conflicting? What is default in this case? For some things there may be clearer answers, but is deleting all keywords because the template has no keywords appropriate and expected? Should the action be essentially like a macro from New From Template + Add new item below with stuff + Select both and Merge? That’s a result that is in my opinion noisy for the sake of safety rather than ideal.

I don’t know, I just have a lot of questions about how this would work in practice. We might program it to work very specifically the way you want (only the middle item gets a template’s attributes, template overwrites everything in the Inspector, etc.), but I bet you if we did that we’d just get more feature requests to make it more flexible—which means more interface, and less elegance.

1 Like

Thanks to all! I’ll consider my work here to be done :wink: