rstudio / bookdown

Authoring Books and Technical Documents with R Markdown
https://pkgs.rstudio.com/bookdown/
GNU General Public License v3.0
3.75k stars 1.27k forks source link

Add more out-of-box custom block environments #1089

Open cderv opened 3 years ago

cderv commented 3 years ago

Currently, we mainly support Theorem and Proof: https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#theorems

It would be interesting to support more generic Note block with pre defined style as we can see in several places.

See also https://github.com/rstudio/bookdown/pull/940#issuecomment-691554658 for ideas.

Creating issue here for reference, but maybe this should not be in bookdown, or not all.

But support for some special block to support HTML and PDF output would be interesting.

For example in LaTeX:

cderv commented 3 years ago

This is also what is done in bs4_book() with some special css https://github.com/rstudio/bookdown/blob/f7d062298ef1a209e18cf422f2327780d647f3d3/inst/resources/bs4_book/bs4_book.css#L458-L489

Example:

but not sure it will render in PDF for now. It will just be ignored for now.

yihui commented 3 years ago

For LaTeX output, my hack was to use a bullet and define the bullet symbol to be an icon: https://github.com/rstudio/bookdown/blob/6bc73688b10702ad8965d8af4f5be5ecea77659c/inst/examples/latex/preamble.tex#L59-L89 There are dedicated LaTeX packages for this task such as awesomebox and tcolorbox as you mentioned above. I don't have much experience with them, though. We briefly mentioned awesomebox in the cookbook: https://bookdown.org/yihui/rmarkdown-cookbook/custom-blocks.html

I'm not sure if this feature should belong to bookdown or not.

cderv commented 3 years ago

I'm not sure if this feature should belong to bookdown or not.

You think it could belong to its own package ? Initially I posted here because it seems feature wanted for books (as the block engine set in bookdown, or the equivalent in jupyter book).

Having it elsewhere would indeed allow us to use it in different type of output. 🤔 I'll think of it more and maybe try it out outside of bookdown.

yihui commented 3 years ago

I think it will definitely benefit non-bookdown users. I'm hesitating because this feature will introduce LaTeX and HTML dependencies that can't be well defined. For example, users may have different preferences over which LaTeX environment to use (like my \itemize hack above, or awesomebox, or tcolorbox), or which icons to use, or margin, padding, bg color, and so on. There is too much that can be customized, and I'm not sure how we can satisfy the potential demand for customization.

That said, I think it's fine to start from bookdown, and move this feature into core rmarkdown when necessary. That shouldn't break anything.

cderv commented 3 years ago

There is too much that can be customized, and I'm not sure how we can satisfy the potential demand for customization.

I completely understand this. However I find that not offering a simple solution does not help all users to benefit from an advanced feature.

I was thinking of this feature as

I believe today you can already do that if you now how (adding correct CSS classes and defining LaTeX environment) but you need the knowledge and I feel it should be easier like with Jupyter book content block, or Mkdoc's content block

cderv commented 3 years ago

cc @apreshill this is the issue I mentioned during the meeting

tchevri commented 3 years ago

Again thank you so much for everything you did, regarding this and https://github.com/rstudio/bookdown/pull/940, really can't thank you enough. Quick question though, if I may? I expected the div syntax to allow me to make full use of rmarkdown format, as opposed to the more limited block engine? Therefore, I was expecting this to work: ::: {.theorem} `r if (out_type=="beamer") "- "` Let $m$ be an even integer and $p$ be any integer. Then, $m \cdot p$ is an even integer. ::: but funny enough, when i compile, the whole theorem gets gobbled up - nothing prints... (I took this from my document, but if I add the same `r ` command into your sample bookdown book theorem in chapter 5, i get the exact same result, obviously. Should i be expecting the `r ` command causes the theorem to no longer appear in the pdf?

Since the answer is probably no, I tried a much simpler version and I modified only your chapter 5 theorem, adding a simple -: - For a right triangle, etc... Doing so messes up the github compile (I get two messy bullet points) and in the bookdown::pdf_book compile, I no longer get the theorem at all.... (same for my custom bookdown::beamer_presentation2). Seems very odd to meL since I am only adding one character, I can't be messing it up?? just to confirm the issue is not on my end, I tried directly with your bookdown template and i am getting the same result, so i am guessing you should be able to reproduce very easily and tell me if i am doing something wrong.

many thanks thomas

cderv commented 3 years ago

Hi @tchevri,

I think you found an issue. We use a Lua filter to power this feature, and I think we only expect a paragraph inside such env. Adding a - first will not create a paragrah but a bullet list element and our Lua filter does not seem to support that.

I moved your comment in a issue. Please next time, open a new issue when you report something not directly related to the issue in which you comment. Thank you !