Skip to content

Instantly share code, notes, and snippets.

@yspkm
Created May 13, 2025 00:10
Show Gist options
  • Save yspkm/1288496caadfa597817bad1880cf903a to your computer and use it in GitHub Desktop.
Save yspkm/1288496caadfa597817bad1880cf903a to your computer and use it in GitHub Desktop.
import re
def convert_latex(text):
# (1) 블록 수식: \[ ... \] → $$ ... $$
text = re.sub(r'\\\[(.*?)\\\]', r'$$\1$$', text, flags=re.DOTALL)
# (2) 인라인 수식: \( ... \) → $ ... $
#text = re.sub(r'\\\((.*?)\\\)', r'$\1$', text, flags=re.DOTALL)
text = re.sub(r'\\\(\s*(.*?)\s*\\\)', r'$\1$', text, flags=re.DOTALL)
return text
# 예시
latex_text = r"""
그리고 컨볼루션 정리(convolution theorem, 會線定理)를 사용하면, 투과파의 각 스펙트럼 \( A_t(\alpha/\lambda, \beta/\lambda) \)와 입사파의 각 스펙트럼 \( A_i(\alpha/\lambda, \beta/\lambda) \) 사이를 다음과 같이 연결할 수 있다.
\[
A_t \left( \frac{\alpha}{\lambda}, \frac{\beta}{\lambda} \right)
= \Bigl[
A_i \left( \frac{\alpha}{\lambda}, \frac{\beta}{\lambda} \right)
*
T \left( \frac{\alpha}{\lambda}, \frac{\beta}{\lambda} \right)
\Bigr],
\quad (3\text{-}75)
\]
"""
converted_text = convert_latex(latex_text)
print(converted_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment