困难

不止deepseek,要让任意大模型处理没经处理过的题目,难如登天。

  1. 公式难处理
  2. 图片难处理

详细分析

目前已知的大模型,输入输出都对markdown和latex做得比较好,而不太支持word等其他东西。
本文集中研究公式的识别

尝试1

都说了是尝试,代码仅供阅读,别跑

本地
本地
word
latex
markdown

deepseek 开问!

# extract_images.py
from docx import Document
import os

def extract_images_from_word(docx_path, output_dir):
    """
    从 Word 文档中提取所有图片并保存到指定目录
    :param docx_path: Word 文档路径
    :param output_dir: 图片保存目录
    :return: 提取的图片路径列表
    """
    doc = Document(docx_path)
    os.makedirs(output_dir, exist_ok=True)
    image_paths = []

    # 遍历文档中的所有关系(图片、图表等)
    for idx, rel in enumerate(doc.part.rels.values()):
        if "image" in rel.target_ref:  # 确认是图片
            img_data = rel.target_part.blob
            img_ext = rel.target_part.content_type.split("/")[-1]  # 获取图片格式(png/jpeg等)
            img_name = f"formula_{idx+1}.{img_ext}"
            img_path = os.path.join(output_dir, img_name)
            
            with open(img_path, "wb") as f:
                f.write(img_data)
            image_paths.append(img_path)
            print(f"已保存图片: {img_path}")

    return image_paths

if __name__ == "__main__":
    docx_file = "your_document.docx"  # 替换为你的 Word 文件路径
    image_folder = "formula_images"   # 图片保存目录
    extracted_images = extract_images_from_word(docx_file, image_folder)
    print(f"共提取 {len(extracted_images)} 张图片")

# ocr_to_latex.py
from PIL import Image
from pix2tex import cli as latexocr
import os

def batch_ocr_formulas(image_dir, output_md):
    """
    使用 LaTeX-OCR 批量识别公式
    """
    model = latexocr.LatexOCR()  # 初始化模型(首次运行会自动下载预训练权重)
    formulas = []

    # 按文件名排序处理图片
    image_files = sorted(
        [f for f in os.listdir(image_dir) if f.lower().endswith(('png', 'jpg', 'jpeg'))],
        key=lambda x: int(x.split('_')[1].split('.')[0])
    )

    for img_file in image_files:
        img_path = os.path.join(image_dir, img_file)
        try:
            img = Image.open(img_path)
            latex_code = model(img)  # 直接返回 LaTeX 代码
            formulas.append(f"$${latex_code}$$\n\n")
            print(f"识别成功: {img_file} -> {latex_code}")
        except Exception as e:
            formulas.append(f"![识别失败]({img_file})\n\n")
            print(f"识别失败: {img_file} - {str(e)}")

    # 写入 Markdown 文件
    with open(output_md, "w", encoding="utf-8") as f:
        f.write("# 公式文档\n\n")
        f.writelines(formulas)
    print(f"Markdown 文件已生成: {output_md}")

if __name__ == "__main__":
    image_folder = "formula_images"
    output_file = "output_formulas.md"
    batch_ocr_formulas(image_folder, output_file)

困难如下

  1. 解析出来公式的是x-wmf格式(基于实际docx里存的是什么,有几张png)
  2. x-wmf格式pix2tex根本不认识,识别个啥。
  3. 模型不好下,代码自动下载不知何时,挂BitComet,十分钟后下好了。放到命令行显示的那个位置

尝试2

问题十分明确,把x-wmf转换成png

# extract_images.py(更新版)
from docx import Document
import os
from wand.image import Image as WandImage
from wand.color import Color

def convert_wmf_to_png(wmf_path, png_path):
    """ 将 WMF 文件转换为 PNG """
    with WandImage(filename=wmf_path, format="wmf") as img:
        img.format = "png"
        img.background_color = Color("white")  # 设置背景为白色
        img.alpha_channel = 'remove'  # 移除透明通道
        img.save(filename=png_path)

def extract_images_from_word(docx_path, output_dir):
    doc = Document(docx_path)
    os.makedirs(output_dir, exist_ok=True)
    image_paths = []

    for idx, rel in enumerate(doc.part.rels.values()):
        if "image" in rel.target_ref:
            img_data = rel.target_part.blob
            img_ext = rel.target_part.content_type.split("/")[-1]
            img_name = f"formula_{idx+1}.{img_ext}"
            img_path = os.path.join(output_dir, img_name)
            
            with open(img_path, "wb") as f:
                f.write(img_data)
            
            # 如果是 WMF 文件,转换为 PNG
            if img_ext.lower() == "x-wmf" or img_name.endswith(".wmf"):
                png_path = os.path.join(output_dir, f"formula_{idx+1}.png")
                convert_wmf_to_png(img_path, png_path)
                image_paths.append(png_path)
                os.remove(img_path)  # 删除原始 WMF 文件
            else:
                image_paths.append(img_path)
    
    return image_paths



好,配置依赖比看上去难了几倍
wand基于ImageMagick,是个独立软件。一顿配置,依然出问题

成功的

我觉得这么一个大问题,市面上一定有对应方案
我找到了doc2x
doc2x
比预想中要成功
在这里插入图片描述

你看到结果就说明成功了

三角函数恒等变换

【题型一 两角和与差公式】

  1. cos ⁡ 47 ∘ cos ⁡ 137 ∘ + sin ⁡ 47 ∘ sin ⁡ 137 ∘ \cos {47}^{ \circ }\cos {137}^{ \circ } + \sin {47}^{ \circ }\sin {137}^{ \circ } cos47cos137+sin47sin137 的值等于( )

A. 0 B. 1 C. -1 D. 1 2 \frac{1}{2} 21

  1. 化简 sin ⁡ 60 ∘ cos ⁡ 15 ∘ − 2 sin ⁡ 2 15 ∘ sin ⁡ 75 ∘ = \sin {60}^{ \circ }\cos {15}^{ \circ } - 2{\sin }^{2}{15}^{ \circ }\sin {75}^{ \circ } = sin60cos152sin215sin75= _____.

  2. tan ⁡ 17 ∘ + tan ⁡ 28 ∘ + tan ⁡ 17 ∘ tan ⁡ 28 ∘ \tan {17}^{ \circ } + \tan {28}^{ \circ } + \tan {17}^{ \circ }\tan {28}^{ \circ } tan17+tan28+tan17tan28 等于( )

A. − 2 2 - \frac{\sqrt{2}}{2} 22 B. 2 2 \frac{\sqrt{2}}{2} 22 C. -1 D. 1

  1. (多选题) 已知 π 4 ≤ α ≤ π , π ≤ β ≤ 3 π 2 , sin ⁡ 2 α = 4 5 , cos ⁡ ( α + β ) = − 2 10 \frac{\pi }{4} \leq \alpha \leq \pi ,\pi \leq \beta \leq \frac{3\pi }{2},\sin {2\alpha } = \frac{4}{5},\cos \left( {\alpha + \beta }\right) = - \frac{\sqrt{2}}{10} 4παπ,πβ23π,sin2α=54,cos(α+β)=102 ,则( )

A. cos ⁡ α = − 10 10 \cos \alpha = - \frac{\sqrt{10}}{10} cosα=1010 B. sin ⁡ α − cos ⁡ α = 5 5 \sin \alpha - \cos \alpha = \frac{\sqrt{5}}{5} sinαcosα=55 C. β − α = 3 π 4 \beta - \alpha = \frac{3\pi }{4} βα=43π D. cos ⁡ α cos ⁡ β = − 2 5 \cos \alpha \cos \beta = - \frac{\sqrt{2}}{5} cosαcosβ=52

好,丢给deepseek

### 题型一 两角和与差公式

1. **答案:A. 0**  
   **解析**:利用余弦差公式:  
   \[
   \cos 47^\circ \cos 137^\circ + \sin 47^\circ \sin 137^\circ = \cos(47^\circ - 137^\circ) = \cos(-90^\circ) = \cos 90^\circ = 0
   \]

