Copy text from a latex file without comments newlines or comments

Alec Jacobson

January 20, 2014

weblog/

Here's a bash one-liner to copy the raw text from a LaTeX file. It strips comments (be careful if you use % in your text), removes newline, thins whitespace and finally pipes to the keyboard.

cat abstract.tex | sed -e "s/%.*$//" | tr '\n' ' ' | sed -e "s/  */ /g" | sed -e "s/^ //g" | pbcopy

If you're issuing this from vim then you need to escape the % sign:

    cat abstract.tex | sed -e "s/\%.*$//" | tr '\n' ' ' | sed -e "s/  */ /g" | sed -e "s/^ //g" | pbcopy