tex.lua 4.1 KB

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