From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id UEo6Es9/BGdHwwAAqHPOHw:P1 (envelope-from ) for ; Tue, 08 Oct 2024 00:41:51 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id UEo6Es9/BGdHwwAAqHPOHw (envelope-from ) for ; Tue, 08 Oct 2024 02:41:51 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YFeSDdiO; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1728348111; a=rsa-sha256; cv=none; b=tKGpRxMONRaqhNnSaHtVb7fSA3xMYBCSoEuiKX+VPKyvX009PGKsZQ2rSnKEncRAnbgCpB lt7/86m9SiMPyRXHD+PFsgB3+s0J8bowqm50zN19N3IPTIFIPyYCL6NlBOXSaxuY2VWoBu kPvW+MraescK+YzURGZBY3fDR6M2q2eac6TnaouTyLkrSJdXjYqTg1hx33/x6mz9gtqV5L geVijztinYMLjtys1HpMZ7ps6bPaYjd+5cG24sxDZ1sNz94eGGRJOdEQKV4z6rMpY7heuN N6fZih64qxGOlIXbO6dkKzMdDFCqthA+hoY/1j6Cd/ZxYOR5Eu2vv7QTHgcPFw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YFeSDdiO; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1728348111; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=DFa4KRYWVPxrk/7Ao2Pn07h/s1XxG9e5oJSD0hB27Eo=; b=rKJUlEZ5uyorzJU9RoGgCQ+i6o1Z43ZdAU87dJRROc8zNoyau9rLoN7Ab1xrBe5bH+5ZhD JkGVth/lbfPlUUYCEL4ErZ2cJO7jA/N99/G3pxtEwsAjbaEHz2fabMT5ZI0uU0BN/owuwv vhwzmeiSCZ6yljzHUzZ2NSRCoM14UCtGMaJkgHzMkPi5/ID0Mx8ukFuwEWS+6YnuaL8ko7 ZmwaZx+Vw6/T6WEWJPLBPP9u5M0sV45rBqXoAxLIcNZcWadQpBauk+p6n6vRuXFl78NTqg n1qoYMmG6TYnHZVaan0EcKY2tKtAhhRPtWHDOBsniTOpUcw+/BseauzwlJnT7Q== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id EC8D185149 for ; Tue, 08 Oct 2024 02:41:50 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxyHm-0004n1-KO; Mon, 07 Oct 2024 20:41:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sxyHj-0004kv-Rw for emacs-orgmode@gnu.org; Mon, 07 Oct 2024 20:41:07 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sxyHe-0004tD-Od for emacs-orgmode@gnu.org; Mon, 07 Oct 2024 20:41:07 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-20b84bfbdfcso39305645ad.0 for ; Mon, 07 Oct 2024 17:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728348061; x=1728952861; darn=gnu.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=DFa4KRYWVPxrk/7Ao2Pn07h/s1XxG9e5oJSD0hB27Eo=; b=YFeSDdiOtpRjh32q+xzVvaBkdNILCm86tfcso4nKoeCVi1REzRNjp8zXyoTd3uWGAc 6ypcZZ12aBfGwygRT6DwY4oOL2QDl6AMw7VudREW/05LjxfqgwsTuzRVOX4obOshXR4E csbqdUbjmmkrhUgqh7xJUfGXdmi5JEqg4HSylsIDD59SAyFMw73NcpucapeZl7OZRPsE QWhih4PSNzg47pqJxDo/DiobKTAIbIfLveZctdO5ymsXCeoBCYieUVj2F+/KYiWZKF0H t7FB87INWwDpB6SwG6zVOeJ4mqC9t1qGcTq/jFtZwUu9DdLBsaXKIV+TkW5MYT2wEPBi QxAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728348061; x=1728952861; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DFa4KRYWVPxrk/7Ao2Pn07h/s1XxG9e5oJSD0hB27Eo=; b=u3UiDJBtjQGaxIwOxWvEFwefXj3OIq8gC/EwtJQY9dXiQtrm0cAQ/KHqMqnXwQe/Ed 61sK2Vp/t3IAanQ8ZUWAT88380r8NazjpMqgky9uAMktQc2qCXrSL6kC+FPbZR2LHBKB qMVlW2zJDFimzd2Uq7tkF5yH1MLpaC9N5GBAQ6ihF9M3mwRGxOqKfIEOGr09vRv6Sj7W iYqHLE6ipxyP+BJ0ToNa+ZK67JgRpaByDdheSNVCjpRPV0GZGZnT7Wm3mV3dQKziplsF ny71wVm42VI77ed4NWXVvaxF5q92YcRJU7kf4Wd16voJSKoAVEbiMlQEbUhdBkuDjnXU 3tPQ== X-Gm-Message-State: AOJu0Ywiq7nh8rhc9jAA+GMSIKvDSBLVE/42a5DZI99buMVZnXsTw2SL a5WQGmh4XxCqbwoHf7aJkz9UVRYL+DHjSxrJsBxfadL4/P9D//mSF6U1fg== X-Google-Smtp-Source: AGHT+IG7RDzoaqCo7Q1+TmMURyTzLMc873bQE8YiplQB92Lj/8pHQb5Ao3J1A1GUc0xYsu3pg0qplg== X-Received: by 2002:a17:902:ce0a:b0:205:4d27:616e with SMTP id d9443c01a7336-20c4e3164bamr23527995ad.22.1728348061022; Mon, 07 Oct 2024 17:41:01 -0700 (PDT) Received: from localhost (c-73-92-213-61.hsd1.ca.comcast.net. [73.92.213.61]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c4d0c801csm5081145ad.22.2024.10.07.17.41.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2024 17:41:00 -0700 (PDT) From: Karthik Chikmagalur To: Ihor Radchenko , Tony Zorman Cc: emacs-orgmode@gnu.org Subject: Re: Using org-latex-preview in other major modes In-Reply-To: <87msq5o03b.fsf@localhost> References: <87edbhljr7.fsf@hyperspace> <87msq5o03b.fsf@localhost> Date: Mon, 07 Oct 2024 17:40:59 -0700 Message-ID: <87a5fffmuc.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=karthikchikmagalur@gmail.com; helo=mail-pl1-x636.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -5.79 X-Spam-Score: -5.79 X-Migadu-Queue-Id: EC8D185149 X-Migadu-Scanner: mx10.migadu.com X-TUID: eTgdKmxzUtVs >> I'm interested in adjusting org-latex-preview to work in other major >> modes (most notably LaTeX-mode itself, so one can get rid of preview.el). >> On the advice of Karthik (Cc'd) I'll move the discussion from private >> mails to this list, so more people who might be interested can join in. >> ... >> [1]: https://abode.karthinks.com/org-latex-preview/latex-preview-everywhere.html > > Abstracting away previews is certainly welcome. > RMS explicitly asked Org mode team to work towards this goal: > https://list.orgmode.org/E1kIkxv-0007iy-Av@fencepost.gnu.org/ I recently spent some time on this feature (LaTeX previews in all major-modes) and produced a few prototypes. You can see some demos in https://www.youtube.com/watch?v=u44X_th6_oY [1] The way support for other major modes works right now is based on the following observation: The `org-latex-preview' feature uses a tiny subset of the `org-element' API. Specifically, it uses only the functions - `org-element-context' - `org-element-property', referring to the properties :value, :begin and :end, and optionally :post-blank and :post-affiliated - `org-element-type', which returns either latex-fragment, latex-environment or any other symbol In addition, it uses two functions to generate the preamble and find section bounds: - `org-latex-preview--get-preamble' - `org-latex-preview--section-bounds' If a major-mode can provide drop-in replacements for all these functions, we can run org-latex-preview -- all of it, including live previews etc, in that mode.[2] I can share the full code in a dev branch soon after cleaning it up. In this email, I was hoping to solicit some feedback on the Emacs-wide API for this, which I describe below: ---------------------- I made calls to the above `org-elment-*' functions "pluggable", by storing these functions in buffer-local variables named - `org-latex-preview--fcontext' - `org-latex-preview--fproperty' - `org-latex-preview--ftype' and so on. Instead of calling `org-element-*' like this: (org-element-property :value (org-element-context)) org-latex-preview now uses (funcall org-latex-preview--fproperty :value (funcall org-latex-preview--fcontext)) A major mode can register these handlers with org-latex-preview like this (example for previews in LaTeX-mode, adapted from Tony's code): (setf (alist-get 'LaTeX-mode org-latex-preview-interfaces) `(:preamble ,#'latex-latex-preview--make-preamble :section ,#'latex-latex-preview-section-bounds :context ,#'latex-latex-preview-context :type ,#'latex-latex-preview-type :property ,#'latex-latex-preview-property)) See [1] for the definition of these `latex-latex-*' functions. These functions in `org-latex-preview-interfaces' are set as the values of the various `org-latex-preview--f*' variables during the first call to org-latex-preview in the buffer. There is no continuous runtime dispatch based on the major-mode. (Since we run many of these functions in the `after-change-functions' hook, we really want to avoid runtime dispatch.) Is this the best way to go about this? Karthik [1]: To see what the "adapter" code looks like for different modes, here are some examples: https://paste.karthinks.com/ac64169c-prog-latex-preview.el.html https://paste.karthinks.com/6ba26238-calc-latex-preview.el.html https://paste.karthinks.com/44930b4e-latex-latex-preview.el.html [2]: This is without handling accurate numbering. Numbering requires a couple more replacement functions that I can describe if required.