|
| 1 | +# Quarto LaTeX engine Pattern Maintenance |
| 2 | + |
| 3 | +Quarto tracks **tinytex** R package's LaTeX error detection patterns to provide helpful diagnostics when LaTeX compilation fails. This document describes the automated verification process and manual adaptation workflow. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The R package **tinytex** maintains a comprehensive database of LaTeX error patterns in its parsing error logic, and export this in `regex.json` in its daily release. It can detect missing packages and fonts. We track these patterns because: |
| 8 | + |
| 9 | +- TinyTeX is the distribution maintain by Posit team actively maintains patterns based on user reports (@yihui and @cderv) |
| 10 | +- It is used by Quarto (`quarto install tinytex`) |
| 11 | +- Every problem will be fixed in the R package first |
| 12 | +- Low update frequency (~4 changes/year) makes manual adaptation practical |
| 13 | + |
| 14 | +**Our process:** |
| 15 | + |
| 16 | +- Daily automated check detects when TinyTeX patterns change |
| 17 | +- GitHub issue created/updated when changes detected |
| 18 | +- Manual review and adaptation for Quarto's usage |
| 19 | + |
| 20 | +## Pattern Differences |
| 21 | + |
| 22 | +tinytex R package and Quarto LaTeX engine use patterns differently: |
| 23 | + |
| 24 | +- R package: Matches patterns line-by-line against log array |
| 25 | +- Quarto: Matches patterns against entire log file as string |
| 26 | + |
| 27 | +### Common Adaptations |
| 28 | + |
| 29 | +1. **Direct copy** (most common): |
| 30 | + |
| 31 | + ```typescript |
| 32 | + // TinyTeX: ".*! LaTeX Error: File [`']([^']+)' not found.*" |
| 33 | + // Quarto: |
| 34 | + /.*! LaTeX Error: File [`']([^']+)' not found.*/g; |
| 35 | + ``` |
| 36 | + |
| 37 | +2. **Anchored patterns** need multiline flag or anchor removal: |
| 38 | + |
| 39 | + ```typescript |
| 40 | + // TinyTeX: "^No file ([^`'. ]+[.]fd)[.].*" |
| 41 | + // Quarto options: |
| 42 | + /^No file ([^`'. ]+[.]fd)[.].*/gm // multiline flag |
| 43 | + /.*No file ([^`'. ]+[.]fd)[.].*/g // remove anchor |
| 44 | + ``` |
| 45 | + |
| 46 | +3. **Filter functions** for post-processing: |
| 47 | + ```typescript |
| 48 | + { |
| 49 | + regex: /.*! Font [^=]+=([^ ]+).+ not loadable.*/g, |
| 50 | + filter: formatFontFilter, // Cleans font names |
| 51 | + } |
| 52 | + ``` |
| 53 | + |
| 54 | +## Manual Adaptation Process |
| 55 | + |
| 56 | +When the automated workflow detects TinyTeX pattern changes, it creates/updates a GitHub issue with: |
| 57 | + |
| 58 | +- Date of detection |
| 59 | +- Category-by-category count changes |
| 60 | +- Full diff of `regex.json` changes |
| 61 | + |
| 62 | +### Adaptation Steps |
| 63 | + |
| 64 | +1. Review the diff: |
| 65 | + |
| 66 | + - Identify added, modified, or removed patterns |
| 67 | + |
| 68 | +2. Update [parse-error.ts](../src/command/render/latexmk/parse-error.ts): |
| 69 | + |
| 70 | + - Add new patterns to `packageMatchers` array |
| 71 | + - Convert TinyTeX string patterns to TypeScript regex with `/g` flag |
| 72 | + - Add multiline flag `/gm` if pattern uses `^` or `$` anchors |
| 73 | + - Add filter function if pattern needs post-processing |
| 74 | + |
| 75 | +3. Test changes |
| 76 | + |
| 77 | + ```bash |
| 78 | + cd tests |
| 79 | + # Windows |
| 80 | + pwsh -Command '$env:QUARTO_TESTS_NO_CONFIG="true"; .\run-tests.ps1 unit\latexmk\parse-error.test.ts' |
| 81 | + # Linux/macOS |
| 82 | + QUARTO_TESTS_NO_CONFIG=true ./run-tests.sh unit/latexmk/parse-error.test.ts |
| 83 | + ``` |
| 84 | + |
| 85 | +4. Commit and close issue |
| 86 | + |
| 87 | +## Verification Workflow |
| 88 | + |
| 89 | +The automated workflow runs daily: |
| 90 | + |
| 91 | +1. Downloads `regex.tar.gz` from [TinyTeX releases](https://github.com/rstudio/tinytex-releases) |
| 92 | +2. Extracts and compares `regex.json` with cached version |
| 93 | +3. If changed: generates diff and creates/updates issue |
| 94 | +4. If unchanged: exits early (no notification) |
| 95 | + |
| 96 | +**Workflow location**: [.github/workflows/verify-tinytex-patterns.yml](../.github/workflows/verify-tinytex-patterns.yml) |
| 97 | + |
| 98 | +**Manual trigger**: Run workflow from GitHub Actions tab when testing or after TinyTeX release announcement |
| 99 | + |
| 100 | +## Resources |
| 101 | + |
| 102 | +- [parse-error.ts](../src/command/render/latexmk/parse-error.ts) - Pattern implementation |
| 103 | +- [parse-error.test.ts](../tests/unit/latexmk/parse-error.test.ts) - Unit tests |
| 104 | +- [TinyTeX R source](https://github.com/rstudio/tinytex/blob/main/R/latex.R) - How patterns are used in R |
| 105 | +- [TinyTeX releases](https://github.com/rstudio/tinytex-releases) - Source of regex.json |
0 commit comments