Varying some material in the Custom LaTeX preamble

So I’m searching for a best practices workflow here.

I’ve got a longish paper (11K words) that includes a couple of pictures generated by the LaTeX package Tikz. Let em tell you what I am doing, followed by what I want, if possible, to do.

As it stands, I have a Custom document class set up in the File -> Compile -> LaTeX Options window, which is what I use to basically generate TeX documents. It’s got a moderate set of packages loaded, macros defined, and so forth. I use this for almost all of the TeX I generate from Scrivener.

The current project I am working on uses these Tikz pictures (Tikz is like xypic or pstricks; it draws graphics). Tikz requires loading itself and any special libraries, then assigning any global style options, before the \begin{document} command (so I can’t simply pass those through with Front Matter, I think).

\usepackage{tikz}
\usetikzlibrary{positioning,decorations.pathreplacing,decorations.markings,calc}

\tikzstyle{stage}=[draw, circle, align=center, text width=2.5cm, minimum height=2em]
\tikzstyle{connectR}=[->,thick]

What I Do: I make standalone PDF or PNG of the output in LaTeX, and then I include those graphics files in my Scrivener project. Scrivener does its thing and simply re-uses the graphic.

What I Want: I would like to be able to, for only projects where I use tikz (or whatever package), have the preamble material come straight from Scrivener, saving me from having to remember/monkey around with that piece of the preamble when I move to my TeX editor.

Is this as simple as setting up a Project Compile Format Preset and using that instead of the Global Compile Format Preset? Are there any conflicts or precedences I should be aware of?

Thanks in advance for any/all help.

This looks like a fairly static chunk of LaTeX code—by that I mean it’s not something you would need to vary per-project, at the code level. If that is the case, then I would consider adding this snippet to your texmf folder so that all of your works can reference it if needed via a simple input command. MMD has a meta-data key for that, so you can add that to your compile settings as needed. For example you could add a file called “usetikz.tex” to the texmf folder (~/Library/texmf on my system), then add the following key to your MMD meta-data block:

LaTeX Input: usetikz

Now the one drawback to that method is that meta-data keys are not saved into compile presets (since they are nearly always project specific). So an alternative you can take to putting these into the Meta-Data compile option pane itself, is to create a document called “Meta-Data” and put your custom MMD formatted meta-data keys in there. Scrivener will look for the very first item in the Contents compile list, and if it is called “Meta-Data” it will glue them together with any automatically generated or manually created meta-data in the compile settings.

Combine that idea with the “Front Matter” feature, and you can swap out sets of meta-data on the fly. I use this technique to switch between Windows and Mac settings with the user manuals. I have two different meta-data blocks, and alternate between them as needed.

Finally, yes, you could have two different Project Presets and put this code chunk into one of them but not the other. Presets will store the custom preamble text independently.

Pretty much what I was going to suggest. Using the LaTeX input command as Ioa suggests is the best way forward.

Once you start down that road you might want to look at going as far as using meta data to input a series of tex files, rather than putting all the latex header/preamble into Scrivener. That makes it very easy to control what is included when you typeset the tex file.

MrGruff,

I think I like the idea of what you’re suggesting. How would I do that with the “Custom…” preamble? Alt’ly, how would I set up my MMD -> LaTeX enviro in Scrivener to simply have a set of LaTeX input files?

Have a look at my beginner’s guide to ScML: viewtopic.php?f=21&t=17239

That explains how to set up the MMD support files (which you’ll need to get from github), and the order in which they call each other. Also, what to put in the metadata pane of the compile dialogue. For most purposes, you would just need to add the \usepackage command for Tikz in the tex file which contains the package definitions (mmd-memoir-packages.tex is the usual one).

Infortunately, the guide doesn’t cover the ‘custom’ approach (that didn’t exist when I wrote it), but you should be able to put an ‘include’ in there, pointing to your standard tex file. The best place to put that is:
~library/texmf/tex/latex/mmd/