As I understand it, when one specifies parts in the _toc.yml file, then renumbering of chapters happens at each part. Is there any way to disable that feature? I'd like for chapter numbering to continue ordinally, using parts as just a benign separator among the chapters.
What I have is:
# Table of content
# Learn more at https://jupyterbook.org/customize/toc.html
#
format: jb-book
root: intro
options:
numbered: True
chapters:
- file: FOUNDATION
parts:
- caption: Foundations
numbered: True
chapters:
- file: e_and_m/J-140_Maxwell_3_S0
sections:
- file: e_and_m/J-140_Maxwell_3_S1
- file: e_and_m/J-140_Maxwell_3_S2
- file: e_and_m/J-140_Maxwell_3_S3
- file: e_and_m/J-140_Maxwell_3_S9
- file: e_and_m/J-140_Maxwell_3_S11
- caption: Relativity
numbered: True
chapters:
- file: relativity/Special Relativity_1_1_VSC
- file: relativity/Special Relativity_2_1
- file: relativity/Special Relativity_3_1
- file: relativity/Special Relativity_4_1
So, J-140_Maxwell_3_S_0 is chapter 1 and Special Relativity_1_1_VSC is also chapter 1.
OR:
I could accomplish the same thing I guess, if I could include new chapters called Foundations.md and Relativity.md but exclude them from numbering. Can I do that as an alternative?
thanks
Related
I am creating a quarto book project in RStudio to render an html document.
I need to specify some parameters in the yml file but the qmd file returns
"object 'params' not found". Using knitR.
I use the default yml file where I have added params under the book tag
project:
type: book
book:
title: "Params_TEst"
author: "Jane Doe"
date: "15/07/2022"
params:
pcn: 0.1
chapters:
- index.qmd
- intro.qmd
- summary.qmd
- references.qmd
bibliography: references.bib
format:
html:
theme: cosmo
pdf:
documentclass: scrreprt
editor: visual
and the qmd file looks like this
# Preface {.unnumbered}
This is a Quarto book.
To learn more about Quarto books visit <https://quarto.org/docs/books>.
```{r}
1 + 1
params$pcn
When I render the book, or preview the book in Rstudio the error I receive is:
Quitting from lines 8-10 (index.qmd)
Error in eval(expr, envir, enclos) : object 'params' not found
Calls: .main ... withVisible -> eval_with_user_handlers -> eval -> eval
I have experimented placing the params line in the yml in different places but nothing works so far.
Could anybody help?
For multi-page renders, e.g. quarto books, you need to add the YAML to each page, not in the _quarto.yml file
So in your case, each of the chapters that calls a parameter needs a YAML header, like index.qmd, intro.qmd, and summary.qmd, but perhaps not references.qmd.
The YAML header should look just like it does in a standard Rmd. So for example, your index.qmd would look like this:
---
params:
pcn: 0.1
---
# Preface {.unnumbered}
This is a Quarto book.
To learn more about Quarto books visit <https://quarto.org/docs/books>.
```{r}
1 + 1
params$pcn
But, what if you need to change the parameter and re-render?
Then simply pass new parameters to the quarto_render function
quarto::quarto_render(input = here::here("quarto"), #expecting a dir to render
output_format = "html", #output dir is set in _quarto.yml
cache_refresh = TRUE,
execute_params = list(pcn = 0.2))
For now, this only seems to work if you add the parameters to each individual page front-matter YAML.
If you have a large number of pages and need to keep parameters centralized, a workaround is to run a preprocessing script that replaces the parameters in all pages. To add a preprocessing script, add the key pre-render to your _quarto.yml file. The Quarto website has detailed instructions.
For example, if you have N pages named index<N>.qmd, you could have a placeholder in the YML of each page:
---
title: This is chapter N
yourparamplaceholder
---
Your pre-render script could replace yourparamplaceholder with the desired parameters. Here's an example Python script:
for filename in os.listdir(dir):
if filename.endswith(".qmd"):
with open(filename, "r") as f:
txt = f.read()
f.replace('yourparamplaceholder', 'params:\n\tpcn: 0.1\n\tother:20\n')
with open(filename, "w") as ff:
ff.write(txt)
I agree with you that being able to set parameters centrally would be a good idea.
The command line is showing me the following error in the config.yml file:
did not find expected '-' indicator while parsing a block collection at line 101 column 3 (Psych::SyntaxError)
I tried to unindent everything and indent it again with spaces but the problem persists.
Here is my code:
name: "SITENAME | Official Website"
description: "SOME DESCRIPTION"
# url: SOME URL
sass:
sass_dir: _sass
style: compressed
author:
name: "AUTHOR'S NAME"
social-network-links:
rss: true
facebook: "FB"
twitter: "TW"
linkedin: "LI"
# Select which share links to show in posts
share-links-active:
twitter: true
facebook: true
linkedin: true
# Facebook App ID (for Ads)
# fb_app_id: ""
# Excerpt Word Length
# Truncates the excerpt to the specified number of words on the index page
excerpt_length: 40
# Ruby Date Format
date_format: "%B %-d, %Y"
# --- Comments --- #
# Disqus shortname (NOT userid)
comments:
provider: "disqus"
disqus:
shortname: "SHORTNAME"
# --- Web Statistics Section --- #
google_analytics: "GA"
# Google Tag Manager ID
gtm: "GTM"
# Output options (more information on Jekyll's site)
timezone: "Europe/Berlin"
markdown: kramdown
highlighter: rouge
permalink: /:year-:month-:day-:title/
paginate: 5
kramdown:
input: GFM
# Default YAML values
defaults:
-
scope:
path: ""
type: "posts"
values:
layout: "post"
comments: true # add comments to all blog posts
social-share: true # add social media sharing buttons to all blog posts
-
scope:
path: "" # all files
values:
layout: "page"
comments: false
# Use tags index page and make tags on each post clickable
link-tags: true
# Exclude these files from production site
exclude:
- CHANGELOG.md
- CNAME
- Gemfile
- Gemfile.lock
- LICENSE
- README.md
- .jekyll-cache
plugins:
- jekyll-feed ******THIS IS THE LINE 101*********
- jekyll-archives
- jekyll-sitemap
I read many threads about this very problem but I can't figure it out. I must say that this is my first config.yml file and I might be missing something easy.
Thanks in advance for your highly appreciated help!
I am looking for a way to dynamically set the key using the path of the file below.
For example if I have this YAML:
prospectors.config:
- fields:
queue_name: <somehow get the globbed string below in here>
paths:
- /var/log/casino/*.log
type: log
output.redis:
hosts:
- "producer:6379"
key: "%{[fields.queue_name]}"
And then I had a file called /var/log/casino/test.log, then key would become test.
Im not sure that what you want is possible.
You could use the source field and configure your Redis output using that as the key:
output.redis:
hosts:
- "producer:6379"
key: "%{source}"
This would have the disadvantage of being the absolute path of the source file, not the basename as your question asks for.
If you have a small number of possible basename patterns, and want a queue for each. For example, you have files:
/common/path/test-1.log
/common/path/foo-0.log
/common/path/01-bar.log
/common/path/test-3.log
...
and wanted to have three queues in redis test, foo and bar you could use the source field and the conditionals available in the keys configuration of redis output something like this
output.redis:
hosts:
- "producer:6379"
key: "default_key"
keys:
- key: "test_key"
when.contains:
source: "test"
- key: "foo_key"
when.contains:
source: "foo"
- key: "bar_key"
when.contains:
source: "bar"
I want to have a multi-line bit of markdown java in a yam file. I tried many things but I guess I don't quite get the quoting rules of Yaml.
{
title: Museum,
body: |
"```java
code code code
java2",
answers: [
"`museum`",
"`museum.getFloor(3)`",
"`museum.getFloor(3).getExhibit(5)`",
"`museum.getFloor(3).getExhibit(5).getCurator()`",
"`museum.getFloor(3).getExhibit(5).getCurator().name`",
"`museum.getFloor(3).getExhibit(5).getCurator().name.toUpper()`"
]
}
Produces:
/Users/pitosalas/.rbenv/versions/2.3.1/lib/ruby/2.3.0/psych.rb:377:in `parse': (generator/test.yml): found character that cannot start any token while scanning for the next token at line 3 column 9 (Psych::SyntaxError)
YAML has two styles: the JSON like flow style and the much better human readable block style.
Roughly speaking you can have nested structures each style nested within itself and can have flow style nested within block style, but block style nested within flow style is not allowed.
Your to level { and } are flow style but you try to introduce, with |, a literal block style scalar within that flow style. Replace the flow style with block style upwards from that scalar:
title: Museum
body: |
"```java
code code code
java2"
answers: [
"`museum`",
"`museum.getFloor(3)`",
"`museum.getFloor(3).getExhibit(5)`",
"`museum.getFloor(3).getExhibit(5).getCurator()`",
"`museum.getFloor(3).getExhibit(5).getCurator().name`",
"`museum.getFloor(3).getExhibit(5).getCurator().name.toUpper()`"
]
and your YAML is fine. Note that the double quotes "around" the value for the key body are not going to be stripped when loading, maybe that is not what you intended.
You should IMO not leave out the trailing , after the last value in the (flow style) sequence that is the value for answers. This will certainly lead to errors when you extend the list and forget to put in the trailing comma on the line above.
I would personally go for block style all the way:
title: Museum
body: |
"```java
code code code
java2"
answers:
- "`museum`"
- "`museum.getFloor(3)`"
- "`museum.getFloor(3).getExhibit(5)`"
- "`museum.getFloor(3).getExhibit(5).getCurator()`"
- "`museum.getFloor(3).getExhibit(5).getCurator().name`"
- "`museum.getFloor(3).getExhibit(5).getCurator().name.toUpper()`"
When dealing with YAML file generation that is convoluted or complex, or when it's not working as I expect, I revert to letting Ruby show me the way:
require 'yaml'
body = <<EOT
"```java
code code code
java2
"
EOT
answers = %w(
`museum`
`museum.getFloor(3)`
`museum.getFloor(3).getExhibit(5)`
`museum.getFloor(3).getExhibit(5).getCurator()`
`museum.getFloor(3).getExhibit(5).getCurator().name`
`museum.getFloor(3).getExhibit(5).getCurator().name.toUpper()`
)
obj = {
"title" => "Museum",
"body" => body,
"answers" => answers
}
puts obj.to_yaml
Which, in this case, outputs:
---
title: Museum
body: |
"```java
code code code
java2
"
answers:
- "`museum`"
- "`museum.getFloor(3)`"
- "`museum.getFloor(3).getExhibit(5)`"
- "`museum.getFloor(3).getExhibit(5).getCurator()`"
- "`museum.getFloor(3).getExhibit(5).getCurator().name`"
- "`museum.getFloor(3).getExhibit(5).getCurator().name.toUpper()`"
If you then pass that YAML back into the parser, you should get the original data structure back:
YAML.load(obj.to_yaml)
# => {"title"=>"Museum",
# "body"=>"\"```java\n" +
# "code code code\n" +
# "java2\n" +
# "\"\n",
# "answers"=>
# ["`museum`",
# "`museum.getFloor(3)`",
# "`museum.getFloor(3).getExhibit(5)`",
# "`museum.getFloor(3).getExhibit(5).getCurator()`",
# "`museum.getFloor(3).getExhibit(5).getCurator().name`",
# "`museum.getFloor(3).getExhibit(5).getCurator().name.toUpper()`"]}
Ok so by the following yaml definition, shouldn't only what's in between {blah} and {!blah} get text.html.basic syntax highlighting? And the {blah} tags themselves take the highlighting of a comment? Unfortunately it's not happening that way. HTML highlighting is anywhere in the document, and {blah} doesn't get comment highlighting.
# [PackageDev] target_format: plist, ext: tmLanguage
---
name: Test
scopeName: source.test
fileTypes: [test]
uuid: 3631aac6-ee25-4ec1-ab08-39f156235363
patterns:
- name: comment.number-sign
begin: \{blah\}
end: \{\!blah\}
patterns:
- include: text.html.basic
match: .
...
Sample Code:
{blah}
<input type="text"/>
{!blah} <----- these are not styled according to comment.number-sign
<input type="text"/> <----- this also has HTML highlighting and I don't want it to
This should get you started:
# [PackageDev] target_format: plist, ext: tmLanguage
name: Test
scopeName: source.test
fileTypes: [test]
uuid: 3631aac6-ee25-4ec1-ab08-39f156235363
patterns:
- name: html.test
begin: (\{blah\})
beginCaptures:
'1': {name: comment.blah.test}
end: (\{!blah\})
endCaptures:
'1': {name: comment.blah.test}
patterns:
- include: text.html.basic
The name is the base scope for the entire selector. beginCaptures and endCaptures assign the comment.blah.test scope to the {blah} tags, while the include rule assigns HTML highlighting to whatever is between the begin and end tags.
Using the Neon Color Scheme (full disclosure: I'm its maintainer), a sample file looks like this:
As you can see, {blah} and {!blah} are in gray italics, the comment scope. Markup outside the {blah} tags is not highlighted at all, while that enclosed in the {blah} tags is highlighted as HTML.
For more on syntax definitions, check the tutorial and the reference at the unofficial docs.