Created
August 16, 2012 18:36
-
-
Save bblum/3372486 to your computer and use it in GitHub Desktop.
Turns raw rust code into syntax hilighted latex.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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