Skip to content

Instantly share code, notes, and snippets.

Thomas Hodgson twsh

Block or report user

Report or block twsh

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@twsh
twsh / figure.py
Last active May 19, 2019
Pandoc filter to turn figure environments into images based on https://github.com/jgm/pandocfilters/blob/master/examples/tikz.py
View figure.py
#!/usr/bin/env python3
"""
Pandoc filter to process raw latex tikz environments into images.
Assumes that pdflatex is in the path, and that the standalone
package is available. Also assumes that ImageMagick's convert
is in the path. Images are put in the tikz-images directory.
"""
import os
@twsh
twsh / chicago-author-title.csl
Created Feb 14, 2018
Print the Author + Title as a citation
View chicago-author-title.csl
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="display-and-sort" page-range-format="chicago">
<info>
<title>Chicago Manual of Style 17th edition (author-date)</title>
<id>http://www.zotero.org/styles/chicago-author-date</id>
<link href="http://www.zotero.org/styles/chicago-author-date" rel="self"/>
<link href="http://www.chicagomanualofstyle.org/tools_citationguide.html" rel="documentation"/>
<author>
<name>Julian Onions</name>
<email>julian.onions@gmail.com</email>
@twsh
twsh / syllabus.sh
Last active Jan 24, 2018
Bash script to create a syllabus
View syllabus.sh
echo -e '---\ntitle:\nauthor: Thomas Hodgson\ndate:\n---\n\n\n\n# Bibliography' > syllabus.md
echo -e 'bibliography = $(HOME)/.pandoc/default.bib\n\npdf: syllabus.md $(bibliography)\n\tpandoc --bibliography=$(bibliography) --metadata=lang:en-GB --variable=papersize:a4 --toc --output syllabus.pdf syllabus.md\n\ndocx: syllabus.md $(bibliography)\n\tpandoc --bibliography=$(bibliography) --metadata=lang:en-GB --output syllabus.docx syllabus.md\n\nhtml: syllabus.md $(bibliography)\n\tpandoc --bibliography=$(bibliography) --metadata=lang:en-GB --to html5 --standalone --base-header-level=2 --output syllabus.html syllabus.md\n\nodt: syllabus.md $(bibliography)\n\tpandoc --bibliography=$(bibliography) --metadata=lang:en-GB --output syllabus.odt syllabus.md' > makefile
@twsh
twsh / tikz-qtree.py
Created Nov 12, 2017
Pandoc filter based on https://github.com/jgm/pandocfilters/blob/master/examples/tikz.py to make images with tikz-qtree.sty
View tikz-qtree.py
#!/usr/bin/env python
"""
Pandoc filter to process raw latex tikz environments into images.
Assumes that pdflatex is in the path, and that the standalone
package is available. Also assumes that ImageMagick's convert
is in the path. Images are put in the tikz-images directory.
"""
import os
@twsh
twsh / nozotero.py
Created Oct 1, 2017
Zotero exports to BibLaTeX include some fields that I would prefer not to have in files that I want to share and use with BibLaTeX. This script gets rid of them using https://github.com/sciunto/python-bibtexparser Reads from stdin and writes to stdout.
View nozotero.py
#!/usr/bin/env python3
import sys
from bibtexparser.bparser import BibTexParser
from bibtexparser.bwriter import BibTexWriter
def remove_keywords(record):
"""
@twsh
twsh / noimage.py
Created Aug 29, 2017
Pandoc filter to remove images
View noimage.py
#!/usr/bin/env python3
"""
Remove images.
"""
from pandocfilters import toJSONFilter
def image(key, value, format, meta):
if key == 'Image':
@twsh
twsh / abstract.sh
Last active Jan 24, 2018
Bash script to create files for abstract writing
View abstract.sh
echo -e '---\ntitle:\nauthor: Thomas Hodgson\ndate:\n---\n\n\n\n# References' > abstract.md
echo -e 'bibliography = $(HOME)/.pandoc/default.bib\n\npdf: abstract.md $(bibliography)\n\tpandoc --bibliography=$(bibliography) --metadata=lang:en-GB --variable=papersize:a4 --output abstract.pdf abstract.md\n\nanonymous: abstract.md $(bibliography)\n\tpandoc --bibliography=$(bibliography) --filter=anonymous.py --metadata=lang:en-GB --variable=papersize:a4 --output anonymous.pdf abstract.md\n\ndocx: abstract.md $(bibliography)\n\tpandoc --bibliography=$(bibliography) --metadata=lang:en-GB --output abstract.docx abstract.md\n\nhtml: abstract.md $(bibliography)\n\tpandoc --bibliography=$(bibliography) --metadata=lang:en-GB --standalone --to html5 --base-header-level=2 --output abstract.html abstract.md\n\nodt: abstract.md $(bibliography)\n\tpandoc --bibliography=$(bibliography) --metadata=lang:en-GB --output abstract.odt abstract.md' > makefile
echo -e '.gitignore\n*.backup\n*.bak\n*.docx\n*.html\n*.odt\n*.otl\n*.pdf\n*
@twsh
twsh / section.py
Last active Jun 21, 2017
Pandoc filter to convert links to sections to `\autoref{}` links when the format is 'latex'
View section.py
#!/usr/bin/env python3
"""
Pandoc filter to convert links to sections to `\autoref{}` links when the
format is 'latex'
"""
from pandocfilters import toJSONFilter, RawInline
@twsh
twsh / names.py
Last active Mar 5, 2018
A script to replace full names with surnames on their second occurrence; modifies a text file (first argument) and reads the names from a CSV file (which should have the names as 'Second Name, First Name(s)')
View names.py
#!/usr/bin/env python3
"""
Replace names with surnames except for the first occurrence.
"""
import argparse
import csv
import re
if __name__ == "__main__":
@twsh
twsh / talk.sh
Last active Jul 23, 2018
Bash script to create files for talks
View talk.sh
echo -e '---\ntitle:\nsubtitle:\nauthor: Thomas Hodgson\ndate:\n---\n\n\n\n# References' > slides.md
echo -e '---\ntitle:\nsubtitle:\nauthor: Thomas Hodgson\ndate:\n---\n\n\n\n# References' > handout.md
echo -e 'bibliography = $(HOME)/.pandoc/default.bib\n\nslides: slides.md $(bibliography)\n\tpandoc --bibliography=$(bibliography) --metadata=lang:en-GB --to beamer --output slides.pdf slides.md\n\nhandout: handout.md $(bibliography)\n\tpandoc --bibliography=$(bibliography) --metadata=lang:en-GB --variable=beamerarticle --variable=papersize:a4 --output handout.pdf handout.md\n\nhtml: handout.md $(bibliography)\n\tpandoc --title-prefix='Handout' --to html5 --base-header-level=2 --bibliography=$(bibliography) --metadata=lang:en-GB --output handout.html handout.md' > makefile
echo -e '.gitignore\n*.backup\n*.bak\n*.html\n*.otl\n*.pdf\n*.taskpaper' > .gitignore
git init
You can’t perform that action at this time.