npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

codex-bilingual-reader-for-zotero

v1.6.0

Published

Create preserved-layout English-Chinese PDFs in Zotero with Codex CLI or OpenAI-compatible APIs.

Readme

Codex Bilingual Reader GitHub preview

中文

Codex Bilingual Reader 是一个适用于 Zotero 8/9/10 的 MIT 开源插件。它可通过本地已登录的 Codex CLI,或 OpenAI、DeepSeek 等 OpenAI 兼容 API,将 PDF 附件转换为保留原排版的中英对照 PDF。生成结果会作为独立的 Zotero 子附件自动导入,原始 PDF 始终不会被修改。

本项目源自 Mengqi97/codex-bilingual-reader-for-zotero(MIT 许可)。上游已停止更新,当前由 fangchenghao 维护,重点是维持对新版 Zotero 的兼容(本版适配 Zotero 10.0.x)。

核心功能

  • 保排版中英对照 PDF:保留图片、公式、表格、可选择文字和页面几何结构,并将英文与中文并列排版。
  • Codex 与多种 API 后端:支持本地 Codex CLI、OpenAI、DeepSeek 及其他 OpenAI 兼容接口。
  • 单篇与批量翻译:支持翻译单篇论文或批量加入队列,并显示运行、等待、取消和断点续传状态。
  • 原生 Zotero 操作入口:可从工具菜单、条目右键菜单或右侧面板启动;完成后自动导入双语 PDF。
  • 任务与费用统计:集中查看页数/片段进度、运行时间、实际 API Token 用量、可配置价格及失败信息。
  • 双语 PDF 设置:可选择译文位于左侧或右侧、默认打开原文或双语附件、预览输出,并可单独调整中缝宽度而无需重新翻译。

效果展示

ActPlan-1K 保排版中英对照 PDF

上图中英文位于左侧,可选择的中文译文位于右侧;图片、公式、表格和页面结构均得到保留。

安装

  1. 从最新 GitHub Release下载 codex-bilingual-reader.xpi。
  2. 在 Zotero 中打开工具 → 扩展和主题(Zotero 9 及更早版本叫附加组件),点击右上角齿轮,选择从文件安装附加组件…,然后选择下载的 XPI。
  3. 打开工具 → Codex 中英对照设置…,点击一键安装/修复 PDF 翻译环境。Windows 会下载并解压约 600 MB 的官方便携引擎;macOS/Linux 会在插件运行目录中创建 Python 虚拟环境并安装 pdf2zh_next / BabelDOC(约 900 MB)。两种方式通常都需要几分钟。
  4. 选择本地 Codex CLI 或 OpenAI 兼容 API,配置模型和凭据,并在翻译前点击测试连接。

也可以用 npm pack codex-bilingual-reader-for-zotero 下载发布包。解压生成的 .tgz,在第 2 步选择其中的 package/build/codex-bilingual-reader.xpi。

保排版 PDF 配置

打开设置后可以看到 PDF 环境是否就绪。点击安装按钮会显示下载、安装和校验阶段。预检成功后插件才保存路径。已有环境可以展开高级设置 · 查看或更改路径,选择工作目录或手动填写。升级插件后,托管目录中的启动脚本会自动更新,已有引擎可以继续使用。

平台支持:

  • Windows:一键安装下载官方便携包并执行 SHA-256 校验;若系统没有 Node.js,会一并安装官方便携版本。
  • macOS / Linux:一键安装在 codex-bilingual-runtime/.venv 中创建虚拟环境,优先复用 Node.js 20+、Python 3.10–3.13 和已有的 uv。在支持的 x64 / arm64 macOS 和 glibc Linux 上,缺少工具时会校验并下载 Node.js 或 uv 到插件运行目录,再按需准备 Python 3.12。首次运行 BabelDOC 还会从镜像下载约 340 MB 的版面模型与字体到 ~/.cache/babeldoc。

