Skip to content

Instantly share code, notes, and snippets.

@Kai-Gao
Kai-Gao / strip_comments.py
Created September 12, 2016 20:59 — forked from dzhuang/strip_comments.py
A script to remove comments from LaTeX source
import ply.lex, argparse, io
# modified from https://gist.github.com/amerberg/a273ca1e579ab573b499
#Usage
# python stripcomments.py input.tex > output.tex
# python stripcomments.py input.tex -e encoding > output.tex
# Modification:
# 1. Preserve "\n" at the end of line comment
@Kai-Gao
Kai-Gao / strip_comments.py
Created September 12, 2016 20:59 — 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',