Dual Export Workflow: Scrivener > LaTeX, and Scrivener > Word (docx)

This is probably a very simple question, but i cant seem to find much on it.

Im an academic writer, and write most of my work in LaTeX (from my Engineering and Psychology past). But in my current discipline (History of Religion), everyone that i collaborate with tends to be inextricably bound to Word. :frowning:

Given that I am just starting a new raft of writing after finishing the last major project, I have upgraded to Scrivener 3 (from 2) and starting to setup my workflow again (Loving the new template btw).

What I am trying to sort out is how I can export to TeX for my personal stuff, and Word for collaboration.

I am using Zotero as a reference manager, exporting through Better BibTeX to a BibTeX database, and using standard cite-keys.

I am wondering whether there might be a mechanism of writing in pure-tex (i.e. using the Plain Text output), and creating a regex to convert the [pagenum][#citekey] type of MMD key to an ODT compatible format for Word output, and a \cite format for TeX.

However, i suspect this would mean removing MMD from my workflow, so a way to do Italics and Bold (the only two formatting options i use regularly) would also be needed.

Anyone have a solution, or able to share what they do?

I almost always compile to LaTeX and DOCX/ODT simultaneously. My workflow is based almost entirely on using Scrivener styles > Markdown. I use Pandoc to generate multiple outputs and to create my bibliographies, which means any output (LaTeX, DOCX, plain text, HTML etc.) get full bibliographic output without any manual intervention. Pandoc refs are specified as [@citekey], and Pandoc does all the heavy lifting when translating to any output.

I use front-matter documents to trigger which of the multiple outputs I want for any given compile, and this all runs via Scrivener’s post-processing function. As an academic I use templates so author names, affiliations, institutions, abstract, author contributions etc. specified in the front-matter get consistently translated into any output. I even have templates for letter writing and generating presentations via Scrivener :slight_smile:

My workflow is fully described here: github.com/iandol/dotpandoc

Thanks for that, it looks like certainly a hundred steps in the right direction. Can you confirm one thing for me though. From my understanding there Pandoc is doing the citation management via citeproc and that should take normal CSL files, and the BibTeX database?

If so I think I can get it to work with Pandoc taking the BibTeX db from Zotero and CSL to output to Word, but leaving it up to xelatex/biber for the LaTeX work.

Edit: ahah, found the Bookends and Pandoc page, which seems to indicate this is right.

Now to setup all the scripts, and the extra layer of LaTeX scripts i need to render all the funky languages and stuff :slight_smile:

Edit2: Looking at it some more, i suspect the issue will be getting Pandoc to reference the citekey not the author.

Edit3: No wait, seems that i was just reading how Bookends does the citekeys. Given BibTeX database, it should just work.

Yes you will be fine with citekeys in the [@citekey] format, and Pandoc uses either citeproc or simply passes onto biblatex using different command options, and these can be automated using pandocomatic so your DOCX gets to use citeproc and your LaTeX can keep using biblatex/biber etc. You can specify the same .BIB bibliography file with metadata and it should be used no matter what the final system is. Personally I use citeproc for all my output formats, and it works for my needs just fine in LaTeX output too, but you may have more complex requirements.

Because there are several tools in this chain and each is extremely flexible, it may seem quite complicated at first to set up. I think it is still worth taking the time to set this up as the time saved once set up more than makes up for it! :stuck_out_tongue:

Thanks, its on my list to setup tomorrow. It may have a few tools in the chain, but not as bad as the old make files I used to write for the analysis engine I built.

Ok, started getting it all setup, and having issues with it finding the ~/.pandoc/pandocomatic.yaml file.

The only novel thing in my setup is that I am storing the pandoc configs in Dropbox and symlinking to the ~/.pandoc directory. I do this for my LaTeX setup as well as i work from multiple machines and it is an easy way of keeping everything in sync and backed up. Permissions are 644, so that shouldn’t be causing any issues.

Does ruby (or pandocomatic) have issues traversing symlinks, or should i be looking elsewhere?

===------ COMMAND OUTPUT: ------=== :: Running: /usr/local/bin/pandocomatic -c pandocomatic.yaml --debug Workflow ::: Config file does not exist: 'pandocomatic.yaml'. :: exit status: pid 99603 exit 243

Edit: resolved by explicitly specifying the .pandoc directory. Would have thought that pandocomatic would have searched the .pandoc location though.

You should not specify the pandocomatic.yaml file on the command line — it will only look in ~/.pandoc if nothing is specified. By explicitly passing -c pandocomatic.yaml you are actually asking pandocomatic to look in the working directory, i.e. the folder where your markdown file is :slight_smile: If you are using scrivomatic, just remove the -y option…

I used this trick in my workflow.scriv example project before Scrivener 3.03 was released so the user put a yaml file in the working directory. It is also used by users who use pandocomatic to build static web sites, you can put different pandocomatic.yaml files in different directories for specific transformations. But normally you won’t need to do that…

symlinks should be fine I think BTW…

Ah yes, i realised that after i had got it working by specifying the .pandoc directory. Working much better now. Now to do the work on the templates.

One thing I don’t think I thought through fully though was the graphics engine, as I tend to use TikZ for my graphics, and of course this needs a TeX renderer. Any suggestions on that front?

Would ImageMagick work for what you want to do? Should be able to install that with Homebrew.

I think this is where the amazing power of Pandoc filters comes into play[1]. There are filters that apparently can take TikZ environments and convert them to embedded images during the conversion:

pandoc.org/lua-filters.html#buil … -with-tikz

tex.stackexchange.com/questions … -docx-file

github.com/jgm/pandocfilters/bl … es/tikz.py

I’ve never used TikZ so I don’t know the specifics, but see if those filters can work for you. Pandocomatic allows you to easily specify to only use the filter for formats that do not support TikZ.


[1] Pandoc uses and intermediate abstract syntax tree model of your doc, so you can easily take semantic chunks like TeX and process each chunk and replace it with something else. If you had to do this with ad-hoc scripts and regexes it would be much much harder…