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

fix ansi2latex filtering #1077

Merged
merged 5 commits into from
Aug 1, 2019
Merged

fix ansi2latex filtering #1077

merged 5 commits into from
Aug 1, 2019

Conversation

t-makaro
Copy link
Contributor

@t-makaro t-makaro commented Jul 31, 2019

Alternative to #1073. Fixes #1071

This produces:
image

As opposed to what #1073 produces:
image

@MSeal I'll leave it to you to decide which option to choose.

@t-makaro t-makaro added this to the 5.6 milestone Jul 31, 2019
@mgeier
Copy link
Contributor

mgeier commented Jul 31, 2019

FWIW, I've solved this problem in nbsphinx by stripping '\n' from the end of all stream outputs:

https://github.com/spatialaudio/nbsphinx/blob/f09f4490525300d5c45213aab3d50d4da68ec40a/src/nbsphinx.py#L1247-L1250

I assume this would still need #1073 (which is a good idea anyway).

I think there is no perfect solution though, because the Jupyter notebook format has some inconsistencies regarding trailing '\n'.

@njapke
Copy link

njapke commented Jul 31, 2019

The results here look much nicer than mine in #1073, but I feel like trimming all trailing \n might be a better solution. The verbatim environment should be produced correctly without needing to trim whitespace in the templates.

@t-makaro
Copy link
Contributor Author

t-makaro commented Jul 31, 2019

Alright, I adjusted to just remove that whitespace. I agree this is a cleaner solution, and it does appear to render as expected with my test pdfs.

Right now this technically removes trailing '\n' from output blocks too, so if someone did print('test\n') in a block then the '\n' would not be rendered in the pdf. I would consider this as fine since it leaves the rest of the whitespacing up to latex. I could create a separate filter for removing this newline and only apply it too the stream block.

@mgeier
Copy link
Contributor

mgeier commented Jul 31, 2019

@t-makaro When you think about it, it doesn't really make sense to add this functionality to a function named ansi2latex(). I think the '\n' should be removed before passing the string to ansi2latex().

I could create a separate filter for removing this newline and only apply it too the stream block.

Yes, this sounds more reasonable.

This will not change the result, but I think in the long run it is better to have functions that do what their name suggests and not arbitrary other things on top of that.

@t-makaro
Copy link
Contributor Author

Now implemented using a filter called: strip_trailing_newline.

@t-makaro t-makaro changed the title fix ansi2latex fix ansi2latex filtering Jul 31, 2019
Copy link
Member

@willingc willingc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me @t-makaro. I'll leave it up to you which PR to go with. Though sentiment seems that this one is preferred.

@t-makaro t-makaro merged commit ed505f4 into jupyter:master Aug 1, 2019
@t-makaro t-makaro deleted the fix_latex_ansi branch August 1, 2019 06:02
@meeseeksmachine
Copy link

This pull request has been mentioned on Jupyter Community Forum. There might be relevant details there:

https://discourse.jupyter.org/t/nbconvert-5-6-0-release/1867/1

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

Successfully merging this pull request may close these issues.

Colored Text Crashes PDF Export
5 participants