all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Add completing-read support to `TeX-documentation-texdoc'?
@ 2023-02-09 14:29 Michael Eliachevitch
  0 siblings, 0 replies; only message in thread
From: Michael Eliachevitch @ 2023-02-09 14:29 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 3062 bytes --]

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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 519 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-09 14:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-09 14:29 Add completing-read support to `TeX-documentation-texdoc'? Michael Eliachevitch

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.