TB2Word
I wanted to write a quick note on exporting from a Tinderbox note in Markdown to a Word .docx file using pandoc, a .bibtex Bibliography automatically generated created by Bookends in the Chicago style using a CSL template.
I am an anthropologist, writing in the humanities, and for a long time, I’ve wanted to be able to create .docx files from Tinderbox, formatted in a very specific, but simple, way. (Times New Roman, 12-point font, 1-inch margins, footnotes, citations in Chicago Style, and double spaced). It’s the standard in the corner of academia where I write.
I’ve used Bookends for a decade and a half. For a long time, I could not get Pandoc to export proper footnotes, and I relied on scanning the document in Bookends. Generating a word file took a lot of fiddling. It slows things down, and basically meant I’d start drafting a project in Tinderbox, and them move to Scrivener at some point. Now, I don’t have to.
I’ve cracked the nut of exporting to Word, inspired by the TinderBox meetup with the author of Bookends, and by Bernardo Vasconcelos and Michael Becker’s discussion of pandoc export.
I wanted to share my results.
TBXConfig.zip (467.2 KB)
The ZIP file contains a folder TBXConfig, which should be placed in the home folder. You will then have to modify the paths in the document. Look for /Users/dtubb
and replace with your own. (e.g. look in the Stamp code
Pandoc:Convert with Pandoc
var theExportedFile;
var theText;
var theConvertedFile;
theExportedFile=$exportDir("TBXConfigNote")+$ExportFileName+$fileType;
theConvertedFile=$exportDir("TBXConfigNote")+$ExportFileName+$convertToType;
$theConversionCommand=$pandocDir("TBXConfigNote")+"pandoc --reference-doc /Users/dtubb/TBXConfig/pandoctemplates/timesnewroman-doblespaced.docx -f markdown+simple_tables+table_captions+yaml_metadata_block+smart --bibliography /Users/dtubb/TBXConfig/bibliographies/bookendsSyncedBibTeXFile.bib --citeproc --csl=/Users/dtubb/TBXConfig/csl/chicago-note-bibliography.csl -s "+theExportedFile+" -o "+ theConvertedFile;
theText=exportedString(this,"tMarkdown");
runCommand("pbcopy ",theText);
runCommand("touch " + theExportedFile);
runCommand("pbpaste > " + theExportedFile);
runCommand($theConversionCommand);
You will also have to install pandoc. (I use home-brew, from the terminal).
brew install pandoc
It will probably take some fiddling to get setup right. I could have abstracted the commands into attributes more. But, I haven’t.
TB2Word
At a high level, what is happening is a TBX stamp calls lightly modified code written by Becker that:
-
Exports a note on the fly to an .md file.
-
Uses Pandoc to convert that export.md file to an export.docx file
-
Using a Word reference file that I crafted.
-
Using a CSL bibliography template that I downloaded.
-
Using a BibTeX file generated by Bookends.
-
The stamp code is mostly Becker’s. It generates the following $theConversionCommand:
/usr/local/bin/pandoc --reference-doc /Users/dtubb/TBXConfig/pandoctemplates/timesnewroman-doblespaced.docx -f markdown+simple*_tables+table_*captions+yaml*_metadata_*block+smart --bibliography /Users/dtubb/TBXConfig/SlipBox.bib --citeproc --csl=/Users/dtubb/TBXConfig/csl/chicago-note-bibliography.csl -s /Users/dtubb/TBXConfig/exports/export.md -o /Users/dtubb/TBXConfig/exports/export.docx
The result, a perfectly formatted Word document, (export.docx) with Times New Roman, 12 point font, 1-inch margins, and double spacing, with citations are properly rendered in footnotes.
The trick, was modifying a Word reference file as a template timesnewroman-doblespaced.docx
to match what I was looking for. For Word, this is a .docx that has all the styles that pandoc uses. It can be edited in Word, in the style editor.
For a bonus, I also got Marked preview working.
Marked Preview
As a bonus, this HTMLPreviewCommand lets a note be previewed in Marked, with a custom .css style, academic.css
. For Marked, I set the style to the custom.css. To make that work, you’ll need to install it using Marked’s settings, and then setup the custom processor in the advanced tab:
$HTMLPreviewCommand:
/usr/local/bin/pandoc -f markdown+simple*_tables+table_*captions+yaml*_metadata_*block+smart -t html --bibliography /Users/dtubb/TBXConfig/bibliographies/bookendsSyncedBibTeXFile.bib --citeproc --csl=/Users/dtubb/TBXConfig/csl/chicago-note-bibliography.csl`
In Marked, you will need to set some settings in the advanced tab.
/usr/local/bin/pandoc
-f markdown+simple*_tables+table_*captions+yaml*_metadata_*block+smart --bibliography /Users/dtubb/TBXConfig/SlipBox.bib --citeproc --csl=/Users/dtubb/TBXConfig/csl/chicago-note-bibliography.csl
You’ll have to check automatically enable for new windows, and enable custom processor, and update permissions.
Conclusion
All in all. With a lot of help from the forum, I can now write in Tinderbox, preview in Marked, and export to Word, with citations and footnotes. It’s a goal I’ve tried to achieve, intermittently, for a long time. It’s something I think scholars in the humanities might find useful.
All in all, it’s exciting for my evolving SlipBox.[1]
Here’s a screenshot:
References
Ahrens, Sönke. How to Take Smart Notes: One Simple Technique to Boost Writing, Learning and Thinking – for Students, Academics and Nonfiction Book Writers. CreateSpace Independent Publishing Platform, 2017.
-
Ahrens, How to Take Smart Notes. ↩︎