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

Figure captions don't work for some text length with (ref:... #463

Closed
eliocamp opened this issue Jun 1, 2022 · 3 comments
Closed

Figure captions don't work for some text length with (ref:... #463

eliocamp opened this issue Jun 1, 2022 · 3 comments
Labels
bug 🐛 Something isn't working

Comments

@eliocamp
Copy link

eliocamp commented Jun 1, 2022

I'm having a very confusing issue trying to make the "(ref:caption)" syntax work. The code below is a reprex document that describes the issue.

---
title: title
output: 
  distill::distill_article: default
---


```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
Caption works with a 50 character length caption 

(ref:caption1) `r paste0(rep("a", 50), collapse = "")`

```{r , fig.cap = "(ref:caption1)"}
plot(pressure)
```

But not with 51 characters

(ref:caption2) `r paste0(rep("a", 51), collapse = "")`

```{r , fig.cap = "(ref:caption2)"}
plot(pressure)
```


Remove one character from the ref name, and now it works with 51 characters. 


(ref:caption) `r paste0(rep("a", 51), collapse = "")`

```{r , fig.cap = "(ref:caption)"}
plot(pressure)
```


But add another chacater (total of 52 characters) to the caption, and it breaks again.

(ref:kaption) `r paste0(rep("a", 52), collapse = "")`

```{r , fig.cap = "(ref:kaption)"}
plot(pressure)
```


The limit seems to be the number of character in the name and in the caption. 

And here's the output: test.html.zip

I'm using distill 1.4 and all other packages up-to-date with R 4.2.0

Infuriatingly, I cannot reproduce this behaviour on my institute server, which has R 3.6.3. But installing R 3.6.3 on my laptop does not fix it.

@eliocamp eliocamp closed this as completed Jun 1, 2022
@eliocamp eliocamp reopened this Jun 1, 2022
@cderv cderv closed this as completed in 180f9fc Jun 2, 2022
@cderv
Copy link
Collaborator

cderv commented Jun 2, 2022

Thanks for the report.

I was not aware this feature was suppose to work in distill. This is a bookdown feature, but it is indeed possible to use it within distill - I forgot.

Anyway, this feature is implement using regex and I think it breaks because of the way the HTML is wrap by default with recent Pandoc version. This is also probably why you don't get the same results on your different environment: check the pandoc version there. (version should be 2.17 or above, vs before 2.17)

I have pushed the same fix as we had in bookdown but that was not used by distill

@cderv cderv added the bug 🐛 Something isn't working label Jun 2, 2022
@eliocamp
Copy link
Author

eliocamp commented Jun 2, 2022

Oh, thanks!
Say, that autowrap thing also created some issues in rticles. If the template had a comment that had a template variable, then if the interpolation created a long string, the new line would not start with a comment and would create all sort of weird errors.

So, for example, if the template has something like this:

% \title{$title$}

And title was long, then the .tex file would be something like this

% \title{This is a very long title that pandoc will 
wrap into a new line}

and would fail.

If you like, I could open an issue in the rticles repo about this.

@cderv
Copy link
Collaborator

cderv commented Jun 2, 2022

If you like, I could open an issue in the rticles repo about this.

Yes please do.

I am thinking this should have been fixed at lower level in rmarkdown instead of in each format 🤔

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

2 participants