Skip to content

Commit 529b0fb

Browse files
authored
Prefer text/latex and application/pdf mime types when rendering latex (#13582)
* fix(jupyter): prefer application/pdf and text/latex MIME types for LaTeX output When rendering Jupyter notebooks to PDF/LaTeX, the MIME type priority queue appended text/latex and application/pdf at the end, causing image/svg+xml to be selected instead. This led to errors when rsvg-convert was not available. Fix by using unshift() to place these types at the front of the priority queue. * test: add smoke test for PDF MIME priority fix (#13582) Pre-rendered .ipynb with both application/pdf and image/svg+xml outputs. Renders to latex format with use-rsvg-convert: false and verifies that \includegraphics with .pdf is used (not \includesvg).
1 parent 2d8bf05 commit 529b0fb

3 files changed

Lines changed: 61 additions & 1 deletion

File tree

‎news/changelog-1.9.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ All changes included in 1.9:
200200

201201
### `jupyter`
202202

203+
- ([#13582](https://github.com/quarto-dev/quarto-cli/pull/13582)): Fix `application/pdf` and `text/latex` MIME types not being preferred over `image/svg+xml` when rendering Jupyter notebooks to PDF, which caused errors when `rsvg-convert` was not available.
203204
- ([#13748](https://github.com/quarto-dev/quarto-cli/pull/13748)): Fix stdin encoding to UTF-8 on Windows to correctly handle JSON in documents containing non-ASCII characters.
204205
- ([#13936](https://github.com/quarto-dev/quarto-cli/pull/13936)): Add support for q/kdb+ programming language in percent format notebooks and code cell options. (author: @benlubas)
205206
- ([#13936](https://github.com/quarto-dev/quarto-cli/pull/13936)): Fix `isJupyterPercentScript` regex to correctly detect percent scripts with `[raw]` cells and cells not at the start of the file. The regex now properly groups the alternation `(markdown|raw)` and uses multiline mode.

‎src/core/jupyter/display-data.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ export function displayDataMimeType(
7575
kTextHtml,
7676
);
7777
} else if (options.toLatex) {
78-
displayPriority.push(
78+
// latex and pdf should be preferred over the other mime types
79+
displayPriority.unshift(
7980
kTextLatex,
8081
kApplicationPdf,
8182
);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"metadata": {
3+
"kernelspec": {
4+
"display_name": "Python 3",
5+
"language": "python",
6+
"name": "python3"
7+
},
8+
"language_info": {
9+
"name": "python",
10+
"version": "3.10.0"
11+
}
12+
},
13+
"nbformat": 4,
14+
"nbformat_minor": 5,
15+
"cells": [
16+
{
17+
"id": "1",
18+
"cell_type": "raw",
19+
"metadata": {},
20+
"source": [
21+
"---\n",
22+
"title: \"Issue 13582: PDF MIME priority for LaTeX\"\n",
23+
"format: latex\n",
24+
"use-rsvg-convert: false\n",
25+
"execute:\n",
26+
" enabled: false\n",
27+
"_quarto:\n",
28+
" tests:\n",
29+
" latex:\n",
30+
" ensureFileRegexMatches:\n",
31+
" - [\"\\\\\\\\includegraphics[^\\\\n]*\\\\.pdf\"]\n",
32+
" - [\"\\\\\\\\includesvg\"]\n",
33+
"---\n"
34+
]
35+
},
36+
{
37+
"id": "2",
38+
"cell_type": "code",
39+
"metadata": {},
40+
"source": [
41+
"# Synthetic cell: outputs contain both application/pdf and image/svg+xml.\n",
42+
"# With the fix, application/pdf should be preferred for LaTeX output."
43+
],
44+
"outputs": [
45+
{
46+
"output_type": "execute_result",
47+
"execution_count": 1,
48+
"data": {
49+
"application/pdf": "JVBERi0xLjAKMSAwIG9iajw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAyIDAgUj4+ZW5kb2JqCjIgMCBvYmo8PC9UeXBlL1BhZ2VzL0tpZHNbMyAwIFJdL0NvdW50IDE+PmVuZG9iagozIDAgb2JqPDwvVHlwZS9QYWdlL01lZGlhQm94WzAgMCAxMDAgMTAwXS9QYXJlbnQgMiAwIFI+PmVuZG9iagp4cmVmCjAgNAowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDA1OCAwMDAwMCBuIAowMDAwMDAwMTE1IDAwMDAwIG4gCnRyYWlsZXI8PC9TaXplIDQvUm9vdCAxIDAgUj4+CnN0YXJ0eHJlZgoxOTAKJSVFT0Y=",
50+
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"100\" height=\"100\">\n<rect fill=\"red\" width=\"100\" height=\"100\"/>\n</svg>"
51+
},
52+
"metadata": {}
53+
}
54+
],
55+
"execution_count": 1
56+
}
57+
]
58+
}

0 commit comments

Comments
 (0)