tex.lua 3.6 KB

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