Importing (just the) Styles for LaTeX

Hello, This could also go into the brand-new forum, but it’s all about LaTex. My question is how to I copy (compile format) styles from another template?

I created a new project, and I created a rather a setup that works great for my complicated journal requirements. Of course, I’m writing in Scrivener and compiling document output for LaTex (to send to LaTex, I’m not using MMD at all btw.)

This is working great(!) except I made for the fundamental mistake: I didn’t start from the non-fiction LaTex template. (I really thought I had, but I guess I didn’t.) The non-fiction template has many styles set up in the format options that I just realalised I need. But I’ve already set up some pretty complicated section layouts to support my document and my journal.

That’s what I’d like to import the styles only from the Non-Fiction LaTex Template. (Or I could import my section layouts into a new project created from the Non-Fiction Template. Whichevers easier. Can you all suggest something to help?

Cheers,
Steve

1 Like

Oof, there isn’t actually a way of only copying the styles out of one compile Format and into another—at least not in the front end. If you are comfortable editing XML files, here’s what I’d do:

  1. First, duplicate your current working Format to a second copy, so that edits can be safely done with it. Just right-click, “Duplicate and Edit”, give it a name and then save and close the compile interface. I’d also suggest saving the format to “My Formats” instead of in the project, just so it’s easier to get at.

  2. In the copy of the LaTeX template you created to look at it, go into compile, edit its built-in Format, and also save it to “My Formats”. Now both of these should be globally available to all projects.

  3. From the main Scrivener menu, use the “Reveal Support Folder in Finder” menu command, and in the Finder window that pops up, navigate into “Compile Formats”.

  4. Open the two .scrformat files you just saved to this location in a suitable coding editor—or just any plain-text editor if you lack one.

  5. In the stock LaTeX format file, search for “<Styles>” (it should be around line 1245).

  6. At this point you’re going to be copying and pasting individual <Style> elements, and their child nodes, over to your project’s format. An editor with a two-pane layout will help a lot here, because you don’t want to duplicate style names. If you want to replace a style (like Caption), then make sure the old one is removed or renamed by changing its Name attribute.

    Depending on what you need, you could also just copy the entire <Styles> element over, replacing it fully in the working format. If you haven’t done any style work at all yet, that will of course be the easiest approach.

  7. Save the XML file, and open up compile and edit your working copy. If the Styles pane loads up fine, and everything looks copacetic, you could go back and export your un-edited format (via right-click) as a backup, and then delete it, then maybe save the working copy into your project if you don’t want it global.

Now if you decide you’d rather take the other approach and import your Section Layouts into the template’s format and run with that, it’s much the same procedure, only you’d be copying nodes out of the <SectionLayouts> element. As before, you do want to avoid name collisions. Overall I would say it would be easiest to copy the styles though, as you’ll have to reassign your section type assignments otherwise, and there may be other things the template format is doing that you don’t want (I’d go through all of the panes in order, using the GUI, to see if it would be worth using it).

While you’re looking at panes, one of the styles depends on a replacement, it’s the Index Term style. We need to use a replacement because that one takes the styled word and duplicates it, so you end up with something like this \index{this}.

If all of that sounds like too much work—I think just going through the two styles lists side by side in the software, and copying and pasting prefix/suffix fields will work fine. Just be sure to check them all, even if they look blank, some might start with a newline.

1 Like

Thank you so much for the detailed answer Amber.

I really appreciate it. I will probably try the XML method. But maybe it’s easier to just copy styles in a “split” screen as you suggested.

Cheers!
Steve

1 Like

Also thanks for the heads up on the replacement for the index style ! :slight_smile: