ropensci-review-tools / babelquarto

Renders a Multilingual Quarto Project (Book or Website)
https://docs.ropensci.org/babelquarto/
Other
40 stars 7 forks source link

Appendices with a single chapter gives an error #47

Closed truecluster closed 4 months ago

truecluster commented 5 months ago

The following YAML with only one chapter in the appendix gives an ERROR. If I move the summary as a second chapter in the appendix, it works.

project:
  type: book

book:
  site-url: "https://mysite.org"
  title: "mytitle"
  author: "myauthor"
  date: "21.6.2024"
  chapters:
    - index.qmd
    - intro.qmd
    - summary.qmd
  appendices:  
    - references.qmd

bibliography: references.bib

format:
  html:
    theme: sandstone
  pdf:
    documentclass: scrbook
    toc: true
    number-sections: true
    colorlinks: true

babelquarto:
  languagecodes:
  - name: es
    text: "Version in es"
  - name: fr
    text: "Version in fr"
  - name: en
    text: "Version in en"
  mainlanguage: 'en'
  languages: ['es', 'fr']
title-es: title in es
title-fr: title in fr
description-es: description in es
description-fr: description in fr
author-es: author in es
author-fr: author in fr
lang: en

Here the processing log:

> babelquarto::render_book(site_url = ret$url)
[1/4] index.qmd
[2/4] intro.qmd
[3/4] summary.qmd
[4/4] references.qmd

pandoc 
  to: latex
  output-file: index.tex
  standalone: true
  toc: true
  number-sections: true
  top-level-division: chapter
  pdf-engine: xelatex
  variables:
    graphics: true
    tables: true
  default-image-extension: pdf

metadata
  crossref:
    chapters: true
  documentclass: scrbook
  papersize: letter
  block-headings: true
  bibliography:
    - references.bib
  babelquarto:
    languagecodes:
      - name: es
        text: Version in es
      - name: fr
        text: Version in fr
      - name: en
        text: Version in en
    mainlanguage: en
    languages:
      - es
      - fr
  title-es: title in es
  title-fr: title in fr
  description-es: description in es
  description-fr: description in fr
  author-es: author in es
  author-fr: author in fr
  lang: en
  lang-en: 'true'
  colorlinks: true
  title: mytitle
  author: myauthor
  date: 21.6.2024

Rendering PDF
running xelatex - 1
  This is XeTeX, Version 3.141592653-2.6-0.999994 (TeX Live 2022) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode

running xelatex - 2
  This is XeTeX, Version 3.141592653-2.6-0.999994 (TeX Live 2022) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode

Output created: _book/index.html

ERROR: Project _quarto.yml validation failed.

In file _quarto.yml
(line 12, columns 15--29) Field "appendices" has value references.qmd, which must instead be an array of values, where each element must be chapter-item
11:   - summary.es.qmd
12:   appendices: references.qmd
                 ~~~~~~~~~~~~~~~
13:   description: description in es
✖ The value references.qmd is of type string.
ℹ The error happened in location book:appendices.

Stack trace:

In file _quarto.yml
(line 12, columns 15--29) Field "appendices" has value references.qmd, which must instead be an array of values, where each element must be chapter-item
11:   - summary.es.qmd
12:   appendices: references.qmd
                 ~~~~~~~~~~~~~~~
13:   description: description in es
✖ The value references.qmd is of type string.
ℹ The error happened in location book:appendices.

    at readAndValidateYamlFromFile (file:///usr/lib/rstudio/resources/app/bin/quarto/bin/quarto.js:20470:15)
    at async file:///usr/lib/rstudio/resources/app/bin/quarto/bin/quarto.js:72909:26
    at async projectContext (file:///usr/lib/rstudio/resources/app/bin/quarto/bin/quarto.js:72743:26)
    at async render (file:///usr/lib/rstudio/resources/app/bin/quarto/bin/quarto.js:81785:19)
    at async Command.fn (file:///usr/lib/rstudio/resources/app/bin/quarto/bin/quarto.js:81960:32)
    at async Command.execute (file:///usr/lib/rstudio/resources/app/bin/quarto/bin/quarto.js:8104:13)
    at async quarto (file:///usr/lib/rstudio/resources/app/bin/quarto/bin/quarto.js:115004:5)
    at async file:///usr/lib/rstudio/resources/app/bin/quarto/bin/quarto.js:115022:9
Error in `map()`:
ℹ In index: 1.
Caused by error in `quarto::quarto_render()`:
✖ Error running quarto cli.
Caused by error:
! System command 'quarto' failed
Run `rlang::last_trace()` to see where the error occurred.
maelle commented 5 months ago

Thank you for reporting this, much appreciated! :pray: It's a YAML coercion problem.

I am also realizing that if someone had translated versions of the appendices, babelquarto would not find them.

Would you mind installing babelquarto from #48 to see whether it fixes your problem? I added a test that fails on main but passes with my changes, but I'd like your confirmation.

pak::pak("ropensci-review-tools/babelquarto@appendices")
truecluster commented 5 months ago

Thanks Maelle, I still get

Error in `map()`:
ℹ In index: 1.
Caused by error in `purrr::map()`:
ℹ In index: 3.
Caused by error in `enc2utf8()`:
! argument is not a character vector
Run `rlang::last_trace()` to see where the error occurred.

which gives

> rlang::last_trace()
<error/purrr_error_indexed>
Error in `map()`:
ℹ In index: 1.
Caused by error in `purrr::map()`:
ℹ In index: 3.
Caused by error in `enc2utf8()`:
! argument is not a character vector
---
Backtrace:
     ▆
  1. └─babelquarto::render_book(site_url = ret$url)
  2.   └─babelquarto:::render(...)
  3.     └─purrr::walk(...)
  4.       └─purrr::map(.x, .f, ..., .progress = .progress)
  5.         └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
  6.           ├─purrr:::with_indexed_errors(...)
  7.           │ └─base::withCallingHandlers(...)
  8.           ├─purrr:::call_with_cleanup(...)
  9.           └─babelquarto (local) .f(.x[[i]], ...)
 10.             └─purrr::map(...)
 11.               └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
 12.                 ├─purrr:::with_indexed_errors(...)
 13.                 │ └─base::withCallingHandlers(...)
 14.                 ├─purrr:::call_with_cleanup(...)
 15.                 └─babelquarto (local) .f(.x[[i]], ...)
 16.                   └─fs::file_move(...)
 17.                     └─fs::path_expand(path)

HTH, Kind regards

maelle commented 5 months ago

could you please share your Quarto configuration file? I guess this one is an encoding problem. :sweat_smile:

truecluster commented 5 months ago

Doesn't look like an encoding issue. I could isolate the problem to

  chapters:
    - index.qmd
    - part: "First Part"
      chapters:
        - summary.qmd

where summary.qmd has not all translations available: breaks as soon as summary.es.qmd or summary.fr.qmd is missing.

maelle commented 5 months ago

@truecluster thank you!

I tried reproducing the bug with d83081f (#48)

But it does not create a bug. Could you either

Thank you for your patience and contributions!

truecluster commented 5 months ago

Here is a minimal repo with summary.fr.qmd made missing by renaming to summary.fr.qmd.txt. babeltest.zip

truecluster commented 4 months ago

Dear Maelle, could you replicate with the repo in the zip? Kind regards

maelle commented 4 months ago

@truecluster sorry for the delay and thanks for the useful reprex, I've added a commit to https://github.com/ropensci-review-tools/babelquarto/pull/48

Can you please tell me whether using babelquarto from that branch works for you?

Note that I will be away at useR! in Salzburg next week, so probably even slower than usual.