PDFMathTranslate-next/BabelDOC 使用 AGPL 许可证,因此它由用户主动下载并作为独立外部引擎运行,MIT 插件不会捆绑或链接其代码。关于调用协议、隐私边界、许可证边界和验收标准,请参阅保排版 PDF 工作流。

使用入口与设置

选中论文后,可从以下任一入口启动翻译:

  • 工具 → 使用 Codex 生成全文中英对照
  • 论文条目的右键菜单
  • Zotero 右侧条目面板中的 Codex 中英对照 区域

可通过编辑 → 设置 → Codex 中英对照、工具 → Codex 中英对照设置…,或右侧面板的翻译设置按钮打开配置页面。

  • 保排版 PDF(默认):Codex CLI 使用本地登录和所选推理强度;API 模式支持 OpenAI、DeepSeek 等 Chat Completions 兼容服务。
  • 默认打开附件:可选择双击论文时优先打开双语 PDF,或保持 Zotero 默认打开原始 PDF 的行为。
  • 测试连接:验证保排版启动器,并通过所选后端翻译一个最小测试句,不会发送论文正文。

跨页句子的翻译

保排版模式使用 BabelDOC 识别的正文阅读顺序。对于引擎配对的跨页或跨栏段落,模型会看到前后片段的原文摘录,每个片段的译文按段落编号放回原位。分批、断点续传和单段重试都使用相同的上下文。升级后首次重译会重新请求旧版缓存中的片段。复杂版面中误识别的页眉、脚注或正文仍可能影响衔接。

典型处理时间

翻译速度取决于 PDF 排版复杂度、网络延迟、模型服务和并发限制。在 1.5.x 的 DeepSeek API 测试中,普通 8 页学术 PDF 约需 10 分钟。公式、表格、双栏排版较多或服务繁忙时可能更久;该数值是经验参考,不是性能保证。

安全与隐私

使用 Codex CLI 时,文本片段通过用户本地的 Codex 登录提交,插件不会读取或复制 Codex 凭据。使用 API 模式时,API Key 保存在本地 Zotero 首选项中,仅作为 Bearer 凭据发送到用户配置的 Base URL。无论使用哪种方式,论文文本都会发送给所选翻译服务商。

在 Windows 上,启动器通过标准输入将文档片段传给配置的 codex.cmd 或 codex.exe,不会把 PDF 文本拼接到 Shell 命令中。

已知限制

  • 扫描型 PDF 不会由本插件执行 OCR,请先在 Zotero 或其他工具中完成 OCR。
  • 保排版 PDF 需要单独安装 PDFMathTranslate-next,并具备可用的 Codex CLI 登录或 OpenAI 兼容 API 配置。
  • PDF 引擎需要 Python 3.10–3.13,由安装器负责查找或准备。未设置 HF_ENDPOINT 时会默认使用 https://hf-mirror.com 下载 BabelDOC 模型,若你的网络无法访问该镜像,请自行设置 HF_ENDPOINT。
  • 只有 API 服务返回标准 usage 对象时才能显示精确 Token 用量;Codex CLI 当前不提供权威 Token 统计。
  • Zotero 全文缓存没有稳定的“段落到 PDF 坐标”映射,因此当前版本无法从双语内容精确跳转回 PDF 中的对应位置。
  • Codex App Server 依赖有效的 ~/.codex/config.toml;若出现 TOML 解析错误,需要先修复提示的配置行。

开发

环境要求:Node.js 20+、Python 3.10+(npm test 中的 Python 用例需要)、Zotero 8+。以下命令在 Windows(Git Bash / PowerShell 均可)、macOS 和 Linux 上一致。

npm ci          # 安装固定依赖
npm run check   # 语法与清单校验
npm test        # Node 测试 + Python 批量翻译器测试
npm run build   # 产出分发包

构建产物位于 build/codex-bilingual-reader.xpi。

只验证保排版启动器、不翻译正文:

node scripts/translate-preserved-pdf-cli.mjs --check

