MD格式中 \[ 符号 改成 $$

两种方式:

1. 打包exe文件

对应文件夹 cmd调出命令行执行

pyinstaller --onefile script.py

PS1: 安装pyinstaller
如果提示没有pyinstaller 先安装pyinstaller


pip install pyinstaller

ps2:卸载 pathlib
如果提示pathlib过时,卸载这个

conda remove pathlib

或者

pip uninstall pathlib

2. bat 文件执行

bat 格式名称随意

@echo off
start /b    python    GS.py

exit


python程序名称为GS,要和bat中的 运行的py文件名称一致


import os
import re

# 定义替换函数
def replace_latex_delimiters(content):
    # 替换 \( \) 为 $$ $$
    content = re.sub(r'\\\((.*?)\\\)', r'$\1$', content)
    # 替换 \[ \] 为 $$ $$
    content = re.sub(r'\\\[', r'$$', content)
    content = re.sub(r'\\\]', r'$$', content)

    return content



# 遍历当前文件夹中的所有 .md 文件
for filename in os.listdir('.'):
    if filename.endswith('.md'):
        with open(filename, 'r', encoding='utf-8') as file:
            content = file.read()
        
        # 替换 LaTeX 分隔符
        new_content = replace_latex_delimiters(content)
        
        # 写回文件
        with open(filename, 'w', encoding='utf-8') as file:
            file.write(new_content)

        print(f'Processed {filename}')



posted @ 2025-01-29 12:46  redufa  阅读(31)  评论(0)    收藏  举报