Numeric Metadata & Placeholder Math

I’d love it if metadata could include numbers and do a little math.

Just addition, subtraction, multiplication and division between two metadata fields.

My particular use case for this is while writing roleplaying game books. I use text-based metadata fields to store placeholders for all sorts of numbers so that it’s easier to tweak them, and I’d love if I could do something like <$custom_subtract:first number,second number> and have it understand “Print the result of this column minus that column”-- saving a lot of tedious document editing.

I know, I know, it’s a niche use case. But it’d be cool.

Isn’t this really a spreadsheet task?

While it’s simple to describe, implementing something like this would be extremely complicated: you’re effectively requesting a built-in programming language. As such, while I don’t speak for Keith, I wouldn’t imagine you’d see something like this in time to be useful for this project, if at all.


I appreciate the response! I think it’s absolutely fair, and I understood at the outset this might be kind of a niche use. I do still think there’s some middle ground between “full featured spreadsheet” and “can add and subtract”, but as always that’s up to you folk.

Still, you make a good point about spreadsheets. I definitely use those a lot as well.

In the meantime, what I settled on is just making the metadata a dropdown list of formulas like (STR-DEX) and running a quick python find/replace over the text after it’s compiled. It works!

If you’re comfortable writing python scripts, you might be interested in Section 21.5.2 of the (Mac) Scrivener manual, which discusses using the Compile engine to apply an arbitrary post-processing script to Scrivener-produced Markdown text.


… I think you just changed my life.

Thank you so much, I’m going to dive right into this. :slight_smile:

Noticing that your forum tag says you’re using Windows, you’ll definitely want the Scrivener 3 beta for this.


I’ve been using the beta for a few weeks now and find it a huge improvement. Thanks for all the work that’s been done on it!

As for my project, thanks to your hint about post-processing I’ve got a plaintext output that’s compiled nicely, processed over with python, and results in finished text I can layout in publishing software really nicely.

Seriously, I can’t thank you enough! I’m working like three times faster now :slight_smile:

Happy to help.

If you have some time and are willing to share your workflow, we’d love to hear about it: