0

In ioslides presentation with Rmarkdown, there is an option to enable highlight mode in each slide by pressing h. Is there some way to make the highlight mode enabled by default and disable it by pressing h.

RLesur
  • 5,810
  • 1
  • 18
  • 53
TheRimalaya
  • 4,232
  • 2
  • 31
  • 37

1 Answers1

0

There is no built-in option to enable highlight mode by default.
This comes from these lines of JavaScript: here and here.
Highlight mode is removed when the speaker changes the slide.

However, there is a hacky way to highlight each slide by default.
In your project, create a new file (named for instance highlight.html).
In this file, copy the following content:

<script type="text/javascript">
  SlideDeck.prototype.prevSlide = function(opt_dontPush) {
    if (this.curSlide_ > 0) {
      var bodyClassList = document.body.classList;
      bodyClassList.add('highlight-code');

      // Toggle off speaker notes if they're showing when we move backwards on the
      // main slides. If we're the speaker notes popup, leave them up.
      if (this.controller && !this.controller.isPopup) {
        bodyClassList.remove('with-notes');
      } else if (!this.controller) {
        bodyClassList.remove('with-notes');
      }

      this.prevSlide_ = this.curSlide_--;

      this.updateSlides_(opt_dontPush);
    }
  };

  SlideDeck.prototype.nextSlide = function(opt_dontPush) {
    if (!document.body.classList.contains('overview') && this.buildNextItem_()) {
      return;
    }

    if (this.curSlide_ < this.slides.length - 1) {
      var bodyClassList = document.body.classList;
      bodyClassList.add('highlight-code');

      // Toggle off speaker notes if they're showing when we advanced on the main
      // slides. If we're the speaker notes popup, leave them up.
      if (this.controller && !this.controller.isPopup) {
        bodyClassList.remove('with-notes');
      } else if (!this.controller) {
        bodyClassList.remove('with-notes');
      }

      this.prevSlide_ = this.curSlide_++;

      this.updateSlides_(opt_dontPush);
    }
  };
</script>

Now, modify the YAML header of the ioslides presentation:

---
title: "Highlighted"
author: "Romain Lesur"
date: "26/06/2018"
output: 
  ioslides_presentation:
    includes:
      after_body: highlight.html
---

It should do the trick.

RLesur
  • 5,810
  • 1
  • 18
  • 53