Skip to content

Instantly share code, notes, and snippets.

@bblum
Created August 16, 2012 18:36
Show Gist options
  • Save bblum/3372486 to your computer and use it in GitHub Desktop.
Save bblum/3372486 to your computer and use it in GitHub Desktop.
Turns raw rust code into syntax hilighted latex.
#!/bin/bash
# Use with extreme caution.
# You will probably need to \definecolor several of these.
IFS='\n'
while read line; do
echo -n "\\texttt{"
echo -n "$line" | sed 's/{/\\{/g' | sed 's/}/\\}/g' | sed 's/_/\\_/g' | sed 's/~/\\textasciitilde/g' | sed 's/ /~/g' | sed 's/^\t*//' | sed 's/%/\\%/g' | sed 's/&/\\\&/g' | \
sed 's/\<fn\>/\\hilight{brown}{fn}/g' | \
sed 's/\<do\>/\\hilight{brown}{do}/g' | \
sed 's/\<for\>/\\hilight{brown}{for}/g' | \
sed 's/\<let\>/\\hilight{brown}{let}/g' | \
sed 's/\<mut\>/\\hilight{brown}{mut}/g' | \
sed 's/\<if\>/\\hilight{brown}{if}/g' | \
sed 's/\(\/\/.*\)/\\hilight{darkcyan}{\1}/g' | \
sed 's/\<assert\>/\\hilight{red}{assert}/g' | \
sed 's/\<main\>/\\hilight{olivegreen}{main}/g' | \
sed 's/\<5\>/\\hilight{brickred}{5}/g' | \
sed 's/\(".*"\)/\\hilight{brickred}{\1}/g' | \
sed 's/\(\<\w*\>\)::/\\hilight{violet}{\1}::/g' | \
sed 's/::/\\hilight{grey}{::}/g' | \
sed 's/\(\w*!\)/\\hilight{blue}{\1}/g' | \
cat
echo "} \\\\"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment