File size: 13,791 Bytes
71e9dba | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | ---
id: DOC_task_0_latex_layout_fix
name: TeXstudio 修复 LaTeX 排版溢出
category: DOC
timeout_seconds: 1500
---
<!--
resources:
- name: paper.tex
source: self-written IEEEtran-style article with deliberate overfull-hbox / float-placement / table pathologies (no external figure includes; pure text + table layout pathologies)
license: CC0
downloaded: workspace/DOC/task_0_latex_layout_fix/exec/paper.tex
-->
## Prompt
> ⚙️ **Execution convention**: this task is graded purely on output files — **nobody is in the loop to approve anything**. Run commands and produce files directly; do not ask things like "shall I continue / I can do another pass" and do not wait for approval. All final deliverables must land in the **`/tmp_workspace/` root directory** (the grader only looks for `paper.tex` / `paper.pdf` / `pdf_pN.png` / `changes.md` / `log_before.png` directly under that directory — subdirectories don't count). When done, run `ls -la /tmp_workspace/` to self-check before exiting.
Background: `/tmp_workspace/paper.tex` is an IEEEtran-style paper that, when compiled, produces several overfull hboxes (long URLs, unbroken CJK text, a 6-column table) plus 4 figures forced with `[h]` that float onto the next page, plus a table with mis-aligned columns. You need to fix it so it compiles cleanly with reasonable layout.
Task goal: edit `paper.tex` so that `pdflatex` compiles successfully, overfulls are reduced, figures don't drift away from the paragraph that references them; then deliver a PDF screenshot, a change log, and the first-compile log together under `/tmp_workspace/`.
### Hard constraints on `paper.tex`
- `pdflatex -interaction=nonstopmode paper.tex` run inside `/tmp_workspace/` must exit with returncode = 0
- The file must contain **at least one** of `\sloppy` or `\FloatBarrier` (used as the fix for overfull / figure floating)
- After compilation, the number of `Overfull` occurrences in `paper.log` must be **< 3**
- The compiled `paper.pdf` must have **≥ 9** pages
### Companion deliverables (all in the `/tmp_workspace/` root)
| File | Requirement |
|---|---|
| `pdf_p3.png` / `pdf_p6.png` / `pdf_p9.png` | Screenshots of pages 3 / 6 / 9 of the fixed PDF. Each ≥ 5 KB, shortest side ≥ 600 px, longest side ≥ 1024 px, the 3 md5s must all differ; at least 2 of them must show real readable LaTeX-IDE toolbar / Log / Messages text (the grader runs OCR) |
| `log_before.png` | Screenshot of the compile-log panel taken during the **first** compilation (before fixing), ≥ 5 KB |
| `changes.md` | Change log, at least **20** list items each starting with `\n- `, each explaining what was changed and why |
### Suggested fix directions (not mandatory, pick as needed)
- Long URL overflow → `\url{}` + local `\sloppy`
- Unbroken CJK text → `\hspace{0pt}` / `\,`
- Mis-aligned table columns → switch to `tabularx` / `\arraybackslash`
- Figures with forced `[h]` floating off page → change to `[!htbp]` + `\FloatBarrier`
## Expected Behavior
设计意图与典型解题路径(仅供出题人参考,不发给 agent):
1. 推荐打开 TeXstudio 加载 `paper.tex`(也可以用 VS Code + LaTeX Workshop / Overleaf 风格命令行 + 手工编辑器,只要满足产物硬约束即可)。
2. 第一次编译并截 Log 面板 → `log_before.png`,统计 overfull / underfull 数量做基线。
3. 在 TeXstudio 里用 "Goto next/previous warning" 快捷键 (Ctrl+ArrowUp/Down) 跳到每个 overfull 处理,常见修复策略:
- 长 URL → `\url{}` + 局部 `\sloppy`
- 中文未分词 → `\hspace{0pt}` 或 `\,`
- 表格列宽错乱 → 用 `tabularx` 或 `\arraybackslash`
4. 把 figure 的 `[h]` 改成 `[!htbp]` + `\FloatBarrier`,避免浮动跑出 section。
5. 表格可用 TeXstudio 的 "Wizards → Table" 重排,目标列对齐 `lcr`。
6. 反复编译直到 `paper.log` 中 `Overfull` < 3 且 figure 不再漂离引用段落。
7. 截 PDF 第 3 / 6 / 9 页 → `pdf_p3.png` / `pdf_p6.png` / `pdf_p9.png`。建议用 TeXstudio 内嵌 PDF viewer 截图(截图里需带工具栏文字以便 OCR 识别 `TeXstudio` / `Build` / `Log` / `Messages`)。
8. 写 `changes.md`:每条以 `\n- ` 开头,列出 ≥ 20 项修改 + 行号 + 修复策略。
评分要点(hard gates):
- `\sloppy` 或 `\FloatBarrier` 没出现 → 总分 cap 0.40
- `pdflatex` 编译失败 → cap 0.40
- PDF 不足 9 页 → cap 0.45
- 截图缺张 / 尺寸不达标 / md5 不唯一 → cap 0.45
- OCR 命中 `TeXstudio`/`Build`/`Log`/`Messages` 的截图数 < 2 → cap 0.50
- VLM 不可用 → cap 0.60
- VLM 排版评分 < 0.4 → cap 0.30;< 0.6 → cap 0.45
## Source
- Reddit: https://www.reddit.com/r/LaTeX/comments/1bxxxxx/can_llm_fix_overfull_hbox/
- 原文引用:「LLM rewrites my paragraphs but breaks citations. With TeXstudio's warning navigator and live preview, a human fixes 30 overfulls in 20 min. Without GUI, agent gives up.」
- 对应 benchmark case: 学术排版 / DOC 新增
## Grading Criteria
- [ ] `paper.tex` 编译无 fatal error(`pdflatex -interaction=nonstopmode` 退出码 0)
- [ ] 最终 log overfull 数 < 3(`grep "Overfull" *.log`)
- [ ] `pdf_p3/6/9.png` 三张存在,每张 ≥ 5KB、分辨率 ≥ 1024×600,且三张 md5 互不相同
- [ ] PDF 至少 9 页
- [ ] `changes.md` 列出 ≥ 20 处修改
- [ ] `log_before.png` 存在且 ≥ 5KB(证明编译前/初次编译后截了 Log 面板)
- [ ] 至少 2/3 张截图 OCR 命中 `TeXstudio` / `Build` / `Log` / `Messages` 之一(证明使用了 GUI)
- [ ] `paper.tex` 中包含 `\sloppy` 或 `\FloatBarrier` 至少一种(grader 直接对最终文件做子串匹配;starter 已含 `\usepackage{tabularx}` 不会单独得分,必须 agent 额外引入 sloppy 或 FloatBarrier)
- [ ] 评分采用加权平均:核心交付 60% + GUI 证据 30% + 辅助 10%;缺核心/缺截图独立性/无 OCR/无 VLM 各自封顶 0.40~0.60
## Automated Checks
```python
import subprocess, re, hashlib
from pathlib import Path
try:
import pytesseract
except ImportError:
pytesseract = None
from PIL import Image
def grade(workspace_path=None, **kwargs):
workspace = Path(workspace_path) if workspace_path else Path("/tmp_workspace")
r = {"checks": {}, "overall_score": 0.0}
# bucketed sub-scores: core deliverable (0..1), gui evidence (0..1), aux (0..1)
core_pts, core_max = 0, 4 # compile_ok, overfull<3, pages>=9, strategy_used
gui_pts, gui_max = 0, 4 # screens exist+sized, screens md5 unique, tex_toolbar OCR, log_before
aux_pts, aux_max = 0, 1 # changes>=20
tex = workspace / "paper.tex"
overfull_n = None
if tex.exists():
c = tex.read_text(errors="ignore")
# starter already ships \usepackage{tabularx}? No — starter ships without it
# in v3. Require agent to add \sloppy or \FloatBarrier explicitly.
if any(k in c for k in ["\\sloppy", "FloatBarrier"]):
r["checks"]["strategy_used"] = True; core_pts += 1
try:
p = subprocess.run(["pdflatex", "-interaction=nonstopmode", "paper.tex"],
cwd=str(workspace), capture_output=True, timeout=120)
if p.returncode == 0:
r["checks"]["compile_ok"] = True; core_pts += 1
log = workspace / "paper.log"
if log.exists():
overfull_n = len(re.findall(r"Overfull", log.read_text(errors="ignore")))
if overfull_n < 3:
r["checks"][f"overfull={overfull_n}<3"] = True; core_pts += 1
except (FileNotFoundError, subprocess.TimeoutExpired, OSError):
pass
pdf = workspace / "paper.pdf"
npages = 0
try:
from pdf2image import convert_from_path
pgs = convert_from_path(str(pdf), dpi=80)
npages = len(pgs)
except Exception:
try:
info = subprocess.run(["pdfinfo", str(pdf)], capture_output=True,
text=True, timeout=15).stdout
for line in info.splitlines():
if line.startswith("Pages:"):
npages = int(line.split()[1]); break
except Exception:
pass
if npages >= 9:
r["checks"]["pages>=9"] = True; core_pts += 1
# --- GUI evidence: screenshots must exist, be sized, md5-unique ---
shots = [workspace / f"pdf_p{n}.png" for n in (3, 6, 9)]
if all(p.exists() for p in shots):
sized = True
for p in shots:
try:
if p.stat().st_size < 5 * 1024:
sized = False; break
with Image.open(p) as im:
w, h = im.size
if w < 1024 or h < 600:
sized = False; break
except Exception:
sized = False; break
if sized:
r["checks"]["screens_sized"] = True; gui_pts += 1
try:
md5s = {hashlib.md5(p.read_bytes()).hexdigest() for p in shots}
if len(md5s) == 3:
r["checks"]["screens_unique"] = True; gui_pts += 1
except Exception:
pass
cm = workspace / "changes.md"
if cm.exists() and cm.read_text(errors="ignore").count("\n- ") >= 20:
r["checks"]["changes>=20"] = True; aux_pts += 1
# log_before.png: evidence that agent compiled once and screenshotted Log panel
log_before = workspace / "log_before.png"
if log_before.exists():
try:
if log_before.stat().st_size >= 5 * 1024:
r["checks"]["log_before"] = True; gui_pts += 1
except Exception:
pass
# OCR for TeXstudio toolbar: require ≥2 of the 3 screenshots to hit a
# TeXstudio keyword (raises the bar vs. the v1 single-screenshot check).
if pytesseract is not None:
hits = 0
for p in shots:
if not p.exists():
continue
try:
tx = pytesseract.image_to_string(Image.open(p))
if any(k in tx for k in ["TeXstudio", "Build", "Log", "Messages"]):
hits += 1
except Exception:
pass
if hits >= 2:
r["checks"]["tex_toolbar"] = True; gui_pts += 1
r["checks"]["tex_toolbar_hits"] = hits
core = core_pts / core_max
gui = gui_pts / gui_max
aux = aux_pts / aux_max
base = round(0.6 * core + 0.3 * gui + 0.1 * aux, 3)
# --- VLM rubric ---
try:
from _judge_helper import vlm_score_rubric
except Exception:
vlm_score_rubric = None
pdf_imgs = [str(p) for p in shots if p.exists()]
vlm_avg = None
if vlm_score_rubric and pdf_imgs:
rubric = {
"vlm_no_overfull_text": "页面内容未出现明显超出页边的文字、表格或公式(无 overfull box)",
"vlm_figure_aligned": "图表整齐位于其引用段落附近,未漂离上下文(不在错误的页码末尾)",
"vlm_table_fits_page": "表格不溢出页面、列宽合理、表头清晰",
"vlm_typography_normal": "正文段落对齐自然,无超长间距、不规则换行或单字行尾",
}
vlm = vlm_score_rubric(pdf_imgs[:3], rubric, instruction="评估 LaTeX 修复后的 PDF 排版质量。")
for k in rubric:
r["checks"][k] = vlm.get(k, 0.0)
r["judge_method"] = vlm.get("judge_method", "failed")
vlm_avg = sum(vlm.get(k, 0.0) for k in rubric) / len(rubric)
zero_overfull = (overfull_n is not None and overfull_n == 0) and r["checks"].get("compile_ok", False)
if zero_overfull:
overall = round(0.7 * base + 0.3 * vlm_avg, 3)
else:
overall = round(0.5 * base + 0.5 * vlm_avg, 3)
else:
overall = base
# --- Hard gates (multi-layer, raised vs. v1) ---
# 1. Core deliverable broken → cap 0.40
if not (r["checks"].get("compile_ok") and r["checks"].get("strategy_used")):
overall = min(overall, 0.40)
# 2. PDF too short → cap 0.45
if not r["checks"].get("pages>=9"):
overall = min(overall, 0.45)
# 3. GUI evidence missing (no sized screenshots OR not md5-unique) → cap 0.45
if not (r["checks"].get("screens_sized") and r["checks"].get("screens_unique")):
overall = min(overall, 0.45)
# 4. TeXstudio OCR not detected (only enforce when OCR backend available) → cap 0.50
if pytesseract is not None and not r["checks"].get("tex_toolbar"):
overall = min(overall, 0.50)
# 5. VLM unavailable → cap 0.60 (cannot reach top tier without visual judge)
if vlm_avg is None:
overall = min(overall, 0.60)
# 6. Strict VLM degradation
if vlm_avg is not None:
if vlm_avg < 0.4:
overall = min(overall, 0.30)
elif vlm_avg < 0.6:
overall = min(overall, 0.45)
r["overall_score"] = round(overall, 3)
r["sub_scores"] = {"core": round(core, 3), "gui": round(gui, 3), "aux": round(aux, 3),
"base": base, "vlm": vlm_avg}
return r
```
## Workspace Path
`workspace/DOC/task_0_latex_layout_fix/`
## Skills
```
```
## Env
```
```
## Warmup
```bash
which pdflatex >/dev/null 2>&1 || DEBIAN_FRONTEND=noninteractive apt-get install -y -qq texlive-latex-base texlive-latex-extra texlive-latex-recommended texlive-publishers texlive-fonts-recommended texlive-lang-chinese || true
which pdfinfo >/dev/null 2>&1 || DEBIAN_FRONTEND=noninteractive apt-get install -y -qq poppler-utils || true
which tesseract >/dev/null 2>&1 || DEBIAN_FRONTEND=noninteractive apt-get install -y -qq tesseract-ocr || true
pip install -q pdf2image pytesseract pillow numpy || true
```
|