若本机还没有 PDF 引擎,可先准备运行时再重跑上面的预检:macOS/Linux 用 bash scripts/install-preserved-pdf-runtime.sh --runtime-root "$PWD/.runtime/pdf2zh",Windows 用 scripts/install-preserved-pdf-runtime.ps1。

致谢与参考项目

本项目在插件架构、交互设计、PDF 保排版流程和兼容接口方面参考或使用了以下优秀开源项目:

感谢这些项目及其贡献者。PDFMathTranslate-next/BabelDOC 作为独立外部 AGPL 引擎运行;所有相关项目仍分别遵循各自的许可证。


English

Codex Bilingual Reader is an MIT-licensed plugin for Zotero 8/9/10. It converts PDF attachments into preserved-layout English/Chinese PDFs using either the locally authenticated Codex CLI or an OpenAI-compatible API such as OpenAI or DeepSeek. The generated PDF is imported automatically as a separate Zotero child attachment, and the original PDF is never modified.

Derived from Mengqi97/codex-bilingual-reader-for-zotero (MIT). The upstream project is no longer maintained; this fork is maintained by fangchenghao with a focus on staying compatible with newer Zotero releases (this version targets Zotero 10.0.x).

Core features

  • Preserved-layout bilingual PDF — retains figures, formulas, tables, selectable text, and page geometry while placing English and Chinese side by side.
  • Codex and multiple API backends — supports the local Codex CLI, OpenAI, DeepSeek, and other OpenAI-compatible endpoints.
  • Single and batch translation — translates one paper or queues multiple selected papers with running, waiting, cancellation, and resumable checkpoint states.
  • Native Zotero entry points — starts from the Tools menu, item context menu, or right-hand pane and automatically imports completed PDFs.
  • Task and cost tracking — displays page/fragment progress, elapsed time, actual API token usage, configurable pricing, and failures in one task center.
  • Bilingual PDF controls — selects the translation side, preferred attachment on open, output preview, and center-gap adjustment without retranslating.

Preview

ActPlan-1K preserved-layout English-Chinese PDF

English is preserved on the left and the translated, selectable Chinese page is placed on the right while figures, formulas, tables, and page geometry remain intact.

Installation

  1. Download codex-bilingual-reader.xpi from the latest GitHub Release.
  2. In Zotero, open Tools → Add-ons and Themes (named Add-ons in Zotero 9 and earlier), click the gear icon, choose Install Add-on From File…, and select the downloaded XPI.
  3. Open Tools → Codex 中英对照设置… and click 一键安装/修复 PDF 翻译环境. On Windows this downloads and extracts the official portable engine (about 600 MB); on macOS/Linux it creates a Python virtual environment in the add-on runtime directory and installs pdf2zh_next / BabelDOC (about 900 MB). Either path normally takes a few minutes.
  4. Select the locally authenticated Codex CLI or an OpenAI-compatible API, configure the model and credentials, and run Test connection before translating a paper.

To download the release through npm, run npm pack codex-bilingual-reader-for-zotero. Extract the resulting .tgz and select package/build/codex-bilingual-reader.xpi in step 2.

Preserved-layout PDF setup

Settings checks the local runtime and shows each installation stage. Paths are saved after preflight succeeds. Expand 高级设置 · 查看或更改路径 to select an existing workspace or edit paths. Updating the XPI refreshes the managed launcher scripts on the next use.

Platform support:

  • Windows: one-click setup downloads the official portable bundle and verifies it with SHA-256; a portable Node.js is installed as well when none is present.
  • macOS / Linux: one-click setup creates a virtual environment at codex-bilingual-runtime/.venv and reuses available Node.js 20+, Python 3.10–3.13, and uv installations. On x64 / arm64 macOS and glibc Linux, the installer can download checksum-verified Node.js and uv into the runtime and provision Python 3.12 as needed. The first run also downloads about 340 MB of BabelDOC layout models and fonts into ~/.cache/babeldoc.

PDFMathTranslate-next/BabelDOC is downloaded on explicit user action and runs as a separate external AGPL engine; it is not bundled or linked into the MIT plugin. See the preserved PDF workflow for provider contracts, privacy boundaries, license boundaries, and acceptance gates.

