Skip to content

Feature/pdfcodeblock #11919

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ Pull requests are very welcome! Here's how to contribute via PR:

2. For significant changes (e.g more than small bug fixes), ensure that you have signed the [individual](https://posit.co/wp-content/uploads/2023/04/2023-03-13_TC_Indiv_contrib_agreement.pdf) or [corporate](https://posit.co/wp-content/uploads/2023/04/2023-03-13_TC_Corp_contrib_agreement.pdf) contributor agreement as appropriate. You can send the signed copy to [jj\@rstudio.com](mailto:[email protected]){.email}.

3. Submit the [pull request](https://help.github.com/articles/using-pull-requests). It is ok to submit as draft in your are still working on it but would like some feedback from us. It always good to share in the open that you are working on it.
3. Submit the [pull request](https://help.github.com/articles/using-pull-requests). It is ok to submit as draft if your are still working on it but would like some feedback from us. It is always good to share in the open that you are working on it.

We'll try to be as responsive as possible in reviewing and accepting pull requests.
11 changes: 11 additions & 0 deletions src/resources/filters/layout/meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function layout_meta_inject_latex_packages()
-- Both options could be undefined, true / false or set to a color value
local useCodeBlockBorder = (adaptiveTextHighlighting and meta[kCodeBlockBorderLeft] == nil and meta[kCodeBlockBackground] == nil) or (meta[kCodeBlockBorderLeft] ~= nil and meta[kCodeBlockBorderLeft] ~= false)
local useCodeBlockBg = meta[kCodeBlockBackground] ~= nil and meta[kCodeBlockBackground] ~= false
local deactivateCodeBlockBg = meta[kCodeBlockBackground] ~= nil and meta[kCodeBlockBackground] == false

-- if we're going to display a border or background
-- we need to inject color handling as well as the
Expand Down Expand Up @@ -101,6 +102,16 @@ function layout_meta_inject_latex_packages()
end


-- if we're NOT going to display a border or background we need to inject
-- code to modify the pandoc behavior for fenced code blocks boxes.
-- This can be used to especially allow code blocks in other boxes like
-- callback
if (not useCodeBlockBorder and deactivateCodeBlockBg) then
metaInjectLatex(meta, function(inject)
inject("\\ifdefined\\Shaded\\renewenvironment{Shaded}{}\\fi")
end)
end


-- enable column layout (packages and adjust geometry)
if (layoutState.hasColumns or marginReferences() or marginCitations()) and _quarto.format.isLatexOutput() then
Expand Down
4 changes: 4 additions & 0 deletions src/resources/schema/document-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@
long: |
Specifies to apply a background color on code blocks. Provide a hex color to specify that the background color is
enabled as well as the color of the background.

For PDF output, if you specify `false` and `code-block-border-left` is `false` or not set, the code block is not
enclosed in a floating LaTeX environment. This is especially useful for long code blocks nested inside a callout block,
as it allows correct page breaks to occur. Line numbering and annotations are not affected.
- name: highlight-style
tags:
formats: [$html-all, docx, ms, $pdf-all]
Expand Down
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ We run several type of tests

- Unit tests, located in `unit/` folder
- Integration tests, located in `integration/` folder
- smoke tests localed in `smoke` folder
- smoke tests located in `smoke` folder

Tests are run in our CI workflow on GHA at each commit, and for each PR.

Expand Down
66 changes: 66 additions & 0 deletions tests/docs/smoke-all/2025/01/21/issue-11698.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
title: "foo"
code-block-bg: false
format: pdf
---
:::: {.callout-caution icon=false}
## Self implementation

Implement the code yourself by filling out the missing sections:

```{python}
#| code-fold: true
#| eval: false
#| code-summary: "Code fragment for implementation."
#| fig-cap: "Test"
import numpy as np
import matplotlib.pyplot as plt
%config InlineBackend.figure_formats = ["svg"]

frequ = 2 * np.pi * 50
f = lambda t: 0.8 * np.sin(t * frequ)
diod = lambda t: (np.exp(1.2 + t) - 1)

t = np.linspace(0, 2 * np.pi / frequ, 1024, endpoint=False)
x = np.linspace(np.min(f(t)) * 1.3, np.max(f(t)) * 1.1, 1024)

ic = lambda t: diod(f(t))

k = np.arange(0, 16) * 1 / 16

# The provided figures where used to create the illustation
if True:
plt.figure()
plt.plot(f(t), t)
plt.plot([np.min(t),np.max(t)], [0,0], "gray")
plt.axis("off")
#plt.savefig("sin.svg", transparent=True)
plt.figure()
plt.plot(x, diod(x))
z = np.array([0, np.min(f(t)), np.max(f(t))])
plt.plot(z, diod(z), "bx")
plt.axis("off")
plt.xlim([-2,5])
plt.gcf().patch.set_visible(False)
#plt.savefig("diode.svg", transparent=True)

plt.figure()
plt.plot(t, ic(t))
plt.plot(2*np.pi*k/frequ, ic(2*np.pi*k/frequ), "ro")
plt.axis("off")
#plt.savefig("ic.svg", transparent=True, bbox_inches ="tight")

y = ic(k)
yhat = (np.fft.fft(y))
#Necessary correction factor for the FFT
factor = 1 / 16
yy = factor * yhat

ic_mean = np.mean(ic(np.linspace(0, 1/50, 2**20)))
c0 = yy[0].real
effective_value = np.linalg.norm(yy[1:])
harmonic_distortion = np.linalg.norm(yy[3:-2])/np.linalg.norm(yy[1:])
```
::::

Some text that will not be displayed in the correct color.
Loading