Skip to content

Visual Editor renaming footnote references breaks order when using multiple children Rmd #10078

Closed

Description

@Dijkie85

System details

RStudio Edition : Server
RStudio Version : 2021.09.0+351 (Ghost Orchid) for Ubuntu Bionic
OS Version      :  WSL2 running under Windows 10 21H1
R Version       :  4.1.2

Steps to reproduce the problem

(1) Create 3 files with the following code:

index.Rmd:

---
title: "Example"
lang: es
toc: false
numbersections: false
documentclass: article
output: 
  bookdown::pdf_document2:
    latex_engine: xelatex
    includes:
    keep_tex: false
---

```{r child=c('01.Rmd', '02.Rmd')}

```

01.Rmd:

# File 1

Text 1[^first]

[^first]: First footnote

02.Rmd:

# File 2

Text 2[^second]

[^second]: Second footnote

(2) Edit both 01.Rmd and 02.Rmd in Visual Editor, and then go back to source editor. You'll find both footnotes are renamed to [^1] in both files (since it's the first --and only-- footnote in each file). So when knit compiles index.Rmd and processes both children, you get the duplicate footnote warning (and only the second footnote in the PDF output), as they're both named the same.

Describe the problem in detail

When editing an Rmd file in visual mode, footnotes are renamed consecutively to [^1], [^2], [^n]. That happens for every file, without regard for others. So, when each file is a child of an index.Rmd, the latter footnotes override the former.

Describe the behavior you expected

Each footnote in each file should have a unique name, so as not to overlap with other children. An easy solution would be to use the filename as a prefix for the footnotenumber, so that footnotes in 01.Rmd are ordered as [^01-1]... [^01-n], while those in 02.Rmd should be `[^02-1]... [^02-n].

Edit: As far as I can tell, this kind of reference labelling already works within bookdown...

  • I have read the guide for submitting good bug reports.
  • I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • If I am reporting an RStudio crash, I have included a diagnostics report.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

Activity

  1. ronblum commented on Nov 15, 2021

    @ronblum
    Contributor

    @Dijkie85 Thank you for opening this up as a separate issue!

  2. added
    visual markdown
    on Nov 15, 2021
  3. jjallaire commented on Dec 4, 2021

    @jjallaire
    Member

    @Dijkie85 The best workaround for this right now is to add a reference prefix for child documents (as described here: https://rstudio.github.io/visual-markdown-editing/markdown.html#references). Note that if a child is included in more than one parent you will still get duplicate footnotes. I'm not sure there is a clean workaround for this in the visual editor unless/until Pandoc allows us to serialize footnotes differently (e.g. as inline so there are no id conflicts to worry about)

  4. Dijkie85 commented on Dec 4, 2021

    @Dijkie85
    Author

    Hi J.J., thanks for looking into this. I will check the workaround. As a suggestion, maybe the visual editor could add the prefix as a default when parsing/converting/renaming footnotes? I think bookdown, which uses multiple child documents as default, has this functionality implemented.

  5. self-assigned this
    on May 5, 2022
  6. jjallaire commented on May 6, 2022

    @jjallaire
    Member

    I've modified the visual editor here (b5b242b) to do the following:

    • Automatically add the prefix in bookdown, bookdown::html_document2 (etc), and Quarto book projects; and
    • Automatically add the prefix for any file that has no YAML front matter (i.e. included files)

    Manual overrides still exist as before, including a new value prefix: none which suppresses the automatic behavior.

  7. romainfrancois commented on May 11, 2022

    @romainfrancois
    Contributor

    btw @Dijkie85 you can use 4 backticks here if you want to show 3, I've edited the description.

  8. romainfrancois commented on May 11, 2022

    @romainfrancois
    Contributor

    With RStudio 2022.06.0-daily+385 "Spotted Wakerobin".

    A roundtrip to source/visual/source changes the files to:

    image

    image

    I believe this is because of this function:

    export function pandocAutoIdentifier(text: string, asciify: boolean) {
      if (asciify) {
        text = pandocAsciify(text);
      }
    
      return (
        text
          // Remove all non-alphanumeric characters, except underscores, hyphens, and periods.
          .replace(/[!"#$%&')*+,\/:;<=>?@\[\\\]^`{|}~]/g, '') // filterPunct
    
          // Replace all spaces with hyphens
          .replace(/\s/g, '-')
    
          // Convert all alphabetic characters to lowercase
          .toLowerCase()
    
          // Remove everything up to the first letter
          .replace(/^[^A-Za-z]+/, '')
      );
    }

    because of the last .replace() this returns "" for both files.

    The auto behavior works otherwise, if e.g. the files are renamed "child_01.Rmd" and "child_02.Rmd". They roundtrip to:

    # File 1
    
    Text 1[^child_01-1]
    
    [^child_01-1]: First footnote
    

    and

    # File 2
    
    Text 2[^child_02-1]
    
    [^child_02-1]: Second footnote
    

    and the footnotes are correct in the rendered:

    image

  9. removed their assignment
    on May 11, 2022
  10. assigned and unassigned on Jun 3, 2022
  11. ronblum commented on Jun 6, 2022

    @ronblum
    Contributor

    Verified in RStudio Desktop 2022.06.0-daily+482 on MacOS 12.5. Also switched the files to Quarto documents and verified that way, as well.

  12. victe commented on Nov 13, 2022

    @victe

    Probably you already discussed before, but I'm not finding where or when the necessity of numbering the footnotes comes. I don't think it is a good behaviour of a code editor to change markups created by the user. In this case, the footnote label could be descriptive, not a number, that is associated with a paragraph, annotation, phrase, that can be moved to another position in a file or even another file or section.
    I think this change from label to number must be, if necessary, in the render process of the file, never in the editing.
    I forbid myself the use of visual quarto with this behaviour.
    Ah! The git diff hell for these not user commanded changes is not minor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugvisual markdown

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions