LaTeX2Md - LaTeX to Markdown 转换器
latex to md 初始化版本,针对复杂学术论文project,处理仍有问题欢迎贡献
LaTeX2Md 是一个强大的 Python 工具,可将 LaTeX 文档转换为 Markdown 格式,同时保留结构、格式、图片、表格、公式和引用。它特别适用于学术论文和复杂文档的转换。
特性
- 将 LaTeX 章节、小节和格式转换为 Markdown
- 处理图片,并将其复制到输出目录
- 将 LaTeX 表格转换为 Markdown 表格
- 使用 Markdown 数学语法保留数学公式
- 处理引用和参考文献
- 支持多列布局
- 处理包含多个文件的学术论文项目结构
- 保留文档结构和交叉引用
安装
pip install latex2md
使用方法
命令行使用
基本用法 - 转换单个 LaTeX 文件到 Markdown:
latex2md path/to/your/document.tex
Python 代码中使用
from latex2md import latex2md
# 创建转换器实例
converter = latex2md("input.tex", "output.md")
# 处理项目文件
converter.consolidate_project()
# 加载并转换文件
if converter.load_file():
converter.convert()
converter.save_file()
# 重要参数说明
# input_file: str - LaTeX 源文件路径
# output_file: str - 输出 Markdown 文件路径
# image_dir: str - 图片保存目录(默认为 'images')
# project_dir: str - LaTeX 项目根目录(可选)
# verbose: bool - 是否显示详细输出(默认 False)
# 带参数的完整示例
converter = latex2md(
input_file="path/to/your/document.tex",
output_file="custom_output.md",
image_dir="custom_images",
project_dir="project_root",
verbose=True
)
converter.consolidate_project()
if converter.load_file():
converter.convert()
converter.save_file()
命令行高级选项
latex2md path/to/your/document.tex -o custom_output.md -i custom_images_dir -p project_directory -v
选项:
-o, --output:指定输出 Markdown 文件路径-i, --image-dir:指定保存图片的目录(默认为 images)-p, --project-dir:指定 LaTeX 项目的根目录(用于处理多文件项目)-v, --verbose:显示详细输出信息
转换学术论文项目
对于包含多个文件的学术论文项目:
latex2md path/to/main.tex -p path/to/project_directory
输出结构
- 对于单个文件转换:创建 filename_md 文件夹,包含 Markdown 文件和 images 子文件夹
- 对于项目转换:创建 project_name_md 文件夹,包含转换后的内容和 images 子文件夹
中文支持
LaTeX2Md 完全支持中文内容的转换。对于包含中文的 LaTeX 文档,转换后的 Markdown 将正确保留所有中文字符。
常见问题
图片转换问题
如果 LaTeX 文档中包含 PDF 图片,LaTeX2Md 会尝试将其复制为 PNG 文件。对于更好的转换效果,建议使用图像处理工具(如 pymupdf)将 PDF 转换为 PNG。
复杂数学公式
对于非常复杂的数学公式,可能需要在转换后手动调整。LaTeX2Md 使用 Markdown 的数学语法(通常是 MathJax 或 KaTeX 兼容的语法)来表示公式。
表格处理
复杂的 LaTeX 表格(如合并单元格或特殊格式)可能需要在转换后手动调整。
贡献
欢迎贡献!请随时提交问题报告或拉取请求。
许可证
本项目采用 MIT 许可证。详见 LICENSE 文件。
希望这个工具能帮助您轻松将 LaTeX 文档转换为 Markdown 格式!如有任何问题或建议,请通过 GitHub Issues 联系我们。
Metadata
Release files for latex2md 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| latex2md-0.1.1.tar.gz | 18.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| latex2md-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.2 kB
Release files / latex2md-0.1.1.tar.gz
| Download URL | latex2md-0.1.1.tar.gz |
|---|---|
| Size | 18.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2ee8a2cd830affae6d225f781bdced0d79ecb8e0099968668eec2a3725be3282
|
|
BLAKE2b-256 checksum How to use checksums |
c5ca611aba6e9864af3de3502178d434f5db36e4cbe436a5a08c0186c1445f44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.0
|
Release files / latex2md-0.1.1-py3-none-any.whl
| Download URL | latex2md-0.1.1-py3-none-any.whl |
|---|---|
| Size | 17.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ed92164a4fbe18e58c748d29f9b0dce28fbcfdc8ca3ae619d6956bfe5a03a0a7
|
|
BLAKE2b-256 checksum How to use checksums |
c730e3c2bc7092876d2613d4f54b44ab039cf1e606c93e896d62bc9bb12a89db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.0
|
Security for latex2md 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.