title: How can I add line numbers that go across chunks in Rmarkdown?
body: <p>I would like to add code line numbering to the HTML output of my Rmarkdown file. I'd be happy with any approach that <em>uniquely</em> identifies every line of code in the output (e.g., sequential line numbers that increment across the entire document, OR code chunks are identified by their own index, and within these code chunks line numbers start at 1). </p>
  
  <p>I have been unable to achieve this.</p>
  
  <p>Using other stackoverflow answers and <a href="https://blog.atusy.net/submodules/rmd-line-num/index.html" rel="nofollow noreferrer">this blog post</a> I have gotten line numbers, but they reset with every new chunk.</p>
  
  <p>I have the following Rmd file:</p>
  
  <pre><code>---
  output:
    html_document:
      highlight: kate
  ---
  
  ```{r setup, include=FALSE}
  knitr::opts_chunk$set(
    class.source = "numberLines lineAnchors"
    )
  ```
  
  ```{r}
  5 + 5
  3 * 9
  ```
  
  ```{r}
  x &lt;- 5
  x * 3
  ```
  </code></pre>
  
  <p>Which compiles to:</p>
  
  <p>As you can see, when a chunk is split by output or a new chunk begins, the line numbers reset. What I would like to see is line numbers as 1, 2, 3, 4, instead of 1, 1, 1, 2.</p>
  
  <p>Anyone know how to get this to work?
  <a href="https://i.stack.imgur.com/Xwi10.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xwi10.png" alt="line numbers reset when chunk is split or new chunk"></a></p>