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 out cross-references #1

Open
hadley opened this issue May 18, 2020 · 8 comments
Open

Figure out cross-references #1

hadley opened this issue May 18, 2020 · 8 comments

Comments

@hadley
Copy link
Member

hadley commented May 18, 2020

From @jjallaire

(1) Inherit from bookdown::html_document2()

(2) Call the helper function I asked Yihui to put in so I could support cross-references in distill

(3) Look at the code of that function and just do it yourself (that might be the best bet although I haven't actually looked at the code recently so don't recall how trivial or non-trivial it is)

@maelle
Copy link
Contributor

maelle commented May 22, 2020

Does Hugo's cross-reference stuff help at all? https://gohugo.io/content-management/cross-references/

@hadley
Copy link
Member Author

hadley commented May 22, 2020

@maelle I don't think so, because we want RMarkdown cross-references.

@hadley
Copy link
Member Author

hadley commented Jun 2, 2020

Need this in hugo_document() setup:

  # Trick knitr into producing bookdown labels
  knitr$opts_knit$bookdown.internal.label <- TRUE

But is cross-linking worth it? Unlike bookdown, this only allows links within the current doc, which is primarily useful for floating figures, and the current syntax highlighting isn't designed for floating figures (since everything is wrapped in a <div>)


Test file:

---
output: hugo_document
---

```{r test, fig.cap = "This is a caption"}
plot(1:5, 1:5)
```

See Figure \@ref(fig:test).

@maelle
Copy link
Contributor

maelle commented Jun 3, 2020

Probably off-topic because too centered on Hugo/html (and on rOpenSci website knitr plot hook) and because I'm assuming linking to figures might be useful even if they're not floating. Is hugodown plot hook outputting html? If it were outputting a Hugo figure shortcode or even the same figure html as what Hugo shortcode would produce (which has the benefit of having separate title, caption and alt text), the title part of that html could be used as a Markdown link. In Hugo academic there's a custom figure shortcode that includes an id HugoBlox/hugo-blox-builder#1475

@hadley
Copy link
Member Author

hadley commented Jun 3, 2020

hugodown produces html; I can make it produce whatever is needed, but this part of the code is already quite hacky so I'd prefer to avoid adding to it unless there is an existing compelling use case (i.e. you can point me to blog posts where you already use this technique).

@maelle
Copy link
Contributor

maelle commented Jun 3, 2020

we use Hugo shortcode as a knitr plot hook (in some of the most recent posts, in the archetype https://github.com/ropensci/roweb2/blob/master/archetypes/Rmd/index.md -- called .md for use with Hugo/blogdown addin but it's Rmd), but not for the cross-reference aspect, it was because I couldn't think of another way to let post authors tweak image width/position, caption and alt text on a per chunk basis -- which minus the different caption/alt seems to already work with hugodown as is. So no compelling use case on the cross-reference aspect and I'll stop the off-topic commenting. 🙂

@apreshill
Copy link
Collaborator

Also chiming in even though no one asked, I do not find the cross-references across posts important and have never used them in 3 years of using Hugo via blogdown. What I do like and use is:

  • figure numbering within a single post, and

  • linking to specific figures/tables in text within the same post.

@danmackinlay
Copy link

FWIW I have a total of 3834 links between posts across the 735 pages of the site I manage (pace @apreshill ) and a total 54 links within a single post, so across two data points we have two different internal linking tendencies. Importance weighting these data points is left as an exercise 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants