Skip to content

Instantly share code, notes, and snippets.

@ns6251
Created September 3, 2021 14:29
Show Gist options
  • Save ns6251/e2ae73b9248213fe3b586739e27c176c to your computer and use it in GitHub Desktop.
Save ns6251/e2ae73b9248213fe3b586739e27c176c to your computer and use it in GitHub Desktop.
platexに丸数字を埋め込むラッパマクロを生成するスクリプト
from __future__ import annotations
from typing import Iterable, Iterator
MACRO_NAME = "marunum"
MACRO_TEMPLATE = """\\newcommand{{\\{}}}[1]{{%
\\ifcase#1%
{}%
\\fi%
}}
"""
def marunum_unicodes() -> Iterator[int]:
yield ord('⓪')
for c in range(ord('①'), ord('⑳')+1):
yield c
for c in range(ord('㉑'), ord('㉟')+1):
yield c
for c in range(ord('㊱'), ord('㊿')+1):
yield c
def utf_macro(code_point: int) -> str:
return f"\\UTF{{{code_point:04X}}}"
def wrapped(it: Iterable[str], size: int) -> Iterator[str]:
for cnt, s in enumerate(it, 1):
if cnt % size == 0:
yield s + "%\n"
else:
yield s
if __name__ == "__main__":
utf_macros = map(utf_macro, marunum_unicodes())
inner = "\\or".join(wrapped(utf_macros, 6))
print(MACRO_TEMPLATE.format(MACRO_NAME, inner))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment