Aligning the URL number with the page number for xaringan presentation

In terms of navigating a long xaringan presentation, is it possible to create custom URLs in xaringan so that the slide number in the URL matches the page number displayed?

For example, here's a slide from a xaringan presentation on xaringan, from last year's rstudio::conf. The page number displayed is "41/91", but the URL displayed is "https://arm.rbind.io/slides/xaringan.html#76".

The reason the numbers don't match is because each transition on a new slide currently gets a new number. What I really want is to be able to go to the 41st slide of a xaringan deck by typing #41 after the URL. Does anyone know how to force xaringan to do this? One possible solution: create a custom URL (https://myurl.html#30a or https://myurl.html#30#a) for in-between slides?

I assume that this feature isn't yet in xaringan, but I could be missing something!

Yes! There is an option countIncrementalSlides that when TRUE the displayed number for each slide is incremented with each new slide, regardless of whether or not it is incremental.

For the exact same reason as you, I always set this in the YAML header for my xaringan slides:

output:
  xaringan::moon_reader:
    nature:
      countIncrementalSlides: true
      slideNumberFormat: "%current%"

I also usually add the slideNumberFormat: "%current%" to make sure that only the current slide number is shown to avoid audience anxiety when they see Slide 10 of 130.

(I copied my answer from the github issue where I first saw the question.)

2 Likes

I'm realizing now that another answer to your question is "No, there's not a way". In remarkjs (thus xaringan), every transition is an entirely new slide, including incremental slides.

For example, if you have an incremental slide with two bullet points

* Point One

--

* Point Two

creates two slides and is more or less equivalent to

* Point One

---

* Point One

* Point Two

It's not possible to have remarkjs come up with a different index for the slides. In other words, the two slides above will always be #n and #n+1. The best you can do is

  1. Align the displayed number with the slide index (see above)

  2. Give the first slide a meaningful name so you can jump to it

If you give an incremental slide a name, you can jump to it with #<slide-name>.

name: my-points

* Point One

--

* Point Two

And then you can jump to the start of this slide "group" by adding #my-points after the URL. It will automatically take you to the first slide of the incremental group. This has the extra benefit of being easier to remember, e.g. I have section on JSON in my slides that I can get to by adding #json to the URL. You can also have links in your slides to jump to those places.