Skip to content

Instantly share code, notes, and snippets.

@andrewheiss
Created December 3, 2012 04:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrewheiss/4192699 to your computer and use it in GitHub Desktop.
Save andrewheiss/4192699 to your computer and use it in GitHub Desktop.
tex2docx
#!/usr/bin/env bash
filename="${1}"
no_extension=${filename%.*}
# echo "Converting Markdown to LaTeX..."
# multimarkdown -t latex ${no_extension}.md > ${no_extension}.tex
echo "Running LaTeX..."
latex -interaction=nonstopmode ${no_extension} > /dev/null
echo "Running Biber..."
biber ${no_extension} > /dev/null
echo "Running LaTeX again..."
latex -interaction=nonstopmode ${no_extension} > /dev/null
echo "Running LaTeX one more time..."
latex -interaction=nonstopmode ${no_extension} > /dev/null
echo "Converting to .odt..."
tex4ht ${no_extension} > /dev/null
mk4ht oolatex ${no_extension} > /dev/null
echo "Converting to .docx (wait while Open/LibreOffice opens and converts the file)..."
## CHANGE THE PATH TO OPEN/LIBREOFFICE HERE!
/Applications/LibreOffice.app/Contents/MacOS/soffice.bin --invisible --convert-to docx "${no_extension}".odt
##
echo "Cleaning up..."
rm "${no_extension}".4ct
rm "${no_extension}".4tc
rm "${no_extension}".aux
rm "${no_extension}".bbl
rm "${no_extension}".bcf
rm "${no_extension}".blg
rm "${no_extension}".dvi
rm "${no_extension}".idv
rm "${no_extension}".lg
rm "${no_extension}".log
rm "${no_extension}".run.xml
rm "${no_extension}".tmp
rm "${no_extension}".xref
echo "...done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment