Skip to content

Process ANSI escape code in non-HTML format for Jupyter errors #10347

@lballabio

Description

@lballabio

Bug description

When using the PDF format for a book project, the generated LaTeX file contains ANSI color characters that cause the document compilation to fail.

A search brings up #7813, which looks like it should fix the problem, but that's not the case.

Steps to reproduce

Here is a minimal YML configuration:

project:
  type: book

execute:
  enabled: true

book:
  title: "A reproducible example"
  chapters:
    - index.qmd

format:
  pdf:
    documentclass: book

and here is the sample input file:

# An example

This outputs an ANSI-colorized traceback:

```{python}
# | error: true

1 + "2"
```

Expected behavior

ANSI color characters should be stripped or translated so that the LaTeX file can compile and produce a PDF document.

Actual behavior

The LaTeX compilation fails wih the following error:

ERROR: 
compilation failed- error
Text line contains an invalid character.
l.220 ^^[
         [0;31m-------------------------------------------------------------... 

Your environment

Mac OS Sonoma 14.5, Python 3.12.4, a fresh virtual environment with only Jupyter and its dependencies installed.

Quarto check output

Quarto 1.5.55
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.2.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.41.0: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.5.55
      Path: /Applications/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: v2024.07.03
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/lballabio/Library/TinyTeX/bin/universal-darwin
      Version: 2024

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.12.4
      Path: /Users/lballabio/Downloads/test/.venv/bin/python3
      Jupyter: 5.7.2
      Kernels: python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........(None)

      Unable to locate an installed version of R.
      Install R from https://cloud.r-project.org/

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingjupyter

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions