-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversion of ipynb to pdf fails because of ANSI escape codes in stacktrace #5633
Comments
For convenience, this is what's in the ipynb:
and this is how pandoc parses it:
Here's a hexdump of the latex output:
|
How do you think pandoc should deal with this? We could easily modify the latex writer to strip out ANSI escape sequences. Is that a good solution? |
The simplest solution for now is to strip those escape sequences, so that conversion to PDF works.
Currently, I pull the notebook through sed before feeding it to pandoc.
Note that also output of a code cell written to stderr is shown in red.
On 6 Jul 2019 23:25, John MacFarlane <notifications@github.com> wrote:
How do you think pandoc should deal with this? We could easily modify the latex writer to strip out ANSI escape sequences. Is that a good solution?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#5633?email_source=notifications&email_token=ABKZ44YJZONISW6KRD6GZ3TP6EEUFA5CNFSM4H6NBJH2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZLAP6I#issuecomment-508954617>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABKZ44Z67U4USU2DV4CI7B3P6EEUFANCNFSM4H6NBJHQ>.
|
Just in case someone needs it, here is the sed command that I use to strip the ANSI color codes: sed -E 's/\\\\u001b[^m]*m//g' file.ipynb | pandoc ... |
We could either modify the ipynb reader to strip out ANSI escape sequences in code, or modify the latex writer to strip them out. The former approach seems more sensible since we'd get similar problems in other output formats (HTML, docx?). However, this has the drawback that ipynb would not round trip the escape sequences when going ipynb -> ipynb. Maybe that's not an issue? |
I've found the same problem when using the question mark to access the documentation of an object. Very simple example:
produces an output like this:
And running XeTeX with the resulting latex code produces the error |
I came up with a good solution that strips them in most cases but still allows for round-trip. |
Could this be fixed by jupyter/nbconvert#1181 which converts the escape sequences into colors? |
Hmmm ... seems that you've addressed this in 2.10.1 (having read the changelog) .... would it be possible to have the option of stripping the ansi escape sequences without using |
Hi, I encountered this problem in my custom workflow, using pandoc 2.18. Is it true that the ASNI are striped only if it is from ipynb? In my workflow there's some steps that
I can provide MWE and open a new issue if needed. |
Yes please. |
This issue concerns the conversion of a Jupyter notebook (
-f ipynb
) to PDF (-t latex -o *.pdf
), where the notebook contains a Python stack trace (example attached), being the result of a runtime error in a code cell. Such a stack trace includes ANSI escape sequences to color some of the output. However, LaTeX chokes on the result that pandoc produces. Message with pdflatex as engine:With xelatex as engine (lualatex responds similarly):
These ANSI escape sequences are encoded in plain ASCII in the Jupyter notebook (inside a JSON string), but appear as real escape sequences in the produced LaTeX source file, inside a verbatim environment.
Further details:
Stacktrace.ipynb
is attached (zipped, because *.ipynb are not supported).Stacktrace.ipynb.zip
A workaround would be nice to have.
(One option is to strip the ASCII encoded ANSI escape sequences from the notebook before conversion with pandoc (e.g. using
sed
). Alternatively, the LaTeX source generated by pandoc can be stripped of ANSI escape sequences (e.g. usingansifilter
) and then pulled through a LaTeX-to-PDF engine separately. None of these options is very appealing.)The text was updated successfully, but these errors were encountered: