executablebooks / sphinx-jupyterbook-latex

Supporting LaTeX infrastructure for Jupyter Book
https://sphinx-jupyterbook-latex.readthedocs.io
BSD 3-Clause "New" or "Revised" License
29 stars 13 forks source link

✨ NEW: Formatting of output code cells #87

Closed AakashGfude closed 3 years ago

AakashGfude commented 3 years ago

@mmcky here I have made a new CellOutput node instead of overriding visit_literal_block which I had suggested as inevitable and we had agreed upon in our chat yesterday.

The present approach just wraps around sphinxVerbatim and provides styling. This is less invasive and prevents fiddling with existing sphinx nodes.

Will change the node name to something more specific, showing this as a proof of concept in the first iteration.

Before image taken from https://github.com/executablebooks/sphinx-jupyterbook-latex/issues/10 (Left: Before, Right: After)

101757324-22e50900-3b2b-11eb-974b-4b4090a89c09 Screen Shot 2021-10-28 at 1 26 50 pm

2nd option:

101757324-22e50900-3b2b-11eb-974b-4b4090a89c09 Screen Shot 2021-10-29 at 5 27 55 pm

3rd option:

101757324-22e50900-3b2b-11eb-974b-4b4090a89c09 Screen Shot 2021-11-02 at 9 40 22 am

3rd option(with padding):

101757324-22e50900-3b2b-11eb-974b-4b4090a89c09 Screen Shot 2021-11-02 at 10 17 12 am

mmcky commented 3 years ago

thanks @AakashGfude if this approach provides enough control over the tex I am all for it. Nice work.

this approach should also enable the introduction of styles in an easier fashion by injecting different tex for the environment. Perhaps we can allow for styling through _config.yml through an option like jb_latex_code_output_style = "redbox" as we would want to apply the style on a document wide basis.

mmcky commented 3 years ago

thanks @AakashGfude the third option looks great. It is a huge improvement and I think we should go ahead and make that the default "style".

mmcky commented 3 years ago

re padding I would actually vote without padding

mmcky commented 3 years ago

style comment: I would also add a really light background to the output block. It might be the case that they last code-block output may look like text, unless you think indentation is enough. Minimal is good if they don't look the same (at that edge case).

AakashGfude commented 3 years ago

style comment: I would also add a really light background to the output block. It might be the case that the last code-block output may look like text unless you think indentation is enough. Minimal is good if they don't look the same (at that edge case).

@mmcky I had the same feeling. But, I was just copying the style of HTML blocks. There is a light background, but it is too light it seems. I will increase it a bit and see.

codecov[bot] commented 3 years ago

Codecov Report

Merging #87 (37810a5) into master (8cc0a8a) will increase coverage by 0.93%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #87      +/-   ##
==========================================
+ Coverage   91.45%   92.39%   +0.93%     
==========================================
  Files           4        4              
  Lines         316      355      +39     
==========================================
+ Hits          289      328      +39     
  Misses         27       27              
Flag Coverage Δ
pytests 92.39% <100.00%> (+0.93%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
sphinx_jupyterbook_latex/__init__.py 95.23% <100.00%> (+0.79%) :arrow_up:
sphinx_jupyterbook_latex/nodes.py 98.55% <100.00%> (+0.72%) :arrow_up:
sphinx_jupyterbook_latex/transforms.py 92.20% <100.00%> (+0.49%) :arrow_up:
AakashGfude commented 3 years ago

@mmcky does this look better?

Screen Shot 2021-11-02 at 10 49 16 am
mmcky commented 3 years ago

style comment: I would also add a really light background to the output block. It might be the case that the last code-block output may look like text unless you think indentation is enough. Minimal is good if they don't look the same (at that edge case).

@mmcky I had the same feeling. But, I was just copying the style of HTML blocks. There is a light background, but it is too light it seems. I will increase it a bit and see.

the code-block input background is great (as before) -- I am referring to the output blocks. If talking about the output blocks I still can't se a background :-)

AakashGfude commented 3 years ago

style comment: I would also add a really light background to the output block. It might be the case that the last code-block output may look like text unless you think indentation is enough. Minimal is good if they don't look the same (at that edge case).

@mmcky I had the same feeling. But, I was just copying the style of HTML blocks. There is a light background, but it is too light it seems. I will increase it a bit and see.

the code-block input background is great (as before) -- I am referring to the output blocks. If talking about the output blocks I still can't se a background :-)

Ooh damn. I reckon its too light.

mmcky commented 3 years ago

@mmcky does this look better?

Screen Shot 2021-11-02 at 10 49 16 am

I think the indentation is probably enough to ensure it looks different to text that may follow the last cell output.

mmcky commented 3 years ago

@AakashGfude it was my screen -- I moved it to my laptop screen and looks a lot darker :-)

mmcky commented 3 years ago

I can see it now on the original -- I have a crapy external display. Let's go with your initial settings. Perhaps if we parameterise this we can then let users adjust it if they want?

AakashGfude commented 3 years ago

Yes, I reckon we can't expect the users as well to have a good display. Will need to put it in the preamble then.

mmcky commented 3 years ago

@AakashGfude roger that.

Let's open an issue for style improvements / parameterisation (more generally) and just move this forward as I think it will be great to have.

Mehdish1 commented 3 years ago

در پنجشنبه ۲۸ اکتبر ۲۰۲۱ در ۹:۵۵ AakashGC @.***> نوشت:

@.**** commented on this pull request.

In sphinx_jupyterbook_latex/theme/jupyterBook.cls https://github.com/executablebooks/sphinx-jupyterbook-latex/pull/87#discussion_r738055198 :

@@ -49,3 +49,12 @@ \DeclareMathOperator{\argmin}{arg\,min} \DeclareMathOperator{\argmax}{arg\,max} \DeclareMathOperator*{\gt}{>} + +\definecolor{VerbatimOutputColor}{RGB}{232,232,224} + +\makeatletter +\newenvironment{sphinxVerbatimOutput}

@mmcky https://github.com/mmcky it will only change those output blocks, where I have specifically added sphinxverbatimOutput. I have done that in visit_ method of CellOutput. At present, I added this environment wrapper for all CellOutputNode but will filter to do only for ones that have code text outputs and not images for example.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/executablebooks/sphinx-jupyterbook-latex/pull/87#discussion_r738055198, or unsubscribe https://github.com/notifications/unsubscribe-auth/AU3VN7H3FEW7ZOMUKLHY5CLUJDUDXANCNFSM5G3YXOEQ .

-- null

michaelosthege commented 2 years ago

Are these changes relevant for configuring the font size?

I asked that question in https://github.com/orgs/executablebooks/discussions/730

mmcky commented 2 years ago

hi @michaelosthege -- this PR was primarily related to creating a visual difference between output blocks and input blocks. This is a nice idea and it would be good to add font-size control. I am wondering though if this should be a global option that is set in _config.yml such that ALL code-cell font sizes are adjusted or if control at the code-cell level is preferred.

cc: @AakashGfude