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

Code block options not rendering correctly in beamer #6041

Closed
darthlite opened this issue Jun 27, 2023 · 6 comments
Closed

Code block options not rendering correctly in beamer #6041

darthlite opened this issue Jun 27, 2023 · 6 comments
Assignees
Labels
beamer bug Something isn't working latex LaTeX engines related libraries and technologies themes Related to HTML theming or any other style related issue (like highlight-style)
Milestone

Comments

@darthlite
Copy link

darthlite commented Jun 27, 2023

Bug description

I think I'm facing a bug, but let me know if I'm not doing things right.

When outputting to a beamer format, I can't get code block formatting to behave as I would like. Specifically, using the options code-block-bg, code-block-border-left, and highlight-style, I do not get any background color or left border at all. This is despite all 3 of these properties being part of the beamer options.

The same combination of settings works perfectly when outputting to a pdf format, however.

Steps to reproduce

Here is a MWE with the issue:

---
title: "Test"
format:
    beamer:
        code-block-bg: "#f8f8f8"
        code-block-border-left: "#245ABE"
        highlight-style: github
---

### Testing code blocks

Code block:
```python
import numpy as np

x = 3   # Defining a variable

def best_function(arg1):
    """
    This is a docstring.
    """
    return arg1

best_function(24.8)
```

Expected behavior

This should produce the following colors (taken from pdf output) -- focusing here only on the code block:
Screenshot 2023-06-27 at 6 26 20 PM

Actual behavior

When outputting to beamer, I get the following instead:
Screenshot 2023-06-27 at 6 28 13 PM

Also, if I comment out highlight-style: github, I get even stranger behavior. The whole block takes on the color of the left border:
Screenshot 2023-06-27 at 6 29 10 PM

Your environment

  • OS: MacOS 13.4.1
  • IDE: VSCodium 1.79.2

Quarto check output

[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.1: OK
      Dart Sass version 1.55.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.3.427
      Path: /Applications/quarto/bin

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

[✓] Checking Python 3 installation....OK
      Version: 3.10.12 (Conda)
      Path: /opt/homebrew/Caskroom/miniforge/base/bin/python
      Jupyter: 5.3.1
      Kernels: julia-0.4, matlab_kernel, python3

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

[✓] Checking R installation...........OK
      Version: 3.2.4
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Users/me/Library/R/3.2/library
        - /Library/Frameworks/R.framework/Versions/3.2/Resources/library
      knitr: 1.12.3
      NOTE: knitr version 1.12.3 is too old. Please upgrade to 1.30 or later.
      rmarkdown: 0.9.5

      The knitr package is outdated in this R installation.
      Update with update.packages("knitr")
@darthlite darthlite added the bug Something isn't working label Jun 27, 2023
@mcanouil
Copy link
Collaborator

Thanks for the report.
Meanwhile we are looking into it, could you fix your masked link which is invalid?

@darthlite
Copy link
Author

Apologies, link should be fixed now.

@cderv cderv added the themes Related to HTML theming or any other style related issue (like highlight-style) label Jun 28, 2023
@cderv
Copy link
Collaborator

cderv commented Jun 28, 2023

github.theme is a custom them we have in Quarto. It seems there needs to be some adjustment either in the .theme file for Pandoc's skylighting library, or maybe with the way we defined the code block environment (i.e Shaded) as it could be conflict with Beamer. @dragonstyle we are tweaking what pandoc does by default right ?

Also, if I comment out highlight-style: github, I get even stranger behavior. The whole block takes on the color of the left border:

Regarding, it could be related or just another issue regarding code-block-border-left

I think we are inserting this

\@ifundefined{shadecolor}{\definecolor{shadecolor}{HTML}{245ABE}}
\makeatother
\makeatletter
\@ifundefined{codebgcolor}{\definecolor{codebgcolor}{HTML}{f8f8f8}}
\makeatother

where code-block-border-left is assigned to shadedcolor, and code-block-bg to codebgcolor

Then we are supposed to assign the codebgcolor to the environment used for codeblock to "overwrite" the main color for Shaded environment

\ifdefined\Shaded\renewenvironment{Shaded}{\begin{tcolorbox}[boxrule=0pt, breakable, borderline west={3pt}{0pt}{shadecolor}, enhanced, colback={codebgcolor}, sharp corners, frame hidden]}{\end{tcolorbox}}\fi

but it seems colback={codebgcolor} does not apply inside beamer. And so the default shadedcolor applies.

Looking at the diff with when we provide highlight-style: github or not, it seems there is this environment present in .tex

\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}

Should be replaced by tcolorbox but maybe that does not work...

Something specifc to handle here IMO... 🤔

Sidenote: The default behavior is already not the same for codeblock with PDF and Beamer.

image

image

@cderv
Copy link
Collaborator

cderv commented Jun 28, 2023

Ok - I think I got to the bottom of it

It seems our redefinition of Shaded environment is not taken into account in Beamer. We include it as before-body.

-- redefined the 'Shaded' environment that pandoc uses for fenced
-- code blocks
metaInjectLatexBefore(meta, function(inject)
inject("\\ifdefined\\Shaded\\renewenvironment{Shaded}{\\begin{tcolorbox}[" .. tColorOptions(options) .. "]}{\\end{tcolorbox}}\\fi")
end)

Including it in preamble solves this issue.

diff --git a/src/resources/filters/layout/meta.lua b/src/resources/filters/layout/meta.lua
index 611c8b041..c64b4e174 100644
--- a/src/resources/filters/layout/meta.lua
+++ b/src/resources/filters/layout/meta.lua
@@ -96,7 +96,7 @@ function layout_meta_inject_latex_packages()

         -- redefined the 'Shaded' environment that pandoc uses for fenced        
         -- code blocks
-        metaInjectLatexBefore(meta, function(inject)
+        metaInjectLatex(meta, function(inject)
           inject("\\ifdefined\\Shaded\\renewenvironment{Shaded}{\\begin{tcolorbox}[" .. tColorOptions(options) .. "]}{\\end{tcolorbox}}\\fi")
         end)
       end

@dragonstyle Do you remember why doing the redefinition of Shaded with tcolorbox happens after \begin{}, with before-body ? It is like this from the start (2d96424)

I see two solutions here:

  • Move the insertion in headers-includes
  • Or only do it for beamer output format to not change how it behave with pdf format.

What are you thoughts ? Happy to discuss live if needed.

@cderv cderv added the latex LaTeX engines related libraries and technologies label Jun 28, 2023
@cderv cderv added this to the v1.4 milestone Jun 28, 2023
@cderv
Copy link
Collaborator

cderv commented Jun 28, 2023

Thanks @dragonstyle and Thanks @darthlite for the report !

@darthlite
Copy link
Author

Thank you all for your work and for the speedy fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beamer bug Something isn't working latex LaTeX engines related libraries and technologies themes Related to HTML theming or any other style related issue (like highlight-style)
Projects
None yet
Development

No branches or pull requests

4 participants