From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id KJqhD6XcEmaHSwEA62LTzQ:P1 (envelope-from ) for ; Sun, 07 Apr 2024 19:49:25 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id KJqhD6XcEmaHSwEA62LTzQ (envelope-from ) for ; Sun, 07 Apr 2024 19:49:25 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fWx7Smbh; 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=1712512165; a=rsa-sha256; cv=none; b=fk1ttguNX9lajUbHZuJnHcTMlEw2ymc30p1W4MDOFB39QwWnG699pY+vAkUnoSruYojnqq EbCiOK+sxlcWXQCaOVjOCBHlM9khAO5Ua0b34r7ksYCcfmQLQD8/puZLuo/b4XqopH0FBO ENHLDwh8kRsdZA1d3FlSRce8poV9/QVTCBV2Jhj2lBl4LVIycJCUw1x7BA+XefQmFbDoiU aQsV2f6uuFrHL7cS1RoDhPXIJ1gI5JygqiXul/Y0doS1xQNoE1lxgvsXP8+TTIavo4VWiY keYsBriWJBkNULP4IMNIxnIDzfm+Pinkp+8cEri1CBBsVPD4UiAe9zO+dz9xCA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fWx7Smbh; 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=1712512165; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=zemq9HAlEpuM4jnaII8QVc4Y2/gY4vf+64by8HJGOAI=; b=T78yXPii6jxtbMLIuKo1SowSPUPv2W4qnFgP9hxagmHyfEJvkXVtd2K/BxYKXBI/KlzwGy ff9xJMj/jqz5UghftMW+mGu6wHrWR4oQDgkPM+E3TjCz6mWZoeOUqo+691UKvKRZx56xYE RmRDjdTi67PvbNLBedwDK4UJ/JIQP1bKkXSnqV8NJMsInDfVQP0+XZHEEY9abIVyZXMu2s n2p5w2KeK3vLkEc+9mCWCQeOa64ujx/9jwiAhdAX4smg/CN4r1hxDrERm9abYkaQqqF2EQ ZPui7Ioyiqiq/wnB9qRB5Szgn634MhJEfJqktSxSiDg6ilTZCwhXKhvZz3Ee2w== 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 079EE2616D for ; Sun, 7 Apr 2024 19:49:25 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtWdh-0005eC-8f; Sun, 07 Apr 2024 13:49:09 -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 1rtWdd-0005bf-JS for emacs-orgmode@gnu.org; Sun, 07 Apr 2024 13:49:05 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rtWdX-00014u-PX for emacs-orgmode@gnu.org; Sun, 07 Apr 2024 13:49:05 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1e3ca4fe4cfso9978705ad.2 for ; Sun, 07 Apr 2024 10:48:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712512137; x=1713116937; darn=gnu.org; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=zemq9HAlEpuM4jnaII8QVc4Y2/gY4vf+64by8HJGOAI=; b=fWx7SmbhXTA0tuq2AsrM7DLCcDyxlHYiWG/3jgmd8IAqRY1Dy1nk+R+wcMJLi4pEcL /b7PZZgF5Q9kPu7GSjbtZpBIQxVS35UD0OFwq9+Rm1DrdlAu3qaUpfblVXbTic+0/O8F UTUqfoX+kUOTJ7g9nnWChqx13bVE8HnGa9bo4pSMG1Nandxy31WoAQCd0VjAHcjcA7SA mSVVElU52WKu0D6O9TDOFqxjh7IHIaxzZauG/DxOXBRlD0P7D1ti90SbqE/63aBQiwkw 1i3MLdRAIkdX/kfrK9icxmeOvoeeXKz37E8vvAf0toPAvpurnfQJOKQbxO05CFxk5Zvf zVUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712512137; x=1713116937; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:to:from:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=zemq9HAlEpuM4jnaII8QVc4Y2/gY4vf+64by8HJGOAI=; b=T1GkI3f6lSVsictlkiRHvBdK3JeDuDsKRlSski2I0gkVsfizASXmaN6yNRXOBh/L+/ jM4QOFMVKC5sTCcQUn4T9XSOQqyy8W68fBDc6pee6Xexy2MEV+OVGaSYxFid9CTVQ258 hA6egENECiGwwr168ALnV+1D0Inkek9w705WuyVZNZptUSqCUIKkrJn9ivnpjsGx2Lcv Q3K/ExFKi4cM4Im92frRdF4SfR4ERbpMonxdJhFI9JBZT0pDhMkiuYE2eg9W5B3b+Cvd sOwMGFHFUacQgmxSnzaT2aZJ4IT9c84m/mbisCY91skAl5ZpUOs4voaS37Zheoa6mGlh xr9A== X-Forwarded-Encrypted: i=1; AJvYcCVg6Z+54BYZuDPATTNgHO9/zXYvGIDiMt5iBMTZQw4vEPoSeQ1mTfxJY8CCMPA+IzK0UUwfzv1zHviQar0sK5MNQ/V/6hE= X-Gm-Message-State: AOJu0YyipAwsLGm6fcbUziqVyklofOUgzvX5PkU4zmjsaA9YzdR35i2S gWjkq0LeNBVlcG3ka6IHf9OYY90s6jifUYotUD9pEwwgmz4AsOuxKqgSedYm X-Google-Smtp-Source: AGHT+IGggyjZIsx4mZ0vAmqTqUgKtptTV3Nky8zz+K6kC8O3gs8aLUHdh4nhjYrzzqrqc0CNWAb4IQ== X-Received: by 2002:a17:902:ce89:b0:1e4:25e8:c2f1 with SMTP id f9-20020a170902ce8900b001e425e8c2f1mr942525plg.29.1712512137436; Sun, 07 Apr 2024 10:48:57 -0700 (PDT) Received: from localhost ([2600:8802:5726:2500:4084:633a:9e6d:2dee]) by smtp.gmail.com with ESMTPSA id a13-20020a170902eccd00b001e3e0a6e76csm2741894plh.99.2024.04.07.10.48.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 10:48:56 -0700 (PDT) From: Karthik Chikmagalur To: Tony Zorman , emacs-orgmode@gnu.org Subject: Re: Using org-latex-preview in other major modes In-Reply-To: <87edbhljr7.fsf@hyperspace> References: <87edbhljr7.fsf@hyperspace> Date: Sun, 07 Apr 2024 10:48:56 -0700 Message-ID: <874jcdf4hj.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=karthikchikmagalur@gmail.com; helo=mail-pl1-x633.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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-Flow: FLOW_IN X-Migadu-Country: US X-Spam-Score: -9.66 X-Migadu-Queue-Id: 079EE2616D X-Migadu-Spam-Score: -9.66 X-Migadu-Scanner: mx10.migadu.com X-TUID: bedbv3SfMPma Hi Tony, Just tried it out, it's very promising! Thanks for taking the initiative on this. > I've prodded the code a little bit and, mostly just following [1], > managed to implement basic previews in a relatively straightforward > fashion. Attached is a proof-of-concept=E2=80=94aptly named > latex-latex-preview.el :) The main user facing functions so far are > 'latex-latex-preview' to preview the maths fragment at point, and > 'latex-latex-preview-region' to preview all fragments in a region. Both > functions currently ignore things like numbered equations and > environments, though both do not seem exceptionally difficult to add > back in. There are two issues with numbering: - providing an Org-agnostic API point to attach a numbering table to, and - calculating the new numbering table in LaTeX (or other major-modes). For The first issue, we need a way to provide an updated numbering table during the auto-regeneration of edited fragments. Currently this is done implicitly by calling `org-latex-preview--place-from-elements' from the `--regenerate-overlay` function. The second requires fast numbering table updates. We do it in Org by mapping over the org-element cache (see `org-latex-preview--get-numbered-environments'). Even this is too slow sometimes, so we suspend numbering updates when live-previewing until the cursor exits the fragment. Parsing the LaTeX buffer from point to the end when (re)generating each preview is going to be too slow, so you'll have to create some kind of cache and update it incrementally. > There's also a stub 'latex-latex-preview-auto-mode' minor mode. Stepping > in and out of already rendered environments works fine, with the preview > being regenerated if needed; only the implementation of > 'org-latex-preview-auto--regenerate-overlay' had to change for that. This was a pleasant surprise, I was expecting more trouble here. > The mode does not currently feature live-previews. The innards of > 'org-latex-preview-auto--detect-fragments-in-change' and > 'org-latex-preview-live--setup' look a bit more org-specific, with > queries to 'org-element-*' functions all over the place, but all of > that looks fixable=E2=80=94at least from afar. I will continue prodding t= he > code a little bit and will report back with any bumps that are hit > along the way. `org-latex-preview-auto--detect-fragments-in-change' is written for speed. It only does quick text-matching and is thus mostly Org-agnostic, except for a call to a numbering calculation near the end. This should be easy to adapt. The problem is the function it calls, `org-latex-preview-auto--maybe-track-element-here', which finds the bounds of the inserted LaTeX fragment using org-element and conditionally sets up a preview overlay. You will need an equivalent of this for LaTeX-mode. Since you have auto-mode working already, live previews should be quite easy to add. From what I can see, you only need to provide your own `org-latex-preview-live--ensure-overlay'. This function creates the preview overlay next to or under the LaTeX fragment. All the other live preview code only changes overlay properties or calls `--regenerate-overlay`, which you've already implemented. Karthik