Skip to content

Instantly share code, notes, and snippets.

@DaniJVaz
DaniJVaz / strip_comments.py
Created October 10, 2016 14:41 — forked from amerberg/strip_comments.py
A script to remove comments from LaTeX source
import ply.lex, argparse, io
#Usage
# python stripcomments.py input.tex > output.tex
# python stripcomments.py input.tex -e encoding > output.tex
def strip_comments(source):
tokens = (
'PERCENT', 'BEGINCOMMENT', 'ENDCOMMENT', 'BACKSLASH',
'CHAR', 'BEGINVERBATIM', 'ENDVERBATIM', 'NEWLINE', 'ESCPCT',