Created
May 13, 2025 00:10
-
-
Save yspkm/1288496caadfa597817bad1880cf903a to your computer and use it in GitHub Desktop.
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 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