latex 去掉所有高亮语句\hl

文章中有许多高亮的地方,希望去掉所有的\hl语句,从而取消高亮
方法如下:
1、创建文件doc.txt, 将latex里.的内容粘贴到里面
2、运行python代码
3、运行代码后自动生成newdoc.txt,粘贴里面的内容到latex文件即可

python代码如下:

import regex as re

with open('./doc.txt', 'r', encoding='utf-8') as f:
    lines = f.read()
    print(lines)

pos = re.search('hl{', lines)
while not pos is None:
    cnt = 0
    start = pos.regs[0][0]-1
    end = -1
    for i in range(start, len(lines)):
        if lines[i] == '{':
            cnt += 1
        if lines[i] == '}':
            if cnt == 1:
                end = i
                break
            else: cnt -= 1
    if end >= 0:
        lines = lines[:end] + lines[(end+1):]
        lines = lines[:start] + lines[(start+4):]
        pos = re.search('hl{', lines)
    else:
        raise Exception('error')

with open('newdoc.txt', 'w', encoding='utf-8') as f:
    f.write(lines)

print('ok')
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值