Permalink
Browse files

cleanup

  • Loading branch information...
1 parent 3f3a1d6 commit 29ab32342e9c07272b4796778cd86d518368b3b2 @cboettig committed Apr 11, 2013
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,103 @@
+#!/usr/bin/env bash
+# ================================================================================
+# A git-diftool utility for a TeX file using `latexdiff`.
+#
+#
+# Usage
+# -----
+# git latexdiff [<commit>]
+# git latexdiff --cached [<commit>]
+#
+#
+# Installation
+# ------------
+# Configure ~/.gitconfig as the follwing::
+#
+# [difftool.latex]
+# cmd = git-latexdiff.sh "$LOCAL" "$REMOTE"
+# [difftool]
+# prompt = false
+# [alias]
+# ...
+# latexdiff = difftool -t latex
+#
+#
+# Requirements
+# ------------
+# This program requires latexdiff installed.
+#
+#
+# Notes
+# -----
+# * CAUTION! This script can not handle a document consisting of multiple TeX
+# files.
+# * On Mac OS X, it create a new instance of Skim.app and wait until the
+# instance quits.
+#
+# ================================================================================
+\unalias -a
+hash -r
+
+PrintError() {
+ printf "$@"
+} >&2
+
+
+# Set up a user configuration here.
+LATEX=pdflatex
+BIBTEX=bibtex
+case $(uname -s) in
+ Linux)
+ VIEWER=evince ;;
+ Darwin)
+ # Create a new instance of Skim.app and wait until the instance quits.
+ VIEWER="open -n -W -a Skim.app" ;;
+esac
+# Set LaTeX options.
+LATEXOPTS="-src-specials -parse-first-line"
+
+
+# Return -1 and die *silentlly* if no change has been made to the TeX file.
+[ ${1##*.} != "tex" -o ${2##*.} != "tex" ] && exit 1
+
+# Create the temporary directory.
+TMPDIR=$(mktemp -d /tmp/git-latexdiff.XXXXXXXX)
+PREFIX=$(mktemp diff.XXXXXX)
+status=$?
+if [[ -z "$TMPDIR" ]]; then
+ PrintError "Failed to create temporary directory.\n"
+ exit $status
+fi
+LATEXOPTS=$LATEXOPTS" -output-directory $TMPDIR"
+
+# Set a trap for cleaning up the temporary directory.
+trap 'rm -fr $TMPDIR $PREFIX*' ABRT EXIT HUP INT QUIT
+
+# Run `latexdiff`.
+latexdiff "$1" "$2" >$TMPDIR/$PREFIX.tex
+status=$?
+if [[ ! $status ]]; then
+ PrintError "\`latexdiff\` failed.\n"
+ exit $status
+fi
+
+# Make sure that cross-references are all right.
+{
+ $LATEX $LATEXOPTS $TMPDIR/$PREFIX.tex
+ # Move diff.aux to the current directory and run `bibtex`, and then move
+ # the resultant files and diff.aux back to $TMPDIR. As of August 2011,
+ # `bibtex` installed via MacPorts does not allow to process *.aux not
+ # located in the current directory.
+ #
+ mv $TMPDIR/$PREFIX.aux .
+ $BIBTEX $PREFIX
+ mv $PREFIX* $TMPDIR
+ $LATEX $LATEXOPTS $TMPDIR/$PREFIX.tex
+ $LATEX $LATEXOPTS $TMPDIR/$PREFIX.tex
+} >/dev/null
+
+# Launch the viewer.
+$VIEWER $TMPDIR/$PREFIX.pdf
+
+
+# vim: ft=sh sw=4
View
@@ -1,108 +0,0 @@
-
-
-
-
-This gives a quick example about how we can add citations into a markdown file with the same ease that we can in latex.
-I illustrate two different ways to get citation information. In the first example we look up the metadata automatically given
-the digital object identifier (doi) for the paper.
-
-In the second example we will read in a bibliography in bibtex format using the bibtex package, which can then be expressed in markdown immediately.
-
-Next I create an inline citation function that can take either a list of doi's or bibentry topics and format them into inline citations, while also storing this information to generate the full bibliography later.
-
-### DOI Approach
-
-The crossref function is available in the rplos package 0.0-6, (use the github copy, not in the CRAN version yet)
-
-
-```r
-require(rplos)
-```
-
-
-
-
-
-
-
-
-### Bibtex approach
-
-For convenience let's write the entry we pulled with crossref to a bibfile, just to get a simple bibfile as our starting point.
-
-
-```r
-library(bibtex)
-entry <- crossref("10.1111/j.1461-0248.2005.00827.x")
-write.bib(entry, file="example.bib")
-```
-
-
-
-
-We simply read in any bibtex file and print the citation:
-
-
-```
-Halpern BS, Regan HM, Possingham HP and McCarthy MA (2006). "Accounting
-for uncertainty in marine reserve design." _Ecology Letters_, *9*. ISSN
-1461-023X, <URL: http://dx.doi.org/10.1111/j.1461-0248.2005.00827.x>.
-```
-
-
-
-Now this would be much more awesome if we could generate keys on write.bib and use those bibtex keys, instead of the index value, `[[1]]`, to generate the citation.
-
-## Inline citations
-The other thing we need is a way to print inline citations that would just use a given shortened format (e.g. author-year, or a number) and add the citation to a `works_cited` object, which we could then use to generate the full citation information at the end.
-
-
-
-```r
-empty <- list()
-class(empty) <- "bibentry"
-options(works_cited = empty)
-pcite <- function(x){
- sapply(x,function(x){
- if(is(x, "character"))
- entry <- crossref(x)
- else # assume it's a bibentry object already
- entry <- x
- ## keep track of what we've cited so far
- options(works_cited = c(getOption("works_cited"), entry))
-
- ## And format the inline citation
- n <- length(entry$author)
- if(n==1)
- sprintf("(%s, %s)", entry$author[[1]]$family, entry$year)
- if(n==2)
- sprintf("(%s & %s, %s)", entry$author[[1]]$family, entry$author[[2]]$family, entry$year)
- else if(n>2)
- sprintf("(%s _et. al._ %s)", entry$author[[1]]$family, entry$year)
- })
-}
-```
-
-
-
-Note that the function can take a list of objects (though I'll have to clean up their formatting), and it can take either dois or the biblio list from above. It would be easy to write the textual citation formatting and number formatting too. I may add these to a simple R package for that purpose.
-
-Now we can gereate inline citations like this `(Halpern _et. al._ 2006)`. Hmm, looks like we need a way for `rinline` code to use `asis` formatting though.
-
-## Bibliography
-Then at the end of the document, use this command to print the bibliography generated by the use of our inline citations.
-
-
-```r
-getOption("works_cited")
-```
-
-Halpern B, Regan H, Possingham H and McCarthy M (2006). "Accounting for
-uncertainty in marine reserve design." _Ecology Letters_, *9*. ISSN
-1461-023X, <URL: http://dx.doi.org/10.1111/j.1461-0248.2005.00827.x>.
-
-
-
-
-
-
View
@@ -1,88 +0,0 @@
-<!--roptions tidy=FALSE, warning=FALSE, comment=NA, message=FALSE-->
-<!--begin.rcode echo=FALSE
-#require(socialR)
-#render_wordpress()
-render_gfm()
-end.rcode-->
-
-This gives a quick example about how we can add citations into a markdown file with the same ease that we can in latex.
-I illustrate two different ways to get citation information. In the first example we look up the metadata automatically given
-the digital object identifier (doi) for the paper.
-
-In the second example we will read in a bibliography in bibtex format using the bibtex package, which can then be expressed in markdown immediately.
-
-Next I create an inline citation function that can take either a list of doi's or bibentry topics and format them into inline citations, while also storing this information to generate the full bibliography later.
-
-### DOI Approach
-
-The crossref function is available in the rplos package 0.0-6, (use the github copy, not in the CRAN version yet)
-<!--begin.rcode
-require(rplos)
-end.rcode-->
-
-<!--begin.rcode results="asis",
- crossref("10.1111/j.1461-0248.2005.00827.x")
-end.rcode-->
-
-
-### Bibtex approach
-
-For convenience let's write the entry we pulled with crossref to a bibfile, just to get a simple bibfile as our starting point.
-<!--begin.rcode
-library(bibtex)
-entry <- crossref("10.1111/j.1461-0248.2005.00827.x")
-write.bib(entry, file="example.bib")
-end.rcode-->
-
-We simply read in any bibtex file and print the citation:
-<!--begin.rcode r bibex, results="asis", echo=FALSE
-biblio <- read.bib("example.bib")
-biblio[[1]]
-end.rcode-->
-Now this would be much more awesome if we could generate keys on write.bib and use those bibtex keys, instead of the index value, `[[1]]`, to generate the citation.
-
-## Inline citations
-The other thing we need is a way to print inline citations that would just use a given shortened format (e.g. author-year, or a number) and add the citation to a `works_cited` object, which we could then use to generate the full citation information at the end.
-
-<!--begin.rcode
-pcite <- function(x){
- if(is.null(getOption("works_cited"))){
- empty <- list()
- class(empty) <- "bibentry"
- options(works_cited = empty)
- }
- sapply(x,function(x){
- if(is(x, "character"))
- entry <- crossref(x)
- else # assume it's a bibentry object already
- entry <- x
- ## keep track of what we've cited so far
- options(works_cited = c(getOption("works_cited"), entry))
-
- ## And format the inline citation
- n <- length(entry$author)
- if(n==1)
- sprintf("(%s, %s)", entry$author[[1]]$family, entry$year)
- if(n==2)
- sprintf("(%s & %s, %s)", entry$author[[1]]$family, entry$author[[2]]$family, entry$year)
- else if(n>2)
- sprintf("(%s _et. al._ %s)", entry$author[[1]]$family, entry$year)
- })
-}
-end.rcode-->
-Note that the function can take a list of objects (though I'll have to clean up their formatting), and it can take either dois or the biblio list from above. It would be easy to write the textual citation formatting and number formatting too. I may add these to a simple R package for that purpose.
-
-Now we can gereate inline citations like this <!--rinline pcite("10.1111/j.1461-0248.2005.00827.x")-->. Hmm, looks like we need a way for `rinline` code to use `asis` formatting though.
-
-## Bibliography
-Then at the end of the document, use this command to print the bibliography generated by the use of our inline citations.
-<!--begin.rcode results="asis"
-getOption("works_cited")
-end.rcode-->
-
-
-Like many others on this list, I finding myself more and more drawn to markdown rather then tex/Rnw as my standard format (not least of which is the ease of displaying the files on github, particularly now that we have automatic image uploading). One thing I miss from latex is the citation commands.
-
-I've taken a little whack at generating parenthetical citations
-
-
Oops, something went wrong.

0 comments on commit 29ab323

Please sign in to comment.