2. **答案:\(\frac{\sqrt{2}}{2}\)**  
   **解析**:化简步骤:  
   \[
   \sin 60^\circ \cos 15^\circ - 2\sin^2 15^\circ \sin 75^\circ = \cos 15^\circ \left( \frac{\sqrt{3}}{2} - 2\sin^2 15^\circ \right)
   \]
   利用二倍角公式 \(2\sin^2 15^\circ = 1 - \cos 30^\circ = 1 - \frac{\sqrt{3}}{2}\),得:
   \[
   \frac{\sqrt{3}}{2} - \left(1 - \frac{\sqrt{3}}{2}\right) = \sqrt{3} - 1
   \]
   最终结果为 \(\cos 15^\circ (\sqrt{3} - 1) = \frac{\sqrt{2}}{2}\)。

3. **答案:D. 1**  
   **解析**:利用正切和角公式:  
   \[
   \tan 17^\circ + \tan 28^\circ + \tan 17^\circ \tan 28^\circ = \tan(17^\circ + 28^\circ)(1 - \tan 17^\circ \tan 28^\circ) + \tan 17^\circ \tan 28^\circ = 1
   \]

4. **答案:B, C**  
   **解析**:  
   - **选项B**:\(\sin \alpha - \cos \alpha = \frac{\sqrt{5}}{5}\),计算正确。  
   - **选项C**:\(\beta - \alpha = \frac{3\pi}{4}\),验证满足\(\cos(\alpha + \beta) = -\frac{\sqrt{2}}{10}\)。

5. **答案:A**  
   **解析**:选项A为\(\cos(18^\circ + 42^\circ) = \cos 60^\circ = \frac{1}{2}\)。

6. **答案:\(\frac{2\sqrt{3}}{3}\)**  
   **解析**:利用正切和角公式及特殊角度性质,最终化简为\(\frac{2\sqrt{3}}{3}\)。

---

### 题型二 二倍角公式

1. **答案:A, C, D**  
   **解析**:  
   - **选项A**:\(\cos 150^\circ = -\frac{\sqrt{3}}{2}\),正确。  
   - **选项C**:\(\sin 75^\circ \cos 75^\circ = \frac{1}{2}\sin 150^\circ = \frac{1}{4}\),正确。  
   - **选项D**:\(\frac{1 - \tan 15^\circ}{1 + \tan 15^\circ} = \tan 30^\circ = \frac{\sqrt{3}}{3}\),正确。

2. **答案:\(-\frac{15}{17}\)**  
   **解析**:由\(\tan(\frac{9\pi}{4} - \alpha) = -\frac{3}{5}\) 得\(\tan \alpha = 4\),代入\(\cos 2\alpha = \frac{1 - \tan^2 \alpha}{1 + \tan^2 \alpha} = -\frac{15}{17}\)。

3. **答案:B. \(\frac{3}{5}\)**  
   **解析**:由\(\sin \alpha = -2\cos \alpha\) 得\(\cos 2\alpha = -\frac{3}{5}\),\(\sin 2\alpha = -\frac{4}{5}\),故\(\cos 2\alpha - \sin 2\alpha = \frac{3}{5}\)。

4. **答案:B. \(-\frac{23}{25}\)**  
   **解析**:利用角度变换,\(\cos(2\alpha - \frac{\pi}{3}) = -\cos(2\theta) = -\frac{23}{25}\)。

---

### 题型三 辅助角公式的应用

1. **(1) 答案:\(\pm \frac{\sqrt{2}}{2}\)**  
   **解析**:\(\sin \alpha + \cos \alpha = \sqrt{2}\sin(\alpha + \frac{\pi}{4}) = \frac{\sqrt{6}}{3}\),解得\(\tan(\alpha + \frac{\pi}{4}) = \pm \frac{\sqrt{2}}{2}\)。  
   **(2) 答案:\(-\frac{17}{25}\)**  
   **解析**:\(\cos(\frac{\pi}{6} - \alpha) = \frac{2}{5}\),利用角度变换得\(\sin(2\alpha + \frac{\pi}{6}) = -\frac{17}{25}\)。

2. **答案:A. \(\frac{\sqrt{3}}{2}\)**  
   **解析**:\(\frac{\sqrt{2}}{2}\cos 15^\circ + \frac{\sqrt{2}}{2}\sin 15^\circ = \sin 60^\circ = \frac{\sqrt{3}}{2}\)。

---

### 题型四 给值求值

1. **答案:C. \(-\frac{\sqrt{3}}{2}\)**  
   **解析**:\(\cos(\alpha + \frac{3\pi}{4}) = -\sin(\alpha + \frac{\pi}{4}) = -\frac{\sqrt{3}}{2}\)。

2. **答案:B. \(-\frac{3}{5}\)**  
   **解析**:\(\cos(\frac{4\pi}{3} - x) = -\cos(x - \frac{\pi}{3}) = -\frac{3}{5}\)。

3. **答案:A. \(-\frac{1}{3}\)**  
   **解析**:利用和角公式,解得\(\cos \beta = -\frac{1}{3}\)。

4. **答案:B. \(\frac{7}{8}\)**  
   **解析**:\(\cos(2x - \frac{\pi}{3}) = 1 - 2\sin^2(\frac{\pi}{6} - x) = \frac{7}{8}\)。

---

### 题型五 给值求角

1. **答案:\(\alpha = \frac{\pi}{3}\)**  
   **解析**:通过化简方程并验证角度范围得出。

2. **答案:\(\alpha + \beta = \frac{7\pi}{4}\)**  
   **解析**:结合角度范围及三角函数值求解。

3. **答案:C. \(-\frac{3\pi}{4}\)**  
   **解析**:利用正切差公式及角度范围确定。

---

### 题型六 恒等变换

1. **答案:B. \(\sqrt{2}\)**  
   **解析**:化简后分母为\(\sqrt{2}\sin 10^\circ\),分子为\(1 - \sqrt{3}\tan 10^\circ\),最终结果为\(\sqrt{2}\)。

2. **答案:\(\frac{1}{2}\)**  
   **解析**:利用和差公式化简,结果为\(\frac{1}{2}\)。

3. **答案:1**  
   **解析**:利用正切和角公式及特殊角度性质化简。

---

### 课后练习

1. **答案:A. \(-\frac{\sqrt{2}}{2}\)**  
2. **答案:C, D**  
3. **答案:B. -3**  
4. **答案:A. \(\frac{4}{3}\)**  
5. **答案:D. \(-\cos \alpha\)**  
6. **答案:B. \(\frac{12}{13}\)**  
7. **答案:C. \(\frac{\sqrt{6} - \sqrt{2}}{4}\)**  
8. **答案:A, B, C**  
9. **答案:①, ②, ③**  
10. **答案:\(-\frac{1}{5}\)**  
11. **答案:\(-\sqrt{2}\)**  
12. **答案:\(-\frac{1}{5}\)**  
13. **答案:\(\frac{1}{3}, \frac{\sqrt{2}}{4}\)**  
14. **答案:\(\frac{7\sqrt{2}}{10}\)**  
15. **(1) 答案:\(-\frac{56}{65}\)**  
   **(2) 答案:\(\sqrt{2} - 1\)**  
16. **(1) 答案:\(\left[\frac{\pi}{6} + k\pi, \frac{2\pi}{3} + k\pi\right]\)**  
   **(2) 答案:\(m < \sqrt{3}\)**

哦,对了,latex导出有两种格式,\[\]和$ 两种,csdn的编辑器只认后一种,deepseek说话默认前一种,看都看得懂。所以如你所见,前一半转译成功,后一半没有成功转译。
还有,doc2x要登录
会员价格便宜,不开会员也能基本满足使用
第二天:这个签到的人机验证怎么这么人机

Logo

欢迎加入DeepSeek 技术社区。在这里,你可以找到志同道合的朋友,共同探索AI技术的奥秘。

更多推荐