File: mathquill.R

package info (click to toggle)
r-cran-bookdown 0.32%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,664 kB
  • sloc: javascript: 11,322; makefile: 21; sh: 20
file content (36 lines) | stat: -rw-r--r-- 1,105 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
mathquill_dependency = function() {
  htmltools::htmlDependency(
    'mathquill', '0.10.1', bookdown_file('resources', 'mathquill'),
    script = c('mathquill.min.js', 'init.js'), stylesheet = 'mathquill.css'
  )
}

local({
  context = rstudioapi::getActiveDocumentContext()
  tags = htmltools::tags
  shiny::runGadget(
    miniUI::miniPage(
      miniUI::gadgetTitleBar('Input LaTeX Math Expressions'),
      htmltools::attachDependencies(
        tags$span(
          id = 'latex_input',
          context$selection[[1]]$text
        ),
        list(bookdown:::jquery_dependency(), mathquill_dependency())
      ),
      tags$p('LaTeX source:', style = 'margin: 1em auto 1em auto;'),
      tags$textarea(
        id = 'latex_source', readonly = 'readonly',
        style = 'height: 40px; min-height: 40px;'
      )
    ),
    server = function(input, output) {
      shiny::observeEvent(input$done, {
        code = input$latex_source
        if (code != '') rstudioapi::insertText(code)
        shiny::stopApp()
      })
    },
    viewer = shiny::dialogViewer('Input LaTeX Math', height = 400)
  )
})