Compile time replacement

Hello,

I was looking for an easy compile time replacement from an external file.

For some of my writings I need to frequently update the data as more cases are added to the study. For this type of work I 'm using Textmate/Sweave/R/Latex.

I would like to use Scrivener to do the main writing and update the numbers as the data are growing.

The “simplest” solution I was able to find until now, is to use R to generate a portion of the compile.list file in the.scriv package, inserting of instance numberof patients key in this file:

<key>SCRCompileProjectVariableReplacementsKey</key> <array> <dict> <key>replacement</key> <string>1120</string> <key>variable</key> <string>numberofpatients</string> </dict> </array>

which is quite cumbersome and I’m still using my Textmare/Sweave… workflow.

Is there a simpler way to do? The ideal solution would be to use a file with all the replacements in it, something like:

mydata.txt:

nbrofpatients,1120 sexratio,0.8 etc...

Patrick

If these numbers are being generated somehow and you are trying to find a way to get that data into the project, I can’t think of a better approach than accessing the file format itself. One of the reasons for its open format is so that stuff like this can be done. I’d focus on making the doing less of a hassle. For example, instead of using a text editor to do the splice yourself, build a script that will go into the project and inject the data where it is needed whenever you run it.

Hi Ioa,

Yes that’s the simplest solution I was able to find until now.

Basically the text I’m writing looks like:
“… at the time of writing \nbofpatients were incuded in the study…”

and since the numbers are changing frequently, the “\nbofpatients” variable needs be replaced at compile time.

So I guess that modifing with a script the compile.list file is the simplest solution, unless there is a hack that I haven’t discovered yet :slight_smile:.

Patrick

The other place where you can independently store data and recall it during compile is custom meta-data. Where replacements work better on a global scale—the entire work needs one placeholder substituted with one datum, custom meta-data can provide individual data points for each item in the binder. Thus you can have one study over here with <$custom:nbofpatients> equally 1,218 and another study over here with a different value entirely—but both are using that same placeholder code in the text or compile settings, where needed. That still won’t resolve a way of getting the data from an external source into Scrivener without scripting, but maybe it gives you another tool to work with that is easier, since you can see those numbers in the meta-data inspector sidebar. These are stored in the master .scrivx file, which has a better XML schema to work with in my opinion. Like I say though, that’s not the best alternative if you just need one value mentioned multiple times in the output; Replacements are good for that.

Excellent!

Metadatas and editing the scrivx file are probably the “cleanest” way to do this!

Thanks!!!

Patrick