Skip to content

scriv2tex is for people who prefer to write raw LaTeX, but would like to organise their writing with Scrivener. The scriv2tex script monitors synced Scrivener folders. When project is synced the monitored folder will be automatically converted to a "tex" folder containing valid LaTeX document.

License

Notifications You must be signed in to change notification settings

gomerser/scriv2tex

Repository files navigation

scriv2tex

scriv2tex is a script that automates the workflow from Scrivener document to TeX document. It is not based on the Scrivener compile, but on the sync function. The resulting TeX document is not one big TeX file, but consists of the same documents found in the Scrivener Drafts folder. The first text file in the Draft folder is treated as preamble file and the required document tags with \includes is generated by the script. This allows the use of \includeonly for partial compilation.

The final workflow for me consists of pressing one single keyboard shortcut to trigger:
- the sync, compilation and presentation of the result in preview.

Getting started

Prerequisites

  • OSX (currently Catalina 10.15.7)
  • Scrivener 3 (currently 3.2.2)
  • Python 3 (currently 3.7.0)

Installation

The scriv2tex script is run in a terminal and therefore needs to be added your PATH environment variable.

Usage

Project initialisation

  1. Create a directory for syncing your project with file extension ".sync".
  2. In Scrivener choose File->Sync->with External Folder...
  3. Choose the external folder created in step 1.
  4. Select the following options:
  • Sync the contents of the Draft folder
  • Sync all other text documents in the project
  • Sync only documents in collection:
  • Prefix file names with numbers
  • Take snapshots of affected documents before updating
  • Check external folder on project open and automatically sync on close
  1. Select the format "Plain Text" with extension "tex".
  2. Confirm the selections by pressing the "Sync" button.
  3. Open a terminal and change to the parent directory of the ".sync" folder where the Scrivener project was synced with. Then start the blocking scriv2tex script:
scriv2tex
  1. the scriv2tex script is now monitoring all ".scriv" directories under the directory where it was executed.

Project usage

Next to the directory created for syncing your project a new directory has been created with file extension ".tex". This is where the scriv2tex script syncs the TeX documents. Here you can also store external content required by your TeX documents, like style sheets, pictures, etc. The scriv2tex script also looks here for a script called "compile.sh", which will, if present, be executed after every sync of your project (File->Sync->with External Folder Now). For an example of compile script, see the example project folder "The Legrand Orange Book.tex".

Example

The project contains an adapted example from latextemplates.com called "The Legrand Orange Book". I copy and pasted the various sections, parts and chapters from the main.tex into seperate text files in Scrivener and copied the compilations insctructions into "compile.sh". Other reference data like style sheets and pictures were copied into the generated ".tex" directory.

Tip 1

Since you'll now will be choosing File->Sync->with External Folder Now frequntly, it's worthwhile to create a keyboard shorcut. Fortunately this is easy on a Mac:

  1. Head to your Mac’s System Preferences (you can find it by hitting the Apple logo at top-left, then clicking “System Preferences”)
  2. Click Keyboard
  3. Click the Shortcuts tab, then click App Shortcuts – the bottom option in the left pane.
  4. Click the “+” button to create your keyboard shortcut.
  5. Pick "Scrivener" and type the exact name of the menu item in the "Menu Title" field, e.g. "with External Folder Now"
  6. Finally, you need to pick your keyboard shortcut. Make sure the key combination you want isn’t already taken by opening your program and testing it out. If something happens, that shortcut is already assigned – if nothing happens and you hear a warning sound, the shortcut is available. I chose ⇧⌘S.
  7. Click Add when you’ve got everything set the way you want it. The change will take affect immediately.

Tip 2

The example compile script concludes with opening Preview to show the updated content. I found this not to work reliably and instead now use Skim to monitor the generated pdf files, which works like a charm.

About

scriv2tex is for people who prefer to write raw LaTeX, but would like to organise their writing with Scrivener. The scriv2tex script monitors synced Scrivener folders. When project is synced the monitored folder will be automatically converted to a "tex" folder containing valid LaTeX document.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published