> ## Documentation Index
> Fetch the complete documentation index at: https://nvd-54.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# MathpixPDFLoader 集成

> 使用 LangChain Python 集成 MathpixPDFLoader 文档加载器。

Inspired by Daniel Gross's snippet here: [https://gist.github.com/danielgross/3ab4104e14faccc12b49200843adab21](https://gist.github.com/danielgross/3ab4104e14faccc12b49200843adab21)

## 概述

### 集成详情

| Class                                                                                                                  | Package                                                                             | Local | Serializable | JS support |
| :--------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------- | :---: | :----------: | :--------: |
| [`MathPixPDFLoader`](https://reference.langchain.com/python/langchain-community/document_loaders/pdf/MathpixPDFLoader) | [`langchain-community`](https://reference.langchain.com/python/langchain-community) |   ✅   |       ❌      |      ❌     |

### 加载器特性

|       Source       | Document Lazy Loading | Native Async Support |
| :----------------: | :-------------------: | :------------------: |
| `MathPixPDFLoader` |           ✅           |           ❌          |

## 设置

### 凭证

Sign up for Mathpix and [create an API key](https://mathpix.com/docs/ocr/creating-an-api-key) to set the `MATHPIX_API_KEY` variables in your environment

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import getpass
import os

if "MATHPIX_API_KEY" not in os.environ:
    os.environ["MATHPIX_API_KEY"] = getpass.getpass("Enter your Mathpix API key: ")
```

要启用模型调用的自动追踪，请设置你的 [LangSmith](/langsmith/home) API 密钥：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
os.environ["LANGSMITH_TRACING"] = "true"
```

### 安装

安装 **langchain-community**。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install -qU langchain-community
```

## 初始化

Now we are ready to initialize our loader:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_community.document_loaders import MathpixPDFLoader

file_path = "./example_data/layout-parser-paper.pdf"
loader = MathpixPDFLoader(file_path)
```

## 加载

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
docs = loader.load()
docs[0]
```

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
print(docs[0].metadata)
```

## 惰性加载

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
page = []
for doc in loader.lazy_load():
    page.append(doc)
    if len(page) >= 10:
        # do some paged operation, e.g.
        # index.upsert(page)

        page = []
```

***

## API 参考

For detailed documentation of all `MathpixPDFLoader` features and configurations head to the [API reference](https://reference.langchain.com/python/langchain-community/document_loaders/pdf/MathpixPDFLoader)

***

<div className="source-links">
  <Callout icon="terminal-2">
    [通过 MCP 将这些文档连接到](/use-these-docs) Claude、VSCode 等工具以获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/document_loaders/mathpix.mdx) 或 [提交 issue](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
