Subject: Re: bug#73638: 31.0.50; doc-view: imenu index cannot be made for LaTeX PDFs

From: Eli Zaretskii <[email-masked]>
Date: Sun, 06 Oct 2024 08:42:01 +0300

> From: Tassilo Horn <[email-masked]>
> Cc: [email-masked], Eli Zaretskii <[email-masked]>
> Date: Sat, 05 Oct 2024 21:56:24 +0200
> 
> Eli, the executive summary is this.  We already can read a PDFs outline
> mutool and use that for quick access to chapters and sections through
> imenu.  However, it turned out that it depends on the PDF at hand if the
> outline is usable for our purpose where "usable" means we get page
> references.  And it seems that many PDFs (e.g., those produced by LaTeX)
> have no page references but named references which won't do the trick
> for doc-view.
> 
> Visuwesh figured out that one can run a JS script using "mutool run
> <script> foo.pdf" for accessing the PDFs internal structure using the JS
> mupdf API and wrote the below simple script which spits out the outline
> with page references as sexp structure.
> 
> Would it be ok to distribute the below JS helper script with Emacs so
> that doc-view can use it?  If so, how?  Maybe the simplest way would be
> to just put it in some doc-view--mutool-outline-script variable and copy
> it to doc-view-cache-directory when invoking imenu on a PDF file the
> first time?

Can't we invoke the JS interpreter with this script as the command, or
invoke it as async subprocess and pipe the script to it via standard
input?