This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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', |