-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
rendering R 4.1's native pipe #1157
Comments
Hi @edzer, Just to understand correctly, so that we are on the same page: How do you expect Is it because This can be reproduce in a simple document with ---
title: test
output:
html_document:
highlight: pygments
---
```{r}
f <- function(x) { x + 1 }
2 |> f()
```
```{r}
(\(x) x + 1)(2)
``` I don't know if this is a syntax highlight theme issue or if this requires some changes in the Pandoc syntax highlighter. For Or are you expecting ligatures ? If so I believe for that, you would need to use a font for code that supports ligature. It is the same in Terminal or maybe even in IDE if you use a font that does not support ligatures. For example, now that rmarkdown integrates with bslib, you could easily change fonts this way. For example with Fira Code, this would look different ---
title: test
output:
html_document:
theme:
version: 4
code_font:
google: Fira Code
---
```{r}
f <- function(x) { x + 1 }
2 |> f()
``` Does it looks like more what you expect ? BTW There are several ways to change fonts and using bslib with rmarkdown is not the only option. |
Note for self: <pre class="sourceCode r"><code class="sourceCode r">
<span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>f <span class="ot"><-</span><span class="cf">function</span>(x) { x <span class="sc">+</span> <span class="dv">1</span> }</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="dv">2</span> <span class="sc">|</span><span class="er">></span> <span class="fu">f</span>()</span>
</code></pre> So Currently, themes gives different color to those two classes. Supporting downlit as R parser instead of Pandoc could help solves this - which is something we are looking into: rstudio/rmarkdown#1881 |
Thanks @cderv for looking into this! I'm looking at the first case - despite the coolness of these ligatures, I think that code sections are most helpful if they show how you would type them. Using this R code:
using this in your pygments example above, I see |
Thanks a lot for the example. Then this is indeed due the syntax highlighter used. With There would be workaround that have less different colors as mentioned earlier but they are not yet available easily in This is something will definitely need to improve. Thanks for the report on this. I had not tried it yet so I did not know about this issue. 😅 |
We need to file an issue to Pandoc's syntax highlighter. Or if you are able to, send a pull request (which is probably not too hard): https://github.com/jgm/skylighting/blob/master/skylighting-core/xml/r.xml Before it is fixed upstream, we can definitely also fix it on our side for now (which should not be hard). |
yes I started looking and asked for confirmation on how to do it. But the changes has to be done upstream in KDE (https://invent.kde.org/frameworks/syntax-highlighting) and not directly in skylighting. Also |
This is (temporarily) fixed in rmarkdown. You can test the development version via remotes::install_github('rstudio/rmarkdown') Thanks! |
Thanks @yihui ! I'll work on the |
rmarkdown 2.10 ========================================================================= - `md_document()` will now handle correctly `preserve_yaml` value for all variants and all pandoc versions (#2190). * with `preserve_yaml = TRUE`, markdown output will keep the YAML metadata block from the Rmd file. * with `preserve_yaml = FALSE`, markdown output will have no YAML metadata block. This fixes a breaking change in Pandoc 2.13 regarding `gfm`, `commonmark` and `commonmark_x` which now supports `yaml_metadata_block` by default (#2118). - New supported syntax for Shiny prerendered documents: you can now use `server: shiny` or `server: type: shiny`. - Ability to inject additional functions into Shiny prerendered server scope using the "server-extras" context. - Fixed the syntax highlighting issue with R's pipe operator `|>` (thanks, @edzer, rstudio/bookdown#1157). rmarkdown 2.9 ========================================================================== - Fix a regression in version 2.8 when a url is used in `css` argument (thanks, @vnijs, #2163). - All HTML dependencies are now correctly supported, included those with only an `href` component but not `file` component in their `src` attribute. Previously, **rmarkdown** would throw the error `'path for html_dependency not provided'` when rendering documents containing HTML dependencies with `href` components (thanks, @crazycapivara, @matthewstrasiotto, #1805, #1948, #2151). - Fix an error thrown with output format using a `file_scope` function (like in **bookdown**) (thanks, @rfaelens, #2149). - Fix an issue with `copy_ressource = TRUE` in `html_document_base` where very long HTML documents were truncated during post processing (thanks, @oliviermeslin, #2145). - When `run()`-ing a `runtime: shiny` document, an extra temp folder will be used in the output path. With the extra temp random folder in the path, predictable output file names may be used. (#2137) - When `run()`-ing a `runtime: shiny` document with a `{bslib}` theme, the global theme value wasn't being restored properly. (#2160) - Floating ToC in `html_document` can now hide headings with unnumbered and unlisted classes (thanks, @atusy, #1993). - Fix prefix handling in R Markdown website's navbar for Fontawesome V5 and compatibility with V4. For icon only available in V5, the full prefix + name should be use, especially with new `fab` prefix (e.g. `fab fa-r-project`). If no prefix is used (e.g `fa-home` instead of `fas fa-home`), the `fa` prefix will be added for V4 compatibility as it has been deprecated in V5. We advice to use the full prefix + name for icons following Fontawesome documentation. (#1994) - `rmarkdown::site_generator()` can hang session waiting for input when the `site` field is not found in the YAML frontmatter of `index.Rmd` (thanks, @kevinushey @mirh, #2043).
There is a similar issue in pdf output where data |> select(colA, colB) |> head() turns into \begin{Shaded}
\begin{Highlighting}[]
\NormalTok{data }\SpecialCharTok{|}\ErrorTok{\textgreater{}} \FunctionTok{select}\NormalTok{(colA, colB) }\SpecialCharTok{|}\ErrorTok{\textgreater{}} \FunctionTok{head}\NormalTok{()}
\end{Highlighting}
\end{Shaded} Is there a known trick to get a ligature in pdf? |
Hi @eddelbuettel, The fix in bookdown was only for HTML output. We need to fix it more globally and upstream - this is tracked in rstudio/rmarkdown#2196.
First thing is the correctly syntax highlighting. The known trick to get correct syntax highlighting would be to use a patch KDE XML syntax definition file. In the meantime I published a gist with a patched xml file you could use: https://gist.github.com/cderv/079b78caefbe45da6d1c03d737970b55 You could download it and use it by adding
This would lead to \begin{Shaded}
\begin{Highlighting}[]
\NormalTok{mtcars }\SpecialCharTok{|\textgreater{}} \FunctionTok{head}\NormalTok{()}
\end{Highlighting}
\end{Shaded} Including this definition file in rmarkdown directly is part of rstudio/rmarkdown#2196 - Still on the todo list though. Second thing is the Ligature. To get the ligature in the pdf output, I guess you would need a font that supports it like Fira Code. Here is an example : ---
title: "Minimal Example"
output:
pdf_document:
latex_engine: lualatex
highlight: zenburn
pandoc_args: "--syntax-definition=r.xml"
monofont: 'Fira Code'
---
```{r}
mtcars |> head()
``` |
Very nice! The syntax checker is already a winner, I am driving this (as my usual slide desks) via binb's variant of metropolis and while it has a monofont option this doesn't (yet) pass through -- but for the one lecture I am using this for it may also better to not just yet jump to ligatures. But I will try to work out where/if the setup gets in the way and overrides. |
@eddelbuettel this should now been fixed for This is in the dev version of rmarkdown. |
@cderv Sweet. Given that I have a commonality via my The ligature fonts do not come out in pdf if I use binb/metropolis. I pokes a little around the created tex file, and as it goes with such files there are quite a few other packages involved. For now I will keep it at the improved fixed width / non-ligature display in pdf. Thanks again! |
Merge remote-tracking branch 'rstudio_origin/main' into jg-tree-fix # By Christophe Dervieux (2) and Yihui Xie (1) # Via Christophe Dervieux * rstudio_origin/main: Add class to book cover to size using CSS fix the syntax highlighting of |> in LaTeX/PDF output: rstudio/bookdown#1157 (rstudio#2228) Add an option to opt-out the header-attrs HTML dependency in `html_document_base()` (rstudio#2227) # Conflicts: # NEWS.md
Merge branch 'jg-tree-fix' into jg-devel * jg-tree-fix: Use latest Pandoc in GHA and update workflow (rstudio#2244) Add class to book cover to size using CSS fix the syntax highlighting of |> in LaTeX/PDF output: rstudio/bookdown#1157 (rstudio#2228) Add an option to opt-out the header-attrs HTML dependency in `html_document_base()` (rstudio#2227) Clean up NEWS.md. # Conflicts: # DESCRIPTION # NEWS.md
* jg-devel: (35 commits) Use latest Pandoc in GHA and update workflow (rstudio#2244) Add class to book cover to size using CSS fix the syntax highlighting of |> in LaTeX/PDF output: rstudio/bookdown#1157 (rstudio#2228) Add an option to opt-out the header-attrs HTML dependency in `html_document_base()` (rstudio#2227) Clean up NEWS.md. Updated autogenerated documentation. Fixed conflicts with rstudio main version. Update documentation for html_document. Add self (JG) as a contributor in DESCRIPTION. Resolve conflicts with new updates to RStudio main branch. Clean up a few things from the merge. Fix problem building with GitHub Actions because of `mathjax: local` in the testthat tests. Revert unnecessary formatting change to code in render.R. Revert an unnecessary formatting change to comments in render.R. Update NEWS.md. revert inadevertent change from accidental merge with jg-tree-fix. Removed unnecessary references to `allow_uptree_lib_dir` in `ioslides_presentation` and `slidy_presentation`. Prepare for PR to RStudio. Updated documentation for new parameter in output_format(). Removed packages.bib from tests/testthat. ...
…n 2.12 Carson Sievert (1): Add BS5's data-bs-* attributes where it's needed so dropdowns and navbar collapsing work with Bootstrap 5 (#2317) Christophe Dervieux (40): Add support for devtools loaded package in `draft()` (#2224) Add an option to opt-out the header-attrs HTML dependency in `html_document_base()` (#2227) Add class to book cover to size using CSS Use latest Pandoc in GHA and update workflow (#2244) Update GHA following v2 tag in r-lib/actions (#2260) Add Config/Needs/website key Add a GHA workflow to generate rmarkdown CITATION.cff file (#2265) Add mention of RStudio's Viewer Pane not working for ioslides_presentation() Update links to Cheatsheets in vignette Only run the update of cff file on main branch Rework anchor_sections to change default behavior (#1964) Add dir variable to HTML templates (#2271) Add a LICENSE.md file in repo (#2275) Typo in documentation Add more highlighting support for HTML output (#1941) Support custom highlight theme in other formats (#2285) Support incremental for Powerpoint presentation (#2286) Add a available_templates() function to list templates (#2287) Add missing topic for pkgdown website typo in help page Add 2 more functions in `shared.lua` Revert "Add 2 more functions in `shared.lua`" Add function in `shared.lua` for sharing fixes in Lua filters across packages (#2291) Just skipping the test on windows for now (#2292) typo in inserted head Support custom url for KaTeX as `math_method` (#2296) Fix header-includes and in_header in `beamer_presentation` (#2299) Pandoc requires a `=` between math flag and its url value (#2300) mathjax local needs output_dir and lib_dir (#2302) For webtex, defaulting to SVG as this is far better rendering Support R KaTeX package as a new `math-method`(#2304) Correctly handle preserve_yaml in markdown formats (#2303) Update NEWS regarding `md_document()` changes display single line summary content inline Allow empty server context in shiny prerendered (#2305) Support webtex for Github documents format (#2301) generate Citation file only at each release post-processing tex file in pdf document is not yet possible (#2320) Add revdep folder to buildignore Update badge link Garrick Aden-Buie (1): Add `$pkgVersion` to shiny prerendered dependencies (#2218) Gary (1): Update CLA links and email alias (#2312) Yihui Xie (7): import bslib (#2154) fix the syntax highlighting of |> in LaTeX/PDF output: rstudio/bookdown#1157 (#2228) tweak and reorder news (#2321) circumvent ThinkR-open/gitdown#17 add the `highlight` argument to html_vignette() to avoid the issue in molic: mlindsk/molic#30 remove the test accordingly CRAN release v2.12 atusy (3): Fix broken links by number-sections.lua on markdown flavors (#2093) Support all math rendering engines from Pandoc in HTML documents (#1940) add shiny_prerendered special comment via pandoc_include_args (#2249) cderv (20): Update CITATION.cff Update CITATION.cff Update CITATION.cff Update CITATION.cff Update CITATION.cff Update CITATION.cff Update CITATION.cff Update CITATION.cff Update CITATION.cff Update CITATION.cff Update CITATION.cff Update CITATION.cff Update CITATION.cff Update CITATION.cff Update CITATION.cff Update CITATION.cff Update CITATION.cff Update CITATION.cff Update CITATION.cff Update CITATION.cff christophe dervieux (1): Fix typo in comment
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary. |
I'm not sure whether this is an issue with bookdown, knitr or some other package, but it looks as if the R 4.1 native pipe symbol
|>
is not rendered correctly:The same might be the case for the new
=>
infix function operator and the prefix\(
The text was updated successfully, but these errors were encountered: