tex.lua 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. local M = {}
  2. M.config = function()
  3. O.lang.latex = {
  4. filetypes = { "tex", "bib" },
  5. aux_directory = nil,
  6. bibtex_formatter = "texlab",
  7. diagnostics_delay = 300,
  8. formatter_line_length = 80,
  9. latex_formatter = "latexindent",
  10. build = {
  11. executable = "latexmk",
  12. args = { "-pdf", "-interaction=nonstopmode", "-synctex=1", "%f" },
  13. on_save = false,
  14. forward_search_after = false,
  15. },
  16. chktex = {
  17. on_open_and_save = false,
  18. on_edit = false,
  19. },
  20. forward_search = {
  21. executable = nil,
  22. args = {},
  23. },
  24. latexindent = {
  25. ["local"] = nil,
  26. modify_line_breaks = false,
  27. },
  28. diagnostics = {
  29. virtual_text = { spacing = 0, prefix = "" },
  30. signs = true,
  31. underline = true,
  32. },
  33. auto_save = false,
  34. ignore_errors = {},
  35. }
  36. end
  37. M.format = function()
  38. -- TODO: implement formatter for language
  39. return "No formatter available!"
  40. end
  41. M.lint = function()
  42. -- TODO: implement linters (if applicable)
  43. return "No linters configured!"
  44. end
  45. M.lsp = function()
  46. if require("lv-utils").check_lsp_client_active "texlab" then
  47. return
  48. end
  49. local preview_settings = {}
  50. local sumatrapdf_args = { "-reuse-instance", "%p", "-forward-search", "%f", "%l" }
  51. local evince_args = { "-f", "%l", "%p", '"code -g %f:%l"' }
  52. local okular_args = { "--unique", "file:%p#src:%l%f" }
  53. local zathura_args = { "--synctex-forward", "%l:1:%f", "%p" }
  54. local qpdfview_args = { "--unique", "%p#src:%f:%l:1" }
  55. local skim_args = { "%l", "%p", "%f" }
  56. if O.lang.latex.forward_search.executable == "C:/Users/{User}/AppData/Local/SumatraPDF/SumatraPDF.exe" then
  57. preview_settings = sumatrapdf_args
  58. elseif O.lang.latex.forward_search.executable == "evince-synctex" then
  59. preview_settings = evince_args
  60. elseif O.lang.latex.forward_search.executable == "okular" then
  61. preview_settings = okular_args
  62. elseif O.lang.latex.forward_search.executable == "zathura" then
  63. preview_settings = zathura_args
  64. elseif O.lang.latex.forward_search.executable == "qpdfview" then
  65. preview_settings = qpdfview_args
  66. elseif O.lang.latex.forward_search.executable == "/Applications/Skim.app/Contents/SharedSupport/displayline" then
  67. preview_settings = skim_args
  68. end
  69. require("lspconfig").texlab.setup {
  70. cmd = { DATA_PATH .. "/lspinstall/latex/texlab" },
  71. on_attach = require("lsp").common_on_attach,
  72. handlers = {
  73. ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
  74. virtual_text = O.lang.latex.diagnostics.virtual_text,
  75. signs = O.lang.latex.diagnostics.signs,
  76. underline = O.lang.latex.diagnostics.underline,
  77. update_in_insert = true,
  78. }),
  79. },
  80. filetypes = { "tex", "bib" },
  81. settings = {
  82. texlab = {
  83. auxDirectory = O.lang.latex.aux_directory,
  84. bibtexFormatter = O.lang.latex.bibtex_formatter,
  85. build = {
  86. args = O.lang.latex.build.args,
  87. executable = O.lang.latex.build.executable,
  88. forwardSearchAfter = O.lang.latex.build.forward_search_after,
  89. onSave = O.lang.latex.build.on_save,
  90. },
  91. chktex = {
  92. onEdit = O.lang.latex.chktex.on_edit,
  93. onOpenAndSave = O.lang.latex.chktex.on_open_and_save,
  94. },
  95. diagnosticsDelay = O.lang.latex.diagnostics_delay,
  96. formatterLineLength = O.lang.latex.formatter_line_length,
  97. forwardSearch = {
  98. args = preview_settings,
  99. executable = O.lang.latex.forward_search.executable,
  100. },
  101. latexFormatter = O.lang.latex.latex_formatter,
  102. latexindent = {
  103. modifyLineBreaks = O.lang.latex.latexindent.modify_line_breaks,
  104. },
  105. },
  106. },
  107. }
  108. vim.g.vimtex_compiler_method = "latexmk"
  109. vim.g.vimtex_view_method = "zathura"
  110. vim.g.vimtex_fold_enabled = 0
  111. vim.g.vimtex_quickfix_ignore_filters = O.lang.latex.ignore_errors
  112. O.plugin.which_key.mappings["t"] = {
  113. name = "+Latex",
  114. c = { "<cmd>VimtexCompile<cr>", "Toggle Compilation Mode" },
  115. f = { "<cmd>call vimtex#fzf#run()<cr>", "Fzf Find" },
  116. i = { "<cmd>VimtexInfo<cr>", "Project Information" },
  117. s = { "<cmd>VimtexStop<cr>", "Stop Project Compilation" },
  118. t = { "<cmd>VimtexTocToggle<cr>", "Toggle Table Of Content" },
  119. v = { "<cmd>VimtexView<cr>", "View PDF" },
  120. b = { "<cmd>TexlabBuild<cr>", "Build with Texlab" },
  121. p = { "<cmd>TexlabForward<cr>", "Preview with Texlab" },
  122. }
  123. -- Compile on initialization, cleanup on quit
  124. vim.api.nvim_exec(
  125. [[
  126. augroup vimtex_event_1
  127. au!
  128. au User VimtexEventQuit call vimtex#compiler#clean(0)
  129. au User VimtexEventInitPost call vimtex#compiler#compile()
  130. augroup END
  131. ]],
  132. false
  133. )
  134. if O.lang.latex.auto_save then
  135. vim.api.nvim_exec([[au FocusLost * :wa]], false)
  136. end
  137. end
  138. M.dap = function()
  139. -- TODO: implement dap
  140. return "No DAP configured!"
  141. end
  142. return M