Skip to content
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

Using headings with profiles in book format always shows the first heading of the file #6251

Open
mvwestendorp opened this issue Jul 17, 2023 · 7 comments
Labels
bug Something isn't working
Milestone

Comments

@mvwestendorp
Copy link

Bug description

I am using the project profiles to support multi-language documents (i.c. Dutch & French) by only showing the text for that language. This works nicely, but when trying to use the same method for headings the first heading always shows up even when it should not be shown based on the profile used.

Steps to reproduce

https://github.com/mvwestendorp/bug-heading-quarto-profile

quarto render . --profile NL renders a correct version in _report-NL
quarto render . --profile FR renders an incorrect version in _report-FR

Expected behavior

Only headings that are visible based on the project's profile are visible in the output

Actual behavior

The first heading of a file is always shown regardless of project profile

image

Your environment

  • IDE: notepad
  • Windows 10

Quarto check output

[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.1: OK
      Dart Sass version 1.55.0: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.3.433
      Path: C:\Program Files\Quarto\bin
      CodePage: 1252

[>] Checking basic markdown render....OK

[>] Checking Python 3 installation....OK
      Version: 3.11.4
      Path: C:/Program Files/Python311/python.exe
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with py -m pip install jupyter

[>] Checking R installation...........OK
      Version: 4.3.1
      Path: C:/PROGRA~1/R/R-43~1.1
      LibPaths:
        - E:/Rlibrary
        - C:/Program Files/R/R-4.3.1/library
      knitr: 1.42
      rmarkdown: 2.21

[>] Checking Knitr engine render......OK
@mvwestendorp mvwestendorp added the bug Something isn't working label Jul 17, 2023
@cderv
Copy link
Collaborator

cderv commented Jul 18, 2023

I think we resolve .content-visible too late to hide the header from the document and preventing the book processing to catch it.

@dragonstyle do you think this is something we should try to do better ?

I am using the project profiles to support multi-language documents (i.c. Dutch & French) by only showing the text for that language.

We have some shortcodes feature to get variables data : https://quarto.org/docs/authoring/variables.html

So providing that this works,

# {{ var chapter1 }}

You could try to leverage the _variable.yml file maybe ? https://quarto.org/docs/authoring/variables.html#var

This is not profile aware (maybe something we can do), but you could have two files (one per language) and then rename to _variable.yml using pre render script depending on the language you are rendering.

Though, you could probably leverage Metadata which are profile aware (https://quarto.org/docs/projects/profiles.html)
and still something you can call.

This would lead to

# {{ meta chapter1 }}

Just ideas to test to see if this helps.

multi-language documents (i.c. Dutch & French)

If you haven't seen it you could be interested in this thread

@cscheid
Copy link
Collaborator

cscheid commented Jul 18, 2023

I think we resolve .content-visible too late to hide the header from the document and preventing the book processing to catch it.

Yes, this is the gist of the issue. Currently, content-visible is not meant to change the "structure" of the document. Arguably, it never should, since it's meant to control format-specific features. It would be confusing if the PDF document had different chapter and section structures from the HTML document, and we should probably discourage it.

More generally, we should take some time and design precisely what steps our document processing will take at what points, and document it. Quarto would then be able to provide error messages when we see "bad" documents.

@mvwestendorp
Copy link
Author

@cderv thanks for those suggestions and pointing me to that very interesting thread!

I think I understand the remarks that this may not be a proper way to use that functionality at this time. But some sort of solution where headings can be made multilingual and contained within a single file would be beneficial I think. The argument being that it keeps all things text in the same place and there is no separate file with variables and shortcodes that make collaborating with non-coders more difficult. To illustrate, in my work context the visual editor in RStudio has lowered the barrier for non-coders to directly work in Quarto files, making it more efficient compared to having to integrate things from Word into Quarto. Getting buy-in from non-coders is a challenge and code and variables for the actual text make this harder.

Some small additional detail related to this issue: for the html output it is possible to set the ToC text for a chapter through a comment in R code. The chapter heading won't show up in the document itself (or in the ToC if the format is a pdf). I have added an example of this to the repo as well as a pdf output and as @cscheid says there seems to be some format-specificity.

@mcanouil
Copy link
Collaborator

@mvwestendorp it seems you are using knitr said the engine, have you considered using inline R expression project profile environment variable?

@mvwestendorp
Copy link
Author

@mcanouil thanks for your suggestion. Yes I use knitr indeed.
If I understand correctly, you mean something like r if(QUARTO_PROFILE == "FR") "French" else "Dutch ?
If so, it is a possibility, else I am curious to know what you mean.
I don't think an inline expression is ideal since it would still pose challenges to non-coder collaborators. Another small downside is that such heading would not show up correctly in the outline of a document in RStudio.

@mcanouil
Copy link
Collaborator

mcanouil commented Jul 20, 2023

In R you can access environment variable using Sys.getenv("QUARTO_PROFILE") so `r if (Sys.getenv("QUARTO_PROFILE") %in% "FR") "French" else "Dutch"` or fore more languages: `r switch(Sys.getenv("QUARTO_PROFILE"), "FR" = "French", "NL" = "Dutch", stop("No translation available!"))`

Using code cell1, for "complex" cases and as an example:

RPython
```{r}
#| output: asis
quarto_profile <- Sys.getenv("QUARTO_PROFILE")

text <- switch(
  EXPR = Sys.getenv("QUARTO_PROFILE"),
  "FR" = "French",
  "NL" = "Dutch",
  "Unknown profile"
)
cat(text)
```
```{python}
#| output: asis
import os

quarto_profile = os.environ.get("QUARTO_PROFILE")

if quarto_profile == "FR":
  print("French")
elif quarto_profile == "NL":
  print("Dutch")
else:
  print("Unknown profile")
```

Footnotes

  1. inline code is only for R.

@mcanouil
Copy link
Collaborator

And using 1.4 pre-release (https://quarto.org/docs/prerelease/1.4/inline.html):

  • Inline R1:

    `r if (Sys.getenv("QUARTO_PROFILE") %in% "FR") "French" else "Dutch"`
    `{r} if (Sys.getenv("QUARTO_PROFILE") %in% "FR") "French" else "Dutch"`
  • Inline Python2:

    `{python} "French" if os.environ.get("QUARTO_PROFILE") == "FR" else "Dutch"`

Footnotes

  1. via engine: knitr.

  2. via engine: jupyter. Also requires import os.

cderv added a commit that referenced this issue Sep 18, 2023
Follow up to #6251 and part of fixes for CI issues  #6871
@dragonstyle dragonstyle added this to the v1.5 milestone Nov 28, 2023
@cscheid cscheid modified the milestones: v1.5, Future Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants