-
-
Notifications
You must be signed in to change notification settings - Fork 123
/
scimax-latex.el
140 lines (106 loc) · 4.58 KB
/
scimax-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
;;; scimax-latex.el --- Utilities to check the LaTeX setup
;;; Commentary:
;;
;;; Code:
(defvar tlmgr-installed-packages nil
"Cached list of installed LaTeX packages.")
(defun tlmgr-installed (&optional refresh)
"Get a list of installed LaTeX packages. Uses a cached value if
possible unless REFRESH is non-nil."
(unless (or tlmgr-installed-packages refresh)
(setq tlmgr-installed-packages
(mapcar (lambda (s)
(split-string (substring s 2) ":" t))
(split-string
(shell-command-to-string "tlmgr list --only-installed") "\n" t))))
tlmgr-installed-packages)
(defun texdoc (package)
"Run texdoc on the PACKAGE."
(interactive (list (completing-read "Package: " (tlmgr-installed))))
(shell-command (format "texdoc %s" package)))
(defun kpsewhich (symbol)
"Run kpsewhich on SYMBOL."
(interactive "sSymbol: ")
(message (shell-command-to-string (format "kpsewhich %s" symbol))))
(defun scimax-latex-setup ()
"Display buffer with LaTeX setup information."
(interactive)
(message "Please wait while I gather some information. This can take a while.")
(pop-to-buffer "*scimax-latex-setup*")
(erase-buffer)
(org-mode)
(message "Getting information on executables")
(insert (s-format "#+TITLE: LaTeX setup
This file describes how LaTeX is setup on your computer.
* Executables
latex: ${(executable-find \"latex\")}
pdflatex: ${(executable-find \"pdflatex\")}
bibtex: ${(executable-find \"bibtex\")}
biber: ${(executable-find \"biber\")}
tlmgr: ${(executable-find \"tlmgr\")}
kpsewhich: ${(executable-find \"kpsewhich\")}
texdoc: ${(executable-find \"texdoc\")}
Configuration:
${(shell-command-to-string \"tlmgr conf texmf\")}
* Latex classes org-mode knows about
Here are some relevant variables
help:org-format-latex-header
help:org-latex-default-packages-alist
help:org-latex-packages-alist
help:org-latex-pdf-process
Note: Not every class has a corresponding style file. Click on the texdoc link to learn more about the class.
Missing files should be installed in the TEXMFHOME directory listed above. See https://en.wikibooks.org/wiki/LaTeX/Installing_Extra_Packages for help.
"
(lambda (arg &optional extra)
(eval (read arg)))))
(message "Getting information on org-mode latex classes.")
(cl-loop for (org-name header-string cls) in
(-uniq (cl-loop for latex-class in org-latex-classes
collect
(list (car latex-class)
(nth 1 latex-class)
(let ((header-string (nth 1 latex-class)))
(when (string-match "documentclass.*?{\\(.*?\\)}" header-string)
(match-string 1 header-string))))))
do
(message "Getting %s" org-name)
(let ((cls-path (s-trim (shell-command-to-string (format "kpsewhich %s.cls" cls))))
(sty-path (s-trim (shell-command-to-string (format "kpsewhich %s.sty" cls)))))
(insert (s-format "
** ${org-name} creates documents with this LaTeX documentclass: ${cls}
This is the header that is expanded.
#+BEGIN_EXPORT latex
${header-string}
#+END_EXPORT
LaTeX path for class: [[${cls-path}]]
[[elisp:(shell-command \"texdoc ${cls}\"][texdoc ${cls}]]
Latex style path: [[${sty-path}]]
"
(lambda (arg &optional extra)
(eval (read arg)))))))
(message "Getting information on default latex packages.")
(insert "* org-mode default latex packages\n
These are defined in [[elisp:(describe-variable 'org-latex-default-packages-alist)][org-latex-default-packages-alist]]\n\n")
(cl-loop for (options package snippet compilers) in org-latex-default-packages-alist
do
(insert (s-format "- ${package} (options=${options}) [[elisp:(shell-command \"texdoc ${package}\"][texdoc ${package}]]\n"
(lambda (arg &optional extra)
(eval (read arg))))))
(message "Getting information on org-defined latex packages")
(insert "\n* org-mode defined latex packages\n
These are defined in [[elisp:(describe-variable 'org-latex-packages-alist)][org-latex-packages-alist]]\n\n")
(cl-loop for (options package snippet compilers) in org-latex-packages-alist
do
(insert (s-format "- ${package} [${options}] [[elisp:(shell-command \"texdoc ${package}\"][texdoc ${package}]]\n"
(lambda (arg &optional extra)
(eval (read arg))))))
(message "Getting information on compiling setup.")
(insert "\n\n* org-mode LaTeX compiling setup\n\n")
(insert (format "org-latex-pdf-process = \"%s\"\n" org-latex-pdf-process))
(when (functionp org-latex-pdf-process)
(insert (format "%s" (describe-function org-latex-pdf-process)))
(kill-buffer "*Help*"))
(pop-to-buffer "*scimax-latex-setup*")
(goto-char (point-min)))
(provide 'scimax-latex)
;;; scimax-latex.el ends here