Created
February 22, 2017 22:41
-
-
Save caugner/d2b4b6263306e989364604472470b835 to your computer and use it in GitHub Desktop.
Visualise bracket depth of a LaTeX document.
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
| # Usage: | |
| # $ cat file.tex | ruby latex-bracket-depth.rb | |
| # $ echo "\textbf{ \textit{foobar} }" | ruby latex-bracket-depth.rb | |
| # \textbf{1\111111{222222}1} | |
| content = STDIN.read | |
| len = content.size | |
| level = 0 | |
| i = 0 | |
| esc = false | |
| while i < len | |
| c = content[i] | |
| if esc | |
| esc = false | |
| elsif c == '{' | |
| level += 1 | |
| elsif c == '}' | |
| level -= 1 | |
| elsif c == '\\' | |
| esc = true | |
| end | |
| if level != 0 and not c =~ /[{}\\]/ | |
| print level | |
| else | |
| print c | |
| end | |
| i += 1 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment