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

From: Visuwesh <[email-masked]>
Date: Sun, 06 Oct 2024 11:58:28 +0530

[ஞாயிறு அக்டோபர் 06, 2024] Eli Zaretskii wrote:

>> 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?

When "mutool run" is called without any script argument, it opens a
REPL.  We would need to `process-send-string' to the REPL but the REPL
reports syntax error when I try to do so.  This is after trying to
"minify" the JS script.  Maybe I am doing something wrong.  I've
attached my test lisp at the end.

I do not understand what you suggest by the former however.