-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlsp-latex.el
1423 lines (1128 loc) · 50.8 KB
/
lsp-latex.el
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; lsp-latex.el --- LSP-mode client for LaTeX, on texlab -*- lexical-binding: t; -*-
;; Copyright (C) 2019-2024 ROCKTAKEY
;; Author: ROCKTAKEY <rocktakey@gmail.com>
;; Keywords: languages, tex
;; Version: 3.9.0
;; Package-Requires: ((emacs "28.1") (lsp-mode "6.0") (consult "0.35"))
;; URL: https://github.com/ROCKTAKEY/lsp-latex
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Table of Contents
;; _________________
;; 1. lsp-mode client for Texlab.
;; 2. How to Use?
;; 3. Variables
;; .. 1. `lsp-latex-texlab-executable'
;; .. 2. `lsp-latex-texlab-executable-argument-list'
;; .. 3. Others, provided by texlab server
;; 4. Build
;; .. 1. `lsp-latex-build'
;; 5. Workspace commands
;; .. 1. `lsp-latex-clean-auxiliary'
;; .. 2. `lsp-latex-clean-artifacts'
;; .. 3. `lsp-latex-change-environment'
;; .. 4. `lsp-latex-find-environments'
;; ..... 1. `lsp-latex-complete-environment'
;; .. 5. `lsp-latex-show-dependency-graph'
;; .. 6. `lsp-latex-cancel-build'
;; 6. Commands with `lsp-latex-complete-environment'
;; .. 1. `lsp-latex-goto-environment'
;; .. 2. `lsp-latex-select-and-change-environment'
;; 7. Forward/inverse search
;; .. 1. Forward search
;; .. 2. Inverse search
;; .. 3. Examples
;; ..... 1. SumatraPDF
;; ..... 2. Evince
;; ..... 3. Okular
;; ..... 4. Zathura
;; ..... 5. qpdfview
;; ..... 6. Skim
;; ..... 7. `pdf-tools' integration
;; 8. License
;; [https://img.shields.io/github/tag/ROCKTAKEY/lsp-latex.svg?style=flat-square]
;; [https://img.shields.io/github/license/ROCKTAKEY/lsp-latex.svg?style=flat-square]
;; [https://img.shields.io/github/actions/workflow/status/ROCKTAKEY/lsp-latex/CI.yml.svg?style=flat-square]
;; [file:https://melpa.org/packages/lsp-latex-badge.svg]
;; [https://img.shields.io/github/tag/ROCKTAKEY/lsp-latex.svg?style=flat-square]
;; <https://github.com/ROCKTAKEY/lsp-latex>
;; [https://img.shields.io/github/license/ROCKTAKEY/lsp-latex.svg?style=flat-square]
;; <file:LICENSE>
;; [https://img.shields.io/github/actions/workflow/status/ROCKTAKEY/lsp-latex/CI.yml.svg?style=flat-square]
;; <https://github.com/ROCKTAKEY/lsp-latex/actions>
;; [file:https://melpa.org/packages/lsp-latex-badge.svg]
;; <https://melpa.org/#/lsp-latex>
;; 1 lsp-mode client for Texlab.
;; =============================
;; While `lsp-tex.el', included by [lsp-mode], provides minimal setting
;; for [Texlab], `lsp-latex.el' provides full features of [Texlab]
;; v5.21.0.
;; [lsp-mode] <https://github.com/emacs-lsp/lsp-mode>
;; [Texlab] <https://github.com/latex-lsp/texlab>
;; 2 How to Use?
;; =============
;; - First, you have to install Texlab. Please install this [here].
;; - Next, you should make `lsp-mode' available. See [lsp-mode].
;; - Now, you can use Language Server Protocol (LSP) on (la)tex-mode or
;; yatex-mode just to evaluate this:
;; ,----
;; | 1 (add-to-list 'load-path "/path/to/lsp-latex")
;; | 2 (require 'lsp-latex)
;; | 3 ;; "texlab" executable must be located at a directory contained in `exec-path'.
;; | 4 ;; If you want to put "texlab" somewhere else,
;; | 5 ;; you can specify the path to "texlab" as follows:
;; | 6 ;; (setq lsp-latex-texlab-executable "/path/to/texlab")
;; | 7
;; | 8 (with-eval-after-load "tex-mode"
;; | 9 (add-hook 'tex-mode-hook 'lsp)
;; | 10 (add-hook 'latex-mode-hook 'lsp))
;; | 11
;; | 12 ;; For YaTeX
;; | 13 (with-eval-after-load "yatex"
;; | 14 (add-hook 'yatex-mode-hook 'lsp))
;; | 15
;; | 16 ;; For bibtex
;; | 17 (with-eval-after-load "bibtex"
;; | 18 (add-hook 'bibtex-mode-hook 'lsp))
;; `----
;; [here] <https://github.com/latex-lsp/texlab/releases>
;; [lsp-mode] <https://github.com/emacs-lsp/lsp-mode>
;; 3 Variables
;; ===========
;; 3.1 `lsp-latex-texlab-executable'
;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;; Where Texlab server executable located.
;; 3.2 `lsp-latex-texlab-executable-argument-list'
;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;; Argument list passed to Texlab server.
;; 3.3 Others, provided by texlab server
;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;; These variables are connected to Texlab configuration variables. See
;; also [Texlab official wiki].
;; Custom variable in Emacs Configuration provided by Texlab
;; -----------------------------------------------------------------------------------------------
;; lsp-latex-build-executable texlab.build.executable
;; lsp-latex-build-args texlab.build.args
;; lsp-latex-build-forward-search-after texlab.build.forwardSearchAfter
;; lsp-latex-build-on-save texlab.build.onSave
;; lsp-latex-build-use-file-list texlab.build.useFileList
;; lsp-latex-build-aux-directory texlab.build.auxDirectory
;; lsp-latex-build-log-directory texlab.build.logDirectory
;; lsp-latex-build-pdf-directory texlab.build.pdfDirectory
;; lsp-latex-forward-search-executable texlab.forwardSearch.executable
;; lsp-latex-forward-search-args texlab.forwardSearch.args
;; lsp-latex-chktex-additional-args texlab.chktex.additionalArgs
;; lsp-latex-chktex-on-open-and-save texlab.chktex.onOpenAndSave
;; lsp-latex-chktex-on-edit texlab.chktex.onEdit
;; lsp-latex-diagnostics-delay texlab.diagnosticsDelay
;; lsp-latex-diagnostics-allowed-patterns texlab.diagnostics.allowedPatterns
;; lsp-latex-diagnostics-ignored-patterns texlab.diagnostics.ignoredPatterns
;; lsp-latex-symbol-allowed-patterns texlab.symbol.allowedPatterns
;; lsp-latex-symbol-ignored-patterns texlab.symbol.ignoredPatterns
;; lsp-latex-bibtex-formatter-line-length texlab.formatterLineLength
;; lsp-latex-bibtex-formatter texlab.bibtexFormatter
;; lsp-latex-latex-formatter texlab.latexFormatter
;; lsp-latex-latexindent-local texlab.latexindent.local
;; lsp-latex-latexindent-modify-line-breaks texlab.latexindent.modifyLineBreaks
;; lsp-latex-latexindent-replacement texlab.latexindent.replacement
;; lsp-latex-completion-matcher texlab.completion.matcher
;; lsp-latex-inlay-hints-label-definitions texlab.inlayHints.labelDefinitions
;; lsp-latex-inlay-hints-label-references texlab.inlayHints.labelReferences
;; lsp-latex-inlay-hints-max-length texlab.inlayHints.maxLength
;; lsp-latex-experimental-math-environments texlab.experimental.mathEnvironments
;; lsp-latex-experimental-enum-environments texlab.experimental.enumEnvironments
;; lsp-latex-experimental-verbatim-environments texlab.experimental.verbatimEnvironments
;; lsp-latex-experimental-citation-commands texlab.experimental.citationCommands
;; lsp-latex-experimental-label-reference-commands texlab.experimental.labelReferenceCommands
;; lsp-latex-experimental-label-definition-commands texlab.experimental.labelDefinitionCommands
;; lsp-latex-experimental-label-reference-prefixes texlab.experimental.labelReferencePrefixes
;; lsp-latex-experimental-label-definition-prefixes texlab.experimental.labelDefinitionPrefixes
;; [Texlab official wiki]
;; <https://github.com/latex-lsp/texlab/wiki/Configuration>
;; 4 Build
;; =======
;; 4.1 `lsp-latex-build'
;; ~~~~~~~~~~~~~~~~~~~~~
;; Request texlab to build `.tex' files. It use [`latexmk'] by default,
;; so add `.latexmkrc' if you want to customize latex commands or
;; options. You can change build command and option to other such as
;; `make', by changing `lsp-latex-build-executable' and
;; `lsp-latex-build-args'.
;; This command build asynchronously by default, while it build
;; synchronously with prefix argument(`C-u').
;; [`latexmk'] <https://personal.psu.edu/~jcc8/software/latexmk/>
;; 5 Workspace commands
;; ====================
;; These commands are connected to Texlab Workspace commands. See also
;; [Texlab official wiki].
;; Custom variable in Emacs Configuration provided by Texlab
;; -------------------------------------------------------------------
;; lsp-latex-clean-auxiliary texlab.cleanAuxiliary
;; lsp-latex-clean-artifacts texlab.cleanArtifacts
;; lsp-latex-change-environment texlab.changeEnvironment
;; lsp-latex-find-environments texlab.findEnvironments
;; lsp-latex-show-dependency-graph texlab.showDependencyGraph
;; lsp-latex-cancel-build texlab.cancelBuild
;; [Texlab official wiki]
;; <https://github.com/latex-lsp/texlab/wiki/Workspace-commands>
;; 5.1 `lsp-latex-clean-auxiliary'
;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;; This command removes LaTeX auxiliary files. It will run `latexmk -c'
;; in the project.
;; 5.2 `lsp-latex-clean-artifacts'
;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;; This command removes LaTeX auxiliary files and artifacts It will run
;; `latexmk -C' in the project.
;; 5.3 `lsp-latex-change-environment'
;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;; This command replaces enviroment name to NEW-NAME in current position.
;; This edits most-inner environment containing the current position.
;; 5.4 `lsp-latex-find-environments'
;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;; This function get list of environments containing the current point.
;; Each element of the list is `lsp-latex-environment-location' instance.
;; See the docstring of `lsp-latex-environment-location'.
;; 5.4.1 `lsp-latex-complete-environment'
;; --------------------------------------
;; This function reads environment name from minibuffer and returns
;; `lsp-latex-environment-location' instance.
;; It takes three arguments, `BUFFER', `POINT', `PROMPT'. `PROMPT' is
;; used as prompt for `consult--read', which is wrapper of
;; `completing-read'. `BUFFER' and `POINT' specify basis to find
;; environments.
;; 5.5 `lsp-latex-show-dependency-graph'
;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;; Show dependency graph written by DOT format. [`graphviz-dot-mode'] is
;; needed if you needs syntax highlights or a graphical image.
;; [`graphviz-dot-mode'] <https://ppareit.github.io/graphviz-dot-mode/>
;; 5.6 `lsp-latex-cancel-build'
;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;; This command request Texlab to cancel the proceeding build.
;; 6 Commands with `lsp-latex-complete-environment'
;; ================================================
;; `lsp-latex-find-environments', which is interface for
;; `texlab.FindEnvironments', does nothing but returns list of
;; environments. So this package provide some additional commands to
;; utilize it.
;; 6.1 `lsp-latex-goto-environment'
;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;; Go to selected environment containing the current point.
;; 6.2 `lsp-latex-select-and-change-environment'
;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;; Change name of selected environment to NEW-NAME.
;; 7 Forward/inverse search
;; ========================
;; Forward search and inverse search are available. See also [Texlab
;; official wiki].
;; [Texlab official wiki]
;; <https://github.com/latex-lsp/texlab/wiki/Previewing>
;; 7.1 Forward search
;; ~~~~~~~~~~~~~~~~~~
;; You can move from Emacs to current position on pdf viewer by the
;; function `lsp-latex-forward-search'. To use, you should set
;; `lsp-latex-forward-search-executable' and
;; `lsp-latex-forward-search-args' according to your pdf viewer.
;; You can see [Texlab official wiki], but you should replace some VSCode
;; words with Emacs words. `latex.forwardSearch.executable' should be
;; replaced with `lsp-latex-forward-search-executable', and
;; `latex.forwardSearch.args' with `lsp-latex-forward-search-args'. You
;; should setq each variable instead of writing like json, and vector in
;; json is replaced to list in Emacs Lisp. So the json:
;; ,----
;; | {
;; | "texlab.forwardSearch.executable": "FavoriteViewer",
;; | "texlab.forwardSearch.args": [ "%p", "%f", "%l" ]
;; | }
;; `----
;; should be replaced with the Emacs Lisp code:
;; ,----
;; | (setq lsp-latex-forward-search-executable "FavoriteViewer")
;; | (setq lsp-latex-forward-search-args '("%p" "%f" "%l"))
;; `----
;; In `lsp-latex-forward-search-args', the string "%f" is replaced with
;; "The path of the current TeX file", "%p" with "The path of the current
;; PDF file", "%l" with "The current line number", by Texlab (see
;; [Forward search arg section in Texlab official wiki]).
;; For example of SumatraPDF, write in init.el:
;; ,----
;; | (setq lsp-latex-forward-search-executable "C:/Users/{User}/AppData/Local/SumatraPDF/SumatraPDF.exe")
;; | (setq lsp-latex-forward-search-args '("-reuse-instance" "%p" "-forward-search" "%f" "%l"))
;; `----
;; while VSCode config with json (see [Texlab official wiki]) is:
;; ,----
;; | {
;; | "texlab.forwardSearch.executable": "C:/Users/{User}/AppData/Local/SumatraPDF/SumatraPDF.exe",
;; | "texlab.forwardSearch.args": [
;; | "-reuse-instance",
;; | "%p",
;; | "-forward-search",
;; | "%f",
;; | "%l"
;; | ]
;; | }
;; `----
;; Then, you can jump to the current position on pdf viewer by command
;; `lsp-latex-forward-search'.
;; [Texlab official wiki]
;; <https://github.com/latex-lsp/texlab/wiki/Previewing>
;; [Forward search arg section in Texlab official wiki]
;; <https://github.com/latex-lsp/texlab/wiki/Configuration#texlabforwardsearchargs>
;; [Texlab official wiki]
;; <https://github.com/latex-lsp/texlab/wiki/Previewing#forward-search>
;; 7.2 Inverse search
;; ~~~~~~~~~~~~~~~~~~
;; You can go to the current position on Emacs from pdf viewer. Whatever
;; pdf viewer you use, you should start Emacs server by writing in
;; init.el:
;; ,----
;; | (server-start)
;; `----
;; Then, you can jump to line {{LINE-NUMBER}} in file named {{FILENAME}}
;; with the command:
;; ,----
;; | 1 emacsclient +{{LINE-NUMBER}} {{FILENAME}}
;; `----
;; {{LINE-NUMBER}} and {{FILENAME}} should be replaced with line number
;; and filename you want to jump to. Each pdf viewer can provide some
;; syntax to replace.
;; For example of SmatraPDF (see [Texlab official wiki]), "Add the
;; following line to your SumatraPDF settings file (Menu -> Settings ->
;; Advanced Options):"
;; ,----
;; | 1 InverseSearchCmdLine = C:\path\to\emacsclient.exe +%l %f
;; `----
;; Then, "You can execute the search by pressing Alt+DoubleClick in the
;; PDF document".
;; [Texlab official wiki]
;; <https://github.com/latex-lsp/texlab/wiki/Previewing#inverse-search>
;; 7.3 Examples
;; ~~~~~~~~~~~~
;; These examples are according to [Texlab official wiki]. Especially,
;; quoted or double-quoted sentences are citation from [Texlab official
;; wiki].
;; [Texlab official wiki]
;; <https://github.com/latex-lsp/texlab/wiki/Previewing>
;; 7.3.1 SumatraPDF
;; ----------------
;; We highly recommend SumatraPDF on Windows because Adobe
;; Reader locks the opened PDF file and will therefore
;; prevent further builds.
;; * 7.3.1.1 Forward search
;; Write to init.el:
;; ,----
;; | (setq lsp-latex-forward-search-executable "C:/Users/{User}/AppData/Local/SumatraPDF/SumatraPDF.exe")
;; | (setq lsp-latex-forward-search-args '("-reuse-instance" "%p" "-forward-search" "%f" "%l"))
;; `----
;; * 7.3.1.2 Inverse Search
;; Add the following line to your [SumatraPDF] settings file
;; (Menu -> Settings -> Advanced Options):
;; ,----
;; | 1 InverseSearchCmdLine = C:\path\to\emacsclient.exe +%l "%f"
;; `----
;; You can execute the search by pressing `Alt+DoubleClick'
;; in the PDF document.
;; [SumatraPDF] <https://www.sumatrapdfreader.org/>
;; 7.3.2 Evince
;; ------------
;; The SyncTeX feature of [Evince] requires communication via
;; D-Bus. In order to use it from the command line, install
;; the [evince-synctex] script.
;; [Evince] <https://wiki.gnome.org/Apps/Evince>
;; [evince-synctex] <https://github.com/latex-lsp/evince-synctex>
;; * 7.3.2.1 Forward search
;; Write to init.el:
;; ,----
;; | (setq lsp-latex-forward-search-executable "evince-synctex")
;; | (setq lsp-latex-forward-search-args '("-f" "%l" "%p" "\"emacsclient +%l %f\""))
;; `----
;; * 7.3.2.2 Inverse search
;; The inverse search feature is already configured if you
;; use `evince-synctex'. You can execute the search by
;; pressing `Ctrl+Click' in the PDF document.
;; 7.3.3 Okular
;; ------------
;; * 7.3.3.1 Forward search
;; Write to init.el:
;; ,----
;; | (setq lsp-latex-forward-search-executable "okular")
;; | (setq lsp-latex-forward-search-args '("--unique" "file:%p#src:%l%f"))
;; `----
;; * 7.3.3.2 Inverse search
;; Change the editor of Okular (Settings -> Configure
;; Okular... -> Editor) to "Custom Text Editor" and set the
;; following command:
;; ,----
;; | emacsclient +%l "%f"
;; `----
;; You can execute the search by pressing `Shift+Click' in the PDF
;; document.
;; 7.3.4 Zathura
;; -------------
;; * 7.3.4.1 Forward search
;; Write to init.el:
;; ,----
;; | (setq lsp-latex-forward-search-executable "zathura")
;; | (setq lsp-latex-forward-search-args '("--synctex-forward" "%l:1:%f" "%p"))
;; `----
;; * 7.3.4.2 Inverse search
;; Add the following lines to your
;; `~/.config/zathura/zathurarc' file:
;; ,----
;; | 1 set synctex true
;; | 2 set synctex-editor-command "emacsclient +%{line} %{input}"
;; `----
;; You can execute the search by pressing `Alt+Click' in the
;; PDF document.
;; 7.3.5 qpdfview
;; --------------
;; * 7.3.5.1 Forward search
;; Write to init.el:
;; ,----
;; | (setq lsp-latex-forward-search-executable "qpdfview")
;; | (setq lsp-latex-forward-search-args '("--unique" "%p#src:%f:%l:1"))
;; `----
;; * 7.3.5.2 Inverse search
;; Change the source editor setting (Edit -> Settings... ->
;; Behavior -> Source editor) to:
;; ,----
;; | 1 emacsclient +%2 "%1"
;; `----
;; and select a mouse button modifier (Edit -> Settings... ->
;; Behavior -> Modifiers -> Mouse button modifiers -> Open in
;; Source Editor)of choice. You can execute the search by
;; pressing Modifier+Click in the PDF document.
;; 7.3.6 Skim
;; ----------
;; We recommend [Skim] on macOS since it is the only native
;; viewer that supports SyncTeX. Additionally, enable the
;; "Reload automatically" setting in the Skim preferences
;; (Skim -> Preferences -> Sync -> Check for file changes).
;; [Skim] <https://skim-app.sourceforge.io/>
;; * 7.3.6.1 Forward search
;; Write to init.el:
;; ,----
;; | (setq lsp-latex-forward-search-executable "/Applications/Skim.app/Contents/SharedSupport/displayline")
;; | (setq lsp-latex-forward-search-args '("%l" "%p" "%f"))
;; `----
;; "If you want Skim to stay in the background after executing the
;; forward search, you can add the `-g' option to"
;; `lsp-latex-forward-search-args'.
;; * 7.3.6.2 Inverse search
;; Select Emacs preset "in the Skim preferences (Skim -> Preferences ->
;; Sync -> PDF-TeX Sync support). You can execute the search by pressing
;; `Shift+⌘+Click' in the PDF document."
;; 7.3.7 `pdf-tools' integration
;; -----------------------------
;; If you want to use forward search with `pdf-tools', follow the
;; setting:
;; ,----
;; | ;; Start Emacs server
;; | (server-start)
;; | ;; Turn on SyncTeX on the build.
;; | ;; If you use `lsp-latex-build', it is on by default.
;; | ;; If not (for example, YaTeX or LaTeX-mode building system),
;; | ;; put to init.el like this:
;; | (setq tex-command "platex --synctex=1")
;; |
;; | ;; Setting for pdf-tools
;; | (setq lsp-latex-forward-search-executable "emacsclient")
;; | (setq lsp-latex-forward-search-args
;; | '("--eval"
;; | "(lsp-latex-forward-search-with-pdf-tools \"%f\" \"%p\" \"%l\")"))
;; `----
;; Inverse research is not provided by Texlab, so please use
;; `pdf-sync-backward-search-mouse'.
;; 8 License
;; =========
;; This package is licensed by GPLv3. See [LICENSE].
;; [LICENSE] <file:LICENSE>
;;; Code:
(require 'cl-lib)
(require 'lsp-mode)
(require 'consult)
(defgroup lsp-latex nil
"Language Server Protocol client for LaTeX."
:group 'lsp-mode)
(defcustom lsp-latex-texlab-executable
(cond ((eq system-type 'windows-nt)
"texlab.exe")
(t "texlab"))
"Executable command to run Texlab.
Called with the arguments in `lsp-latex-texlab-executable-argument-list'."
:group 'lsp-latex
:type 'string)
(defcustom lsp-latex-texlab-executable-argument-list '()
"List of Arguments passed to `lsp-latex-texlab-executable'."
:group 'lsp-latex
:type '(repeat string))
(defcustom lsp-latex-completion-sort-in-emacs nil
"Sort completion results in Emacs if non-nil.
Texlab sorts completion results, so sorting in Emacs is not needed.
Set non-nil value if you prefers they are sorted in Emacs.
See also `lsp-completion-sort-initial-results'."
:group 'lsp-latex
:type 'boolean
:version "3.2.0")
(defcustom lsp-latex-root-directory nil
"Root directory of each buffer."
:group 'lsp-latex
:risky t
:type '(choice string
(const nil)))
(make-obsolete-variable 'lsp-latex-root-directory "Texlab 5.16.1 and more ignore this variable." "3.8.0")
(defcustom lsp-latex-build-executable "latexmk"
"Build command used on `lsp-latex-build'."
:group 'lsp-latex
:risky t
:type 'string)
(defcustom lsp-latex-build-args
'("-pdf" "-interaction=nonstopmode" "-synctex=1" "%f")
"Argument list passed to `lsp-latex-build-executable'.
Value is used on `lsp-latex-build'.
\"%f\" can be used as the path of the TeX file to compile."
:group 'lsp-latex
:risky t
:type '(repeat string))
(define-obsolete-variable-alias 'lsp-latex-forward-search-after
'lsp-latex-build-forward-search-after
"3.0.0")
(defcustom lsp-latex-build-forward-search-after nil
"Execute forward-research after building."
:group 'lsp-latex
:type 'boolean
:version "3.0.0")
(defcustom lsp-latex-build-on-save nil
"Build after saving a file or not."
:group 'lsp-latex
:type 'boolean
:version "3.0.0")
(define-obsolete-variable-alias 'lsp-latex-build-output-directory
'lsp-latex-build-aux-directory
"2.0.0"
"Directory to which built file is put.
Note that you should change `lsp-latex-build-args' to change output directory.
If you use latexmk, use \"-outdir\" flag.
This variable is obsoleted since Texlab 3.0.0.")
(defcustom lsp-latex-build-use-file-list nil
"Whether to use \".fls\" file for project detection or not."
:group 'lsp-latex
:type 'boolean
:version "3.8.0")
(defcustom lsp-latex-build-aux-directory "."
"Directory to which built file is put.
Note that you should change `lsp-latex-build-args' to change output directory.
If you use latexmk, it is automatically determined by Texlab."
:group 'lsp-latex
:type 'string
:risky t
:version "2.0.0")
(defcustom lsp-latex-build-log-directory "."
"Directory containing log for build without latexmk.
If you use latexmk, it is automatically determined by Texlab."
:group 'lsp-latex
:type 'string
:risky t
:version "3.7.0")
(defcustom lsp-latex-build-pdf-directory "."
"Directory containing PDF for build without latexmk.
Note that you should change `lsp-latex-build-args' to change output directory.
If you use latexmk, it is automatically determined by Texlab."
:group 'lsp-latex
:type 'string
:risky t
:version "3.7.0")
(make-obsolete-variable
'lsp-latex-build-is-continuous
"This variable is obsoleted since Texlab 3.2.0.
https://github.com/latex-lsp/texlab/blob/fe828eed914088c6ad90a4574192024008b3d96a/CHANGELOG.md#changed."
"3.0.0")
(defcustom lsp-latex-forward-search-executable nil
"Executable command used to search in preview.
It is passed server as \"latex.forwardSearch.executable\"."
:group 'lsp-latex
:type 'string
:risky t)
(defcustom lsp-latex-forward-search-args nil
"Argument list passed to `lsp-latex-forward-search-executable'.
It is passed server as \"latex.forwardSearch.executable\".
Placeholders
%f: The path of the current TeX file.
%p: The path of the current PDF file.
%l: The current line number."
:group 'lsp-latex
:type '(repeat string)
:risky t)
(define-obsolete-variable-alias 'lsp-latex-lint-on-save
'lsp-latex-chktex-on-open-and-save
"2.0.0"
"Lint using chktex after saving a file.
This variable is obsoleted since Texlab 3.0.0.")
(defcustom lsp-latex-chktex-additional-args nil
"Additional arguments passed to ChkTeX.
Note that redefining -I and -f flags is not allowed.
These are set by Texlab server."
:group 'lsp-latex
:type '(repeat string)
:version "3.7.0")
(defcustom lsp-latex-chktex-on-open-and-save nil
"Lint using chktex after opening and saving a file."
:group 'lsp-latex
:type 'boolean
:version "2.0.0")
(define-obsolete-variable-alias 'lsp-latex-lint-on-change
'lsp-latex-chktex-on-edit
"2.0.0"
"Lint using chktex after changing a file.
This variable is obsoleted since Texlab 3.0.0.")
(defcustom lsp-latex-chktex-on-edit nil
"Lint using chktex after changing a file."
:group 'lsp-latex
:type 'boolean
:version "2.0.0")
(defcustom lsp-latex-diagnostics-delay 300
"Delay time before reporting diagnostics.
The value is in milliseconds."
:group 'lsp-latex
:type 'integerp
:version "2.0.0")
(defcustom lsp-latex-diagnostics-allowed-patterns '()
"Regexp whitelist for diagnostics.
It should be a list of regular expression.
Only diagnostics that match at least one of the elemnt is shown.
Note that this is applied before `lsp-latex-diagnostics-ignored-patterns',
so `lsp-latex-diagnostics-ignored-patterns' is priored."
:group 'lsp-latex
:type '(repeat string)
:version "3.0.0")
(defcustom lsp-latex-diagnostics-ignored-patterns '()
"Regexp blacklist for diagnostics.
It should be a list of regular expression.
Only diagnostics that do NOT match at least one of the elemnt is shown.
Note that this is applied after `lsp-latex-diagnostics-allowed-patterns',
so this variable is priored."
:group 'lsp-latex
:type '(repeat string)
:version "3.0.0")
(defcustom lsp-latex-symbol-allowed-patterns '()
"Regexp whitelist for document symbol.
It should be a list of regular expression.
Only document symbol that match at least one of the elemnt is shown.
Note that this is applied before `lsp-latex-symbol-ignored-patterns',
so `lsp-latex-symbol-ignored-patterns' is priored."
:group 'lsp-latex
:type '(repeat string)
:version "3.5.0")
(defcustom lsp-latex-symbol-ignored-patterns '()
"Regexp blacklist for document symbol.
It should be a list of regular expression.
Only document symbol that do NOT match at least one of the elemnt is shown.
Note that this is applied after `lsp-latex-symbol-allowed-patterns',
so this variable is priored."
:group 'lsp-latex
:type '(repeat string)
:version "3.5.0")
(define-obsolete-variable-alias 'lsp-latex-bibtex-formatting-line-length
'lsp-latex-bibtex-formatter-line-length
"Maximum amount of line on formatting BibTeX files.
0 means disable.
This variable is obsoleted since Texlab 3.0.0.")
(defcustom lsp-latex-bibtex-formatter-line-length 80
"Maximum amount of line on formatting BibTeX files.
0 means disable."
:group 'lsp-latex
:type 'integerp
:version "2.0.0")
(define-obsolete-variable-alias 'lsp-latex-bibtex-formatting-formatter
'lsp-latex-bibtex-formatter
"2.0.0"
"Formatter used to format BibTeX file.
You can choose \"texlab\" or \"latexindent\".
This variable is obsoleted since Texlab 3.0.0.")
(defcustom lsp-latex-bibtex-formatter "texlab"
"Formatter used to format BibTeX file.
You can choose \"texlab\" or \"latexindent\"."
:group 'lsp-latex
:type '(choice (const "texlab") (const "latexindent"))
:version "2.0.0")
(defcustom lsp-latex-latex-formatter "texlab"
"Formatter used to format LaTeX file.
You can choose \"texlab\" or \"latexindent\".
This variable is valid since Texlab 3.0.0."
:group 'lsp-latex
:type '(choice (const "texlab") (const "latexindent"))
:version "2.0.0")
(defcustom lsp-latex-latexindent-local nil
"Path to file of latexindent configuration.
The value is passed to latexindent through \"--local\" flag.
The root directory is used by default."
:group 'lsp-latex
:type '(choice string (const nil))
:version "2.0.0")
(defcustom lsp-latex-latexindent-modify-line-breaks nil
"Latexindent modifies line breaks if t."
:group 'lsp-latex
:type 'boolean
:version "2.0.0")
(defcustom lsp-latex-latexindent-replacement nil
"Additional indent flag passed to latexindent."
:group 'lsp-latex
:type '(choice
string
(const :tag "Indentation and replacements (not respect verbatim code blocks)" "-r")
(const :tag "Indentation and replacements (respect verbatim code blocks)" "-rv")
(const :tag "Only replacements (not respect verbatim code blocks)" "-rr")
(const :tag "Only indentation" nil))
:version "3.9.0")
(defcustom lsp-latex-completion-matcher "fuzzy-ignore-case"
"Algorithm used to filter the completion by Texlab.
\"fuzzy\", which means fuzzy matching, or \"prefix\",
which means that prefix matching is allowed.
In addition, \"-ignore-case\" suffix is also available,
which means the matcher should be case insensitive."
:group 'lsp-latex
:type '(choice (const "fuzzy")
(const "fuzzy-ignore-case")
(const "prefix")
(const "prefix-ignore-case"))
:version "3.5.0")
(defcustom lsp-latex-inlay-hints-label-definitions '()
"When non-nil, inlay hints for \"\\label\"-like commands are displayed."
:group 'lsp-latex
:type 'boolean
:version "3.7.0")
(defcustom lsp-latex-inlay-hints-label-references '()
"When non-nil, inlay hints for \"\\ref\"-like commands are displayed."
:group 'lsp-latex
:type 'boolean
:version "3.7.0")
(defcustom lsp-latex-inlay-hints-max-length nil
"When non-nil, inlay hints is truncated to the length."
:group 'lsp-latex
:type '(choice int (const nil))
:version "3.9.0")
(defcustom lsp-latex-experimental-math-environments '()
"List of environment name regarded as math environment, such as \"align\"."
:group 'lsp-latex
:type '(repeat string)
:version "3.3.0")
(defcustom lsp-latex-experimental-enum-environments '()
"List of environment name regarded as enumelation environment.
For example, \"itemize\" or \"enumerate\" meet the condition."
:group 'lsp-latex
:type '(repeat string)
:version "3.3.0")
(defcustom lsp-latex-experimental-verbatim-environments '()
"List of environment name regarded as verbatim environment.
This suppresses warnings in the environment where the code is not
written in LaTeX.
For example, \"lstlisting\" is meet the condition."
:group 'lsp-latex
:type '(repeat string)
:version "3.3.0")
(defcustom lsp-latex-experimental-citation-commands '()
"List of command name which should be regarded as citation command.
For example, \"cite\" is meet the condition. Note that backslash is not needed."
:group 'lsp-latex
:type '(repeat string)
:version "3.5.0")
(defcustom lsp-latex-experimental-label-definition-commands '()
"List of command name which should be regarded as \"\\label\"-like command.
For example, \"label\" is meet the condition. Note that backslash is not needed."
:group 'lsp-latex
:type '(repeat string)
:version "3.8.0")
(defcustom lsp-latex-experimental-label-reference-commands '()
"List of command name which should be regarded as \"\\ref\"-like command.
For example, \"ref\" is meet the condition. Note that backslash is not needed."
:group 'lsp-latex
:type '(repeat string)
:version "3.7.0")
(defcustom lsp-latex-experimental-label-definition-prefixes '()
"List of prefix for the label name for definition.
Each element should be (COMMAND PREFIX), where COMMAND is string regarded as
reference like \"label\", and where PREFIX should be string like \"fig:\"."
:group 'lsp-latex
:type '(repeat (list string string))
:version "3.8.0")
(defcustom lsp-latex-experimental-label-reference-prefixes '()