Download scripts/_dbg_fn.py from m-rui001/physics-typst-corpus: direct link, hf CLI and curl.
- Browser
- Download file 887 Bytes
-
https://huggingface.co/datasets/m-rui001/physics-typst-corpus/resolve/main/scripts/_dbg_fn.py
- Command line
-
hf download hf://datasets/m-rui001/physics-typst-corpus/scripts/_dbg_fn.py
-
curl -L -o _dbg_fn.py https://huggingface.co/datasets/m-rui001/physics-typst-corpus/resolve/main/scripts/_dbg_fn.py
887 Bytes
| import re, sys | |
| sys.path.insert(0, 'scripts') | |
| def _balanced(s, i): | |
| depth, j = 0, i | |
| while j < len(s): | |
| ch = s[j] | |
| if ch == "\\": | |
| j += 2 | |
| continue | |
| if ch == "{": | |
| depth += 1 | |
| elif ch == "}": | |
| depth -= 1 | |
| if depth == 0: | |
| return s[i + 1:j], j + 1 | |
| j += 1 | |
| return None, i | |
| def footnote_numbers(text): | |
| nums = {} | |
| for i, m in enumerate(re.finditer(r"\\footnote\s*\{", text)): | |
| inner, _ = _balanced(text, m.end() - 1) | |
| if not inner: | |
| continue | |
| lm = re.search(r"\\label\{([^}]*)\}", inner) | |
| if lm: | |
| nums[lm.group(1)] = i + 1 | |
| return nums | |
| t = open('papers/2209.06202/src/main.tex', encoding='utf-8', errors='replace').read() | |
| print(footnote_numbers(t)) | |
| print('footnote count', len(re.findall(r'\\footnote\s*\{', t))) | |