Entry points and settings

With a paper selected, start translation from any of these entries:

  • Tools → 使用 Codex 生成全文中英对照
  • The paper item's context menu
  • The Codex 中英对照 section in Zotero's right-hand item pane

Open settings through Edit → Settings → Codex 中英对照, Tools → Codex 中英对照设置…, or the 翻译设置 button in the right-hand pane.

  • Preserved PDF (default) — Codex CLI uses the local login and selected reasoning level; API mode supports OpenAI, DeepSeek, and other Chat Completions-compatible providers.
  • Default open attachment — chooses whether double-clicking a paper prefers its bilingual PDF or retains Zotero's original-PDF behavior.
  • Test connection — validates the preserved-PDF launcher and translates one minimal test sentence through the selected backend without sending a document.

Sentences spanning pages

When BabelDOC identifies adjacent body paragraphs across a page or column break, each translation receives short excerpts from its neighbors. The broker preserves that context across batches and retries and maps each translation to its original paragraph ID. The first translation after upgrading requests fresh translations for fragments cached by older versions. Reading order depends on the layout engine correctly identifying body text.

Typical processing time

Translation time depends on PDF layout complexity, network latency, model availability, and provider rate limits. In a 1.5.x test, an eight-page academic PDF took about ten minutes with the DeepSeek API. Formula-heavy, table-heavy, multi-column documents or provider congestion may take longer; this is an observed estimate, not a performance guarantee.

Security and privacy

With Codex CLI, source fragments are submitted through the user's local Codex login, and the plugin never reads or copies Codex credentials. With API mode, the API key remains in the local Zotero preference profile and is sent only as a Bearer credential to the configured Base URL. In either mode, document text is sent to the selected translation provider.

On Windows, the launcher sends document fragments through stdin to the configured codex.cmd or codex.exe; it never interpolates PDF text into a shell command.

Known limitations

  • Scanned PDFs are not OCRed by this plugin. Run OCR in Zotero or another tool first.
  • Preserved PDF output requires a separately installed PDFMathTranslate-next engine and either a valid Codex CLI login or a working OpenAI-compatible API configuration.
  • The runtime needs Python 3.10–3.13. Setup finds or provisions a compatible interpreter. When HF_ENDPOINT is unset the launcher defaults to https://hf-mirror.com for BabelDOC model downloads; override it if that mirror is unreachable from your network.
  • Exact token usage is displayed only when an API provider returns a standard usage object. Codex CLI tasks do not currently expose authoritative token counts.
  • Zotero's full-text cache does not retain a robust paragraph-to-PDF coordinate map, so the current version cannot jump from bilingual content to the exact corresponding PDF location.
  • The Codex App Server requires a valid ~/.codex/config.toml. Fix the reported configuration line before retrying if a TOML parse error occurs.

Development

Requirements: Node.js 20+, Python 3.10+ (needed by the Python cases in npm test), and Zotero 8+. The commands below are identical on Windows (Git Bash or PowerShell), macOS, and Linux.

npm ci          # install pinned dependencies
npm run check   # syntax and manifest checks
npm test        # Node tests + Python batch-translator tests
npm run build   # produce the distributable

The distributable is build/codex-bilingual-reader.xpi.

To validate the preserved-layout launcher without translating any content:

node scripts/translate-preserved-pdf-cli.mjs --check

If the machine has no PDF engine yet, provision the runtime first and rerun the preflight: bash scripts/install-preserved-pdf-runtime.sh --runtime-root "$PWD/.runtime/pdf2zh" on macOS/Linux, or scripts/install-preserved-pdf-runtime.ps1 on Windows.

Acknowledgements and references

This project references or builds on the ideas, plugin interactions, preserved-layout workflow, and compatible interfaces of these excellent open-source projects:

Many thanks to their maintainers and contributors. PDFMathTranslate-next/BabelDOC remains a separately installed external AGPL engine, and every referenced project continues to be governed by its own license.