-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Custom environment using Fenced Divs #940
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
Conversation
|
This is great, very exciting - I'll be happy to try it out whenever you think I won't be wasting your time, that's probably the most I can offer as clearly I don't play in your court when it comes to coding. This said, I don't know if it's relevant, but my bookdown creates also slides, as per a previous discussion. I noticed that when I have incremental bullets, it screws up the numbering! So on the first slide, a theorem may appear as theorem 3.1, but if the slide is repeated because of an incremental bullet, then this theorem incorrectly changes to 3.2 though it's the exact same theorem, not a desirable outcome imho. I thought i'd highlight it, as I am sure it will be an easy fix for you, but not something you might have necessarily spontaneously thought about. |
|
Slides output are not really an obvious bookdown output, so yes I did not thought of that. I'll have a look at your example. Currently I am trying to reproduce what exists, but we can surely make improvement to make this more generic. |
|
True, but isn't it desirable to have some slides with your book?
So yes, right now everything works perfect for again - here is my opportunity to thank you very warmly, as i have very much benefited from all your work and help! Merci infiniment. |
|
Thanks for the feedbacks. I'll take that into account. For new features, don't hesitate to open new issue if none already is. IMO It is easier to follow up on one feature per issue, than one topic issue with several bugs and feature request inside it. |
This comment has been minimized.
This comment has been minimized.
|
Two of the issues has been solved now. About the identifier, we add one for |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
For easier testing, I added the lua filter by default. One think I noticed: Currently we don't have good helper function in rmarkdown so that lua filters can be used in other package. I needed to add a function in bookdown, similar to Anyway, we need now to decide when and where this will work:
Todos
|
This comment has been minimized.
This comment has been minimized.
|
Hi! I'm currently writing a stat textbook with Bookdown. We've got a mid-October deadline and realized a couple of weeks ago that fenced divs would solve all of our problems with exercises, solutions, and theorem style numbering. I wrote a lua filter to replace latex-div.lua that implements fenced divs in both HTML and LaTeX. It's probably not exactly what's needed for integration with the bookdown package, but we are using it now for a 400+ page book and it's working well. It was a snap to handle the LaTeX side. The HTML side was much harder, because the cross references needed to be done by hand. I've dealt with a lot of issues and pitfalls and maybe can be of service. I've got a test book I'm using to build out technologies that our real book will use (like a single-chapter PDF makefile). It's got the lua filter, fenced-blocks.lua, and you can see it in action by building the book. You need to disable the built-in latex-div.lua, which I've done by simply commenting out its contents on my system. I'm in the thick of the Fall semester and also trying to hand our book to CRC by mid-October, but I'm happy to help where I can. You're welcome to use the code however you like. |
|
Hi @turtlegraphics ! Thanks a lot for sharing your work ! This is really awesome ! There are a lot of great ideas ! I really like the numbering and cross referencing from the lua filter - we were not planning to do that from the lua filter but as you managed to do it, it could be interesting to add. Also the special classes to allow further customisation in HTML is really cool ! We may integrate some of this and also fix some of your pitfall (latex-divs.lua conflicts, latex preamble or i18n). If I have question I'll ping you, but in the mean time it would be awesome if you find time to contribute here to make all this supported in bookdown (by testing or just by telling me which are the important feature to have so that I don't forget). |
DESCRIPTION
Outdated
| LazyData: TRUE | ||
| RoxygenNote: 7.1.1 | ||
| Encoding: UTF-8 | ||
| Remotes: rstudio/rmarkdown#1899 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To remove after merging the PR in rmarkdown
|
The conflicts with |
This comment has been minimized.
This comment has been minimized.
|
awesome - and interesting (if not weird) issue...
I believe most of us will be keen to know how you fix it, does not look so
obvious, why it even happens.
Thank you so much for all this effort - we all very much appreciate.
…On Tue, Sep 22, 2020 at 3:56 AM Christophe Dervieux < ***@***.***> wrote:
This must have an id thing is really annoying ! But it is currently
necessary for the labelling and internationalization for all eng_theorem
related chunks.
Ok I now fixed that by generating an id for a div if none is provided, as
knitr:::unnamed_chunk() does.
It means we can write a fenced div with no id and it will render correctly
in bookdown - parse_fig_labels will do its trick. Obviously, an id should
be provided to be able to reference correctly using ***@***.***
Converting 02-components.Rmd in inst/examples using
convert_to_fenced_div() then rendering the bookdown book with version of
this branch gives the correct result. The pandoc divs will just use <p>
tags for the content, which we did not have before - so some spacing can
appear differently.
Using engine:
[image: image]
<https://user-images.githubusercontent.com/6791940/93814534-ef45c180-fc54-11ea-8164-6eacc49af399.png>
After conversion, using fenced div:
[image: image]
<https://user-images.githubusercontent.com/6791940/93814592-084e7280-fc55-11ea-9f37-bbbd1e5fec7f.png>
This seems to impact the inserted blank square. So I need to look at that.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#940 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGOTT66TGXNFBBRX2VH2YYTSG6VXNANCNFSM4QQUIUNA>
.
|
|
it happens because of the css rule currently used. bookdown/inst/resources/gitbook/css/plugin-bookdown.css Lines 93 to 96 in 57f1217
As using pandoc, everything is inserted between a |
|
Ok this currently fails with pandoc 2.7.3 😞 - I was developing with 2.9.2.1 - I need to find why. |
|
Ok I tested several pandoc versions and I isolated the issue to be with pandoc 2.7.3 and earlier. It works from 2.8+ From there, following the release note for 2.8, I found that what is described in the documentation about Attributes element (https://pandoc.org/lua-filters.html#type-attr) only work for pandoc 2.8+ That means we need to explicitly use It should work now with pandoc 2.7.3 - that was not easy to find as no explicit error, and it is not mention in the documentation. |
|
@tchevri I was looking back at your comment about beamer support, but I can't make the current theorem or proof engines work with beamer output. So I guess I won't deal with this here. could you open a new issue specific to your beamer support idea with a working example so that I better understand what is required. ok? Thank you ! |
|
@yihui I think you can review now.
I tested on several pandoc versions, and with the bookdown book. Let's get your feedback before going any further - I already spent a lot of time on this one. About the feature:
|
|
Oh and one think I observed about the current behavior: When rendering to HTML, CSS for those environments like |
atusy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! I briefly reviewed the lua filter, and suggest changes.
…o read from or write to files)
…down::pkg_file_lua(): rstudio/rmarkdown#1904
…that actually test the implementation of rmarkdown::pkg_file_lua() (such tests can be added to the rmarkdown package instead)
…ested `if` statements)
…unction can be easier to test (no longer relies on the existence of _bookdown.yml, and the caller can also easily clean up the temp file)
…1a3fb6 remove this test anyway since it really belongs to the rmarkdown package instead of bookdown
…406f68530162fccce03
…ad of doing it for every single output format; this also make sure we won't need to do extra work in the future to support custom environments in other formats like Word and EPUB
c45c9b8 to
7c5fbb8
Compare
yihui
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the long delay! I just finished reviewing and tweaking this giant PR. I'll merge it for now, and take a look at the CSS issue later. Thanks!
…of, regardless of its type (could be a text nodeor <p>), so it works for both ```{proof} and ::: {.proof}
| font-style: normal; | ||
| } | ||
| div.proof:after { | ||
| div.proof>p:last-child:after { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been addressed by c59e3dc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of remember having tried that, and that was not ok in the output... I may have wrongly test it maybe. 🤷♂️
|
Thanks! That was interested to look at the tweak you made to modify this PR. Even if you did not review the lua file per-se, I guess you've tested the filter itself and that worked ok for you ? Or you blindly trusted me with the general behavior of this new feature ? 😅
I opened an issue to track this: #977 but it seems you closed it already. And added another one for beamer support #978 |
|
I only tested it briefly (in the bookdown-demo project). |
OK I finally found where We may want to check if it works with this new env once we support markdown output in the Lua filter. |
|
This option was introduced in e214250. The main purpose was to support theorem environments for the file format That said, it will still be nice if the new syntax works for .Rmarkdown posts. Currently there is a missing step that I haven't done in blogdown yet: |


This will resolve #924
The aim is to use fenced Divs to create the custom block, instead of using special knitr's engines. Some notes in this PR
Engines
eng_theoremandeng_proofare in bookdownknitr:::eng_block2Tricky stuffs
\BeginKnitrBlockare used but we may not need them anymorerestore_block2()- we should keep some(#type:id)- that means we need a unique id, even if not is provided. Currently chunk name is used but with fenced divs, pandoc can't access that.restore_block2()parse_fig_labelsrun inresolve_refs_htmlConflicts
latex-divs.luain Rmarkdown. There is conflict.Current status
Something like this should work for now in this draft PR. It is not perfect but it is a start.
There are a lot of things to check because of how things works currently:
I'll keep working on this to make it work, and we can discuss the different choices here
Must do
- new testthat snapshoting may help hereThis will be a future project to useexpect_snapshot