Skip to content

Instantly share code, notes, and snippets.

@austinjp
Last active September 28, 2015 19:12
Show Gist options
  • Save austinjp/9388e07cf8c952ea1c99 to your computer and use it in GitHub Desktop.
Save austinjp/9388e07cf8c952ea1c99 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Stupid script to render LaTeX from Authorea to PDF, RTF, ODF and HTML.
# I can't get Authorea to reliably render things, so
# it looks like I'll have to do it myself. I was really
# hoping to avoid learning LaTeX et al, so this is
# an Ugly Hack.
# The commands pdflatex and bibtex are repeated as per:
# http://tex.stackexchange.com/questions/119459/undefined-citations
# Process:
# 1. You'll probably want to apt-get install pandoc texlive latex2rtf
# 2. Ensure Authorea is synchronising to Github.
# 3. Include any usepackage statements etc into header.tex
# 4. git clone --branch master https://github.com/you/your-authorea-repo.git
# 5. cd into that directory and copy this script into it.
# 6. Go to Authorea and download your doc with the choices:
# "Thesis" and "LaTeX" (Don't select any specific publisher).
# 7. Name that file "doc.tex" and put it in the directory used above.
# 8. Run this script and pray :) Output should be in doc.pdf
# Move old files to a backup folder:
export AUTHRENDTEMPDIR=bak-$$
export AUTHRENDTEMPDIR2=bak-$$-2
mkdir $AUTHRENDTEMPDIR
mv -f doc.4ct doc.4tc doc.aux doc.bbl doc.blg doc.css doc.dvi doc.html doc.idv doc.lg doc.log doc.odt doc.out doc.pdf doc.rtf doc.tmp doc.xref doc.*bak* $AUTHRENDTEMPDIR
# Forcibly include Authorea's header.tex file, yuck:
sed -i.bak1 's/\\begin{document}/\\include{header}\n\\begin{document}/' doc.tex
# Fix some LaTeX which fails to render well in RTF. This could stand some improvement, see
# http://tex.stackexchange.com/questions/79046/baselinestretch-vs-setspace
sed -i.bak2 's/\\itemsep1pt\\parskip0pt\\parsep0pt//g' doc.tex
tex -interaction batchmode doc.tex
pdflatex -interaction batchmode doc.tex
sed -i.bak1 's/converted_to_latex/biblio/g' doc.aux
bibtex doc.aux
pdflatex -interaction batchmode doc.tex
sed -i.bak2 's/converted_to_latex/biblio/g' doc.aux
pdflatex -interaction batchmode doc.tex
sed -i.bak3 's/converted_to_latex/biblio/g' doc.aux
# Generate RTF file:
latex2rtf doc
# Generate ODT (OpenDocument) file. This is slightly broken, but
# can be opened in Word. It generates errors, but appears to work.
# The formatting of the references is bad, though.
pandoc doc.tex -o doc.odt --bibliography bibliography/biblio.bib -s
# Generate HTML with associated CSS. This is broken, images fail.
# Also it will prompt you for input, type Q and enter as many times as necessary.
htlatex doc.tex "html,word" 'symbol/!' "doc"
mkdir $AUTHRENDTEMPDIR2
mv -f doc.4ct doc.4tc doc.aux doc.bbl doc.blg doc.dvi doc.idv doc.lg doc.log doc.out doc.tmp doc.xref doc.*bak* $AUTHRENDTEMPDIR2
# You should now have:
# doc.pdf
# doc.rtf
# doc.odt
# doc.html
# doc.css
# ... plus a bunch of other files (doc.blg, doc.dvi etc) in a backup directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment