Quarto: `.content-visible` and `AND` checking of multiple profiles - r-markdown

I would like to do something like:
::: {.content-visible when-profile="profileA"}
Some Content
:::
BUT checking for an AND combination of profile A & B, meaning that "Some Content" only is rendered when both profileA and profileB are active.
Both of these do not currently work:
Dual when-profile arguments:
::: {.content-visible when-profile="profileA" when-profile="profileB"}
Some Content
:::
Array of profiles:
::: {.content-visible when-profile=["profileA", "profileB"]}
Some Content
:::
Any ideas on how to do this more concisely then the working
:::: {.content-visible when-profile="profileA"}
::: {.content-visible when-profile="profileB"}
Some Content
:::
::::

Related

Adding classes to headers with a Pandoc lua filter

I'm putting together a Quarto template for Springer Nature journals. The LaTeX document class has some frustrating aspects that I'm trying to circumvent with lua filters so the template can be used as much as possible with vanilla markdown. One such filter (inspired by this discussion) takes any heading with the class {.backmatter} and for the PDF format, uses \bmhead* instead of \section; this bit works as expected:
local backmatter_inserted = false
function Header(el)
if quarto.doc.isFormat("pdf") then
if not backmatter_inserted and el.classes:includes("backmatter") then
backmatter_inserted = true
el.content = pandoc.utils.stringify(el.content)
return {
pandoc.RawBlock('tex', '\\backmatter'),
pandoc.RawBlock('tex', '\\bmhead*{' .. el.content .. '}')
}
elseif el.classes:includes("backmatter") then
el.content = pandoc.utils.stringify(el.content)
return pandoc.RawBlock('tex', '\\bmhead*{' .. el.content .. '}')
end
elseif quarto.doc.isFormat("html") and el.classes:includes("backmatter") then
el.classes:insert("appendix")
el.classes:insert("unnumbered")
return el
end
end
However, the HTML portion of the filter does not appear to be working as intended. For the HTML output, I'd like to tuck content under these headings away unnumbered in the appendix, e.g. by adding the classes "appendix" and "unnumbered". Neither of these classes currently appear to be added when running this filter.
I tried adding the classes in the md input and it works as expected, with the heading appearing in the appendix unnumbered:
# Heading {.backmatter .unnumbered .appendix}
Sample text
Running pandoc native, this appears as:
Header
3
( "heading" , [ "backmatter" , "unnumbered" , "appendix" ] , [] )
[ Str "Heading" ]
With only {.backmatter} as an input class and running the filter, it appears as:
Header
3
( "heading" , [ "backmatter" ] , [] )
[ Str "Heading" ]
I've read somewhere about a change in handling of Pandoc for section classes: am I missing something here?

Bookdown - Reference tag from another math environment broken

It seems i can't reference equations, lemas, etc when inside math.
In the following example the tag eq:test cant be referenced inside the align, but it works fine outside.
---
title: "Test"
site: bookdown::bookdown_site
documentclass: article
---
If
\begin{equation}
A = B
(\#eq:test)
\end{equation}
then
\begin{align*}
A \ &= B &&, \text{ by } \#ref(eq:test) \\ % this will not work
&= C
\end{align*}
But here \#ref(eq:test) it works.
I want to know if this is currently not possible or i'm missing some special notation to make it work.
Try with latex command \label{} and \eqref{}.
\label, \eqref works smoothly for pdf output as expected. For html output, we need to configure the Tex component of mathjax through the tex block as instructed here.
---
title: "Test"
output:
bookdown::pdf_document2:
documentclass: article
bookdown::html_document2: default
---
```{=html}
<script>
MathJax = {
tex: {
tags: 'all'
}
};
</script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax#3/es5/tex-chtml.js"></script>
```
If
\begin{equation}
A = B \label{test-eq1}
\end{equation}
then
\begin{align*}
A \ &= B &&, \text{ by } \eqref{test-eq1} \\
&= C
\end{align*}
But here \eqref{test-eq1} it works.
pdf output
html output

Quarto: .content-visible div dependent on params?

Using quarto, I'd like to do something like:
---
params:
show_private_info: true
---
::: {.content-visible <ARGUMENT TESTING FOR `params$show_private_info`>}
Some private information
:::
Is that feasible?
Clearly something can be whipped up using an asis (r) code block cating out the markdown, with eval dependent on params$show_private_info, but I'd like to avoid that detour if possible ...
Answered here as follows:
`r if (params$show_private_info) "::: {.content-hidden}"`
Some private information
`r if (params$show_private_info) ":::"`
with the additional recommendation to explicitly solve this by use of actual profiles instead.

Change default behavior of callout blocks in Quarto

In Quarto, I'd like to change the default behavior of a single callout block type so that it will
always automatically have the same caption (e.g. "Additional Resources")
always be folded (collapse="true")
Let's say I want this for the tip callout block type while the others (note, warning, caution, and important) should not be affected.
In other words, I want the behavior/output of this:
:::{.callout-tip collapse="true"}
## Additional Resources
- Resource 1
- Resource 2
:::
by only having to write this:
:::{.callout-tip}
- Resource 1
- Resource 2
:::
Update:
I have actually converted the following lua filter into a quarto filter extension collapse-callout, which allows specifying default options for specific callout blocks more easily. See the github readme for detailed instructions on installation and usage.
As #stefan mentioned, you can use pandoc Lua filter to do this more neatly.
quarto_doc.qmd
---
title: "Callout Tip"
format: html
filters:
- custom-callout.lua
---
## Resources
:::{.custom-callout-tip}
- Resource 1
- Resource 2
:::
## More Resources
:::{.custom-callout-tip}
- Resource 3
- Resource 4
:::
custom-callout.lua
local h2 = pandoc.Header(2, "Additional Resources")
function Div(el)
if quarto.doc.isFormat("html") then
if el.classes:includes('custom-callout-tip') then
local content = el.content
table.insert(content, 1, h2)
return pandoc.Div(
content,
{class="callout-tip", collapse='true'}
)
end
end
end
Just make sure that quarto_doc.qmd and custom-callout.lua files are in the same directory (i.e. folder).
After a look at the docs and based on my experience with customizing Rmarkdown I would guess that this requires to create a custom template and/or the use of pandoc Lua filters.
A more lightweight approach I used in the past would be to use a small custom function to add the code for your custom callout block to your Rmd or Qmd. One drawback is that this requires a code chunk. However, to make your life a bit easier you could e.g. create a RStudio snippet to add a code chunk template to your document.
---
title: "Custom Callout"
format: html
---
```{r}
my_call_out <- function(...) {
cat(":::{.callout-tip collapse='true'}\n")
cat("## Additional Resources\n")
cat(paste0("- ", ..., collapse = "\n\n"))
cat("\n:::\n")
}
```
```{r results="asis"}
my_call_out(paste("Resource", 1:2))
```
Blah blah
```{r results="asis"}
my_call_out("Resource 3", "Resource 4")
```
Blah blah

Yesod Mform and hamlet

Hi I am new to yesod and following the documentation to make a form. In the documentation the form template was created in .hs file itself. But I have a separate hamlet where I want to customize.
I want to access "fields" in my hamlet file. The expected type of 'generateFormPost' is (xml, Enctype) . Can anybody tell me what I should be returning from 'tableMform extra' . I think it should be in xml format. But I think I should not be using toWidget as in below example of documentation.
tableMform extra = do
fields <- forM lis (\(w,h) -> mopt intField "this is not used" (Just h) )
return (fields) ---I know this line has the type error. Can anybody suggest how to deal with it
{-
--I am referring this code from yesod website to make my form. In this it was using runFormGet, but I want use generateFormPost and moreover it was creating a widget which is used in displaying the website. I don't want to create the widget here but in my hamlet file where the 'fields' is accessed via interpolation.
personForm :: Html -> MForm Handler (FormResult Person, Widget)
personForm extra = do
(nameRes, nameView) <- mreq textField "this is not used" Nothing
(ageRes, ageView) <- mreq intField "neither is this" Nothing
let personRes = Person <$> nameRes <*> ageRes
let widget = do
toWidget
[lucius|
##{fvId ageView} {
width: 3em;
}
|]
[whamlet|
#{extra}
<p>
Hello, my name is #
^{fvInput nameView}
\ and I am #
^{fvInput ageView}
\ years old. #
<input type=submit value="Introduce myself">
|]
return (personRes, widget)
-}
getHomeR :: Handler Html
getHomeR = defaultLayout $ do
-- Generate the form to be displayed
(fields, enctype) <- generateFormPost tableMform
let (fires,fiview) = unzip fields
$(widgetFile "layout")
|]
Please let me know if there is any misunderstanding. I have idea of how to get the form from the way done in the documentation, but I want to use a separate hamlet file, as I want to customize the look of the form.
Thanks
Sai
EDIT:
Sorry, I wasn't clear. I was trying to make a Mform where instead of creating the layout of the form in the ".hs" file , I wanted to give the layout in hamlet file. I have done it through http://pastebin.com/fwpZsKXy . But after doing that I could split it in to two files as I wanted. I have solved those errors. Thanks anyways
I got it. I was not clear of what "tableMform extra" has to return. I know that it has to return something of type [(FormResult a, xml)][1] . But then I was not sure what the type of "forM lis ((w,h) -> mopt intField (fromString w) (Just h) )" -- Line 2 was , So I followed what was done in documentation did it in the way it was done there.(without use of external widget file) .
After doing that I tried to do in the way I wanted to do i.e using a separate hamlet, julius and lucius files. http://pastebin.com/FgGph2CU . It worked !!
In summary I wasn't clear of the 'type' of "forM lis ((w,h) -> mopt intField (fromString w) (Just h) )" . Once I figured that out, it was easy.