Skip to content
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

Colored Text Crashes PDF Export #1071

Closed
MSeal opened this issue Jul 28, 2019 · 2 comments · Fixed by #1077
Closed

Colored Text Crashes PDF Export #1071

MSeal opened this issue Jul 28, 2019 · 2 comments · Fixed by #1077
Labels

Comments

@MSeal
Copy link
Contributor

MSeal commented Jul 28, 2019

Printing colored text results in latex conversion when exporting to pdf that fail to process by xelatex.

Executing and then exporting via jupyter nbconvet --to=pdf ColorExportFail

from colorama import Fore, Back, Style 
print(Fore.RED + 'red')

Raises an exception:

! FancyVerb Error:
  Empty verbatim environment
.
\FV@Error ...ncyVerb Error:^^J\space \space #1^^J}
                                                  
l.381 }\end{Verbatim}

Just exporting the latex via jupyter nbconvet --to=latex ColorExportFail produces

    \begin{Verbatim}[commandchars=\\\{\}]
\textcolor{ansi-red}{red
}\end{Verbatim}

Instead of

    \begin{Verbatim}[commandchars=\\\{\}]
\textcolor{ansi-red}{red}
\end{Verbatim}

The extra newline breaks exports.

ColorExportFail.txt

This is on current master (5.5.0)

@njapke
Copy link

njapke commented Jul 30, 2019

I found the issue. It has to do with style_jupyter.tplx.
Line 140-144

((* block stream *))
    \begin{Verbatim}[commandchars=\\\{\}]
((( output.text | wrap_text(charlim) | escape_latex | ansi2latex -)))
    \end{Verbatim}
((* endblock stream *))

In line 142 the block begins with ((( but ends with -))). Once I corrected that, the resulting latex code looked like this (in the relevant section):

    \begin{Verbatim}[commandchars=\\\{\}]
\textcolor{ansi-red}{red
}
    \end{Verbatim}

This compiles without any problems into a PDF. The new line after {red is passed through from the notebook, because there the block looks like this:

{
 "name": "stdout",
 "output_type": "stream",
 "text": [
  "\u001b[31mred\n"
 ]
}

The trailing \n is responsible for that line break, but it seems to be harmless.

I don't know why closing the block the wrong way ate the necessary line break, but I'll make a pull request soon implementing this.

@t-makaro
Copy link
Contributor

t-makaro commented Jul 30, 2019

The whitespace trimming in the stream block is there to make sure that the verbatim box is not larger than it needs to be. Otherwise there is a strangely large amount of whitespace after a stream block. I'd like to delve into the code for the ansi2latex filter before removing that whitespace gobbler (the -) because ansi2latex is treating the newline differently than it should (as the newline isn't a part of the original string. The newline is only a part of how it is stored in the ipynb file).

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants