emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Add completing-read support to `TeX-documentation-texdoc'?


From: Michael Eliachevitch
Subject: Add completing-read support to `TeX-documentation-texdoc'?
Date: Thu, 09 Feb 2023 14:29:20 +0000

Hi,

AUCTeX has support for viewing TeX-live documentation via the 
`TeX-documentation-texdoc', which runs the texdoc [1] program in a subprocess.

I found that on the texdoc github wiki provides snippets [2] that add
auto-completion for the texdoc cli program by getting the package names from
texlive.tlpdb. This inspired me to make a texdoc command for emacs that let's
the user select a latex package via `completing-read'. I initially implemented
this for myself as a dead simple new standalone command:

--8<---------------cut here---------------start------------->8---
(defun my-texdoc--get-package-list ()
 (let ((tlpdb-fpath (file-name-concat
                     (string-trim-right
                      (shell-command-to-string "kpsewhich -var-value 
TEXMFROOT"))
                     "tlpkg/texlive.tlpdb"))
       (name-regex "^name \\([^ \n.]+\\)$"))
   (with-current-buffer (find-file-noselect tlpdb-fpath 'nowarn 'rawfile)
     (save-excursion
       (goto-char (point-min))
       (cl-loop
        while (re-search-forward name-regex nil 'noerror)
        collect (match-string-no-properties 1))))))

(defun my-texdoc (pkg)
 "Show TeX documentation for package PKG.
If called interactively, select package from TexLive with interactive 
completion."
 (interactive
  (list (completing-read
         "texdoc: "
         (my-texdoc--get-package-list)
         nil nil nil
         'my-texdoc-history)))
   (call-process "texdoc" nil " *texdoc*" nil "--view" pkg))

--8<---------------cut here---------------end--------------->8---

The snippet requires the `kpsewhich' binary to exist, but usually that is 
installed together with `texdoc' via TeX-live anyway.

`TeX-documentation-texdoc' is much more complex than my simple wrapper, as it
defaults to `symbol-at-point', and also allows choosing a manual from a list of
candidates provided by `texdoc --list'. Also its process handling is much more
complex than my `call-process'. Still, I think that it could probably be
refactored and simplified by using modern emacs functionality which might not
have existed when it was written and probably adapting it to use
`completing-read' with a list of candidates as I did above is not complicated
either.

However, I'm not sure if this would be wanted, as I don't know if AUCTeX is 
still being actively developed of is just in maintenance and bugfix-mode, and 
how much people care about keeping its behaviour stable.

Another downside might be that I can't guarantee that my code works on all 
machines and also doing the regex-iteration over texlive.tlpdb might take a 
while for some installations.

If there's no interest in including something like that in AUCTeX, I'll see if I
can share my snippet on somewhere else on the internet, in some wiki or e.g. it
could become a consult [3] command, but I thought I'd ask about having something
like that built-into emacs at first.

Cheers, Michael Eliachevitch

[1]: https://tug.org/texdoc/
[2]: https://github.com/TeX-Live/texdoc/wiki/Tab-completion
[3]: https://github.com/minad/consult

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]