From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.bugs Subject: bug#44842: 28.0.50; Support texed latex as Calc language Date: Tue, 24 Nov 2020 15:58:33 +0100 Message-ID: <87eekiby3q.fsf@web.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16957"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , Stefan Monnier , Roland Winkler To: 44842@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 24 15:59:10 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1khZmg-0004D9-Hz for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 24 Nov 2020 15:59:10 +0100 Original-Received: from localhost ([::1]:56754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1khZmf-0002o9-5g for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 24 Nov 2020 09:59:09 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1khZmY-0002o1-2y for bug-gnu-emacs@gnu.org; Tue, 24 Nov 2020 09:59:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49262) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1khZmX-0008Ls-Rq for bug-gnu-emacs@gnu.org; Tue, 24 Nov 2020 09:59:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1khZmX-0004Rx-QC for bug-gnu-emacs@gnu.org; Tue, 24 Nov 2020 09:59:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Michael Heerdegen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 24 Nov 2020 14:59:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 44842 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.160622992717083 (code B ref -1); Tue, 24 Nov 2020 14:59:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 24 Nov 2020 14:58:47 +0000 Original-Received: from localhost ([127.0.0.1]:60808 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1khZmJ-0004RS-3s for submit@debbugs.gnu.org; Tue, 24 Nov 2020 09:58:47 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:56164) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1khZmH-0004RL-Tm for submit@debbugs.gnu.org; Tue, 24 Nov 2020 09:58:46 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51514) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1khZmH-0002mD-Kt for bug-gnu-emacs@gnu.org; Tue, 24 Nov 2020 09:58:45 -0500 Original-Received: from mout.web.de ([212.227.17.12]:37149) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1khZmF-0008FQ-MT; Tue, 24 Nov 2020 09:58:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1606229915; bh=ifUJ2CSd3TlODdUHqhnBAj1TNrowXCILTbIVzIO9wiE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=gayPPOMSuGbUmtRXnBgX5snVs3H0a8+R/C+N44OEdcXJPuDyT3g0khHxlOX6vmbha 5BFWfmJHbPUh6D6zBq6AVpRWgF4/5zIsgTyQqLhW0epRxDbbTThzPcnr5Hs8ObKarA 1GeAueb6sJtfApXUTR/g81Rbn9VQxsNzHL5fqGKI= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Original-Received: from drachen.dragon ([94.218.219.247]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MNwjS-1kscPD0Lvs-00OXwu; Tue, 24 Nov 2020 15:58:35 +0100 X-Provags-ID: V03:K1:TltizgzlEkyiYLMywjR0kic6KlxjjgETdvHcIOBInQTGAnTRBEP YNcLI2qGdb0H0C0Bz7C+JcfSajEQ7L1nnq6r8D21JDKOhwSuwKefgs9ouiU7WuSp695P7FP cH+uCrrkNTlpnfHhgLNguPAsEWlSKTOXM7YwWNSHVBTmIdoj5b8ViBaAuqgBcCvEOhj2m3q d+zYIsgZ385wzbLsc2DrA== X-UI-Out-Filterresults: notjunk:1;V03:K0:MmQHzDGSZzc=:0wR4BN/z/EYj/zBhRqRfMz z5Ba8ExKDtpte9fNe3kpYiEdJRL1tDOrJyGyOswnNRxLnRQZbbAOxBdD1UhRtVE9dtOS6hThv VS9iLHy+VkBCCllbxWF8FY/coapstSY/zkZm0u2MVk23XSrXgvf8OMPdjkrEhDv0/jSo9QX6+ ZKxkMLY7HQ5Ogqp1Xzamqafp2dbZHMeBUqtGWBuC4Xyrq1CIgyvoBpPlyVWoS+A40SxP4ynMp KoFwBQXFr55QUyfzj0KlhJPaKDlWaj5ZD7rJe1chLMuuH7PYoEqNPrKYrgRnwW1DzDDFC3t0R 8OOsvq5q4Me8pC1AbnaS2nObzPlNDqg7J0WggYolx0FnBXntR0knZ4JILfI/P31dacTngPXpu CUckH5dC6ncrjsDTgmyFvT2tlQcfsdUT+280gh3sIru+14dIV7O9W0/IeDvl2RbVGl1DrLu1Z 6tEetRXIpwbRn7686RHWwsZDYP2SmQZFNrfxvWHAELmaDmb/+TcQXnjOO9qpPo9pCREsuIJ3i YN+ec57b47uHqLZacVjco1mpszoZpytQJG6Z6hdplO5KcLvNjt4hbBpU5tYwV1C+x1CLxO/z8 DPZAeW9mKHmlmg4J2mm9+a5L4BRpfRPLZCdQOWi1F71kYmQX5MJjUk4B+UfyYvBnDouHiH+up lZVzjV8dJZdZNbIszuLMQWlYKD29dY0F2h2vLgeA68k9yjtm9MCA7+iQ2sirRFBZxMiYb21ha 1mxzkE+Ul7wSKSz9AnbpKNYmFxng+i6/dTT1yEs8S5Yk2Dv72ykwKkTV5+C4U3eCI9ws14Y7 Received-SPF: pass client-ip=212.227.17.12; envelope-from=michael_heerdegen@web.de; helo=mout.web.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:194071 Archived-At: --=-=-= Content-Type: text/plain Hello, Roland, Mattias, if you can help, Stefan CC'd for information since I had discussed this with him on emacs-help: I want to enable Calc latex language mode to support latexed output as an image. Can someone please help me to prepare an according patch? Here is my prove of concept so far, working for me in a master emacs -Q: --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=calc-latex.el Content-Transfer-Encoding: quoted-printable (require 'org) (require 'org-element) (require 'ox) (require 'image) (require 'calc) (require 'calc-lang) (calc-set-language 'latex +2 'no-refresh) (defun my-latex-output-filter (s) (cl-flet ((overlay-latex-string-with-image (lambda (latex-string) (with-temp-buffer ;; Use package "breqn" because it provides an environment = that allows ;; linebreaks inside parenthesized expressions (insert (concat "\\begin{dmath*} " latex-string " \\end{dm= ath*}\n")) (let ((org-latex-packages-alist (cons '("" "breqn" t) org-latex-packages-alist))) (cl-letf (((plist-get org-format-latex-options :scale) 1= .333)) (org-format-latex (format "/tmp/%s/ltximg/org-ltximg" user-login-name) (point-min) (copy-marker (point-max)) "/tmp/" nil nil 'forbuffer 'dvipng))) (goto-char (point-min)) (if (search-forward-regexp "\\[\\[file:\\(.*\\)\\]\\]" nil= t) (match-string 1) nil))))) (when (string-match-p "\n" s) ;; We can't make one image per line as I would prefer since Calc adds ;; line breaks that cuts parenthesized expressions ;; Event this doesn't work as expected: (setq s (replace-regexp-in-string "\n" "\\\\\\\\\n" s))) (setq-local auto-window-vscroll t) (let (prefix latex-string) (if (string-match (rx bos (group (* space)) (group (+ anychar)) eos) = s) (setq prefix (match-string 1 s) latex-string (match-string 2 s)) (setq prefix "" latex-string s)) (let ((file (overlay-latex-string-with-image latex-string))) (concat prefix (if file ;; FIXME: I guess we want a key to let us see the latex= text? (propertize latex-string 'display (create-image file 'png nil :mask 'heuristi= c :ascent 0) ;; 'keymap image-map ; This may interfere w= ith Calc bindings! ) latex-string)))))) (put 'latex 'math-output-filter 'my-latex-output-filter) --=-=-= Content-Type: text/plain I'm using the latex "breqn" package because it allows me to use the line breaks that Calc adds to the output by itself; that looks very good most of the time, is even a bit aware of the window width, and doesn't make latex barf when line breaks appear inside paren expressions (as it does normally). I don't know if I can assume that every latex installation has "breqn" installed. Without something like "breqn" the results were not satisfactory in my experiments, I found that solution after a long with trouble. Then, for subformula editing etc., we probably want to provide a way to turn the image into the source output and back. And: how should this feature be enabled? Should it be provided as a separate language? The one dimension we have for the prefix arg of d L is already completely exhausted. Anything else I forgot to consider? I guess it would be nice to get rid of all or most of the org dependencies. Oh, and I didn't mention yet that this is super cool and thus has a high priority to have ;-) Regards, Michael. In GNU Emacs 28.0.50 (build 5, x86_64-pc-linux-gnu, GTK+ Version 3.24.23, cairo version 1.16.0) of 2020-11-24 built on drachen Repository revision: 9a574a6e51d669eaff091ab590fb18733a386d2c Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12008000 System Description: Debian GNU/Linux bullseye/sid --=-=-=--