From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pranshu Newsgroups: gmane.emacs.devel Subject: table.el, adding an option to customize escaping in latex export Date: Wed, 29 May 2024 01:06:20 +1000 Message-ID: <87r0dm9dsj.fsf@pebl> 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="40122"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue May 28 17:13:57 2024 Return-path: Envelope-to: ged-emacs-devel@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 1sByWS-000AGH-Mi for ged-emacs-devel@m.gmane-mx.org; Tue, 28 May 2024 17:13:56 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sByVy-0002bk-9A; Tue, 28 May 2024 11:13:26 -0400 Original-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 1sByPE-0006ky-Jh for emacs-devel@gnu.org; Tue, 28 May 2024 11:06:28 -0400 Original-Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sByPC-0008B4-Jk for emacs-devel@gnu.org; Tue, 28 May 2024 11:06:28 -0400 Original-Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6f4603237e0so659250b3a.0 for ; Tue, 28 May 2024 08:06:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716908784; x=1717513584; darn=gnu.org; h=mime-version:message-id:date:subject:to:from:from:to:cc:subject :date:message-id:reply-to; bh=+mAaba+jGK0IvTUCdl89iRXnsAi6Jv2Ek8h4wIAX+lg=; b=C/DI7jonTH4f+BE9l+mrKEXJkBomOxeX/filJvAVrFg/pH9O07OgE9mfSluFNV1yYx 67tut66BG56Rtd3936VGSOgdR6B+k17ba3UeyVi1neVhiRaWyw+p8NwPDQmvfzEAIxd+ 0KDjI8Ht6gZNhpQj0cdcjwYnGuiCnZsJoybCyTO2BAHoPQc/1kZJNAsLH6+QtoL+V6aL W+nrl1WOn71aqLhC3w0yDFIiFTib1azHuYAq0a205V1RIpPEqXmPSlY/ocGcLxkBqZYG xiHMWcZwlRqYs0l4oOzGUun799sFDWfu2OzYFVosRfPVI8UUwwBX0aSDBy4mTnCheKFX GWbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716908784; x=1717513584; h=mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=+mAaba+jGK0IvTUCdl89iRXnsAi6Jv2Ek8h4wIAX+lg=; b=rRhgchDnUdTb5ZWnwpslrWPAVHn8NC6/Q/fHE7aqM0B1PtZAKkp5OLZhl9JDG2gT6L Q5CyKg096rKu1THtuCherX6+DEkRunqClZrjJu0zintFME1pLD7VRPuoCYm8uM6lExbR NHV56aRKDDJu60Fe+UggGY3BTbxeghD9o973McJ526Ozbl8rsg8w1r2uDKWfqPBlJfnZ /gogOASFNXgwn8yUZ6JVoPmZaDBpO0JiQBx2jyhHwuVPy1PLGJhTUKgGutPiZCdA+Wxp T1OPMlRFMD8ABnRqtU814GnGPWypiywIA4XnXrPuhpdIV971PXHEjxGg26+erS6SIH2X JT3Q== X-Gm-Message-State: AOJu0Yz1QzEA8vlr4KQubUI5hGPHkaQXHSWV462xXKJjCA9hSaTSUD21 xTWylPhGXtZ8GAvcl3ivt5bMUku55o5q3RCkMxs8ffS2VBzY4EeBxGz4/Q== X-Google-Smtp-Source: AGHT+IHZT/XriXa/TdETC9RxbyHy9YmE5rRi0CLzg78s/QXOreZCxDUylmsJHJA51j2OsaBgGsD+ow== X-Received: by 2002:a05:6a00:1d93:b0:6ff:7ea6:d5ae with SMTP id d2e1a72fcca58-6ff7ea70f30mr12230673b3a.6.1716908783885; Tue, 28 May 2024 08:06:23 -0700 (PDT) Original-Received: from pebl ([2001:8003:7816:8300:7f15:5962:16a0:6470]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f8fc373c92sm6695509b3a.96.2024.05.28.08.06.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 08:06:23 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=pranshusharma366@gmail.com; helo=mail-pf1-x429.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 28 May 2024 11:13:24 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:319651 Archived-At: --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=table.diff diff --git a/lisp/textmodes/table.el b/lisp/textmodes/table.el index 19c6a8d7c4..28401084a6 100644 --- a/lisp/textmodes/table.el +++ b/lisp/textmodes/table.el @@ -697,6 +697,19 @@ table-word-continuation-char :type 'character :group 'table) +(defcustom table-source-latex-escape-characters (cons "[#$~_^%{}&]" t) + "A cons cell containing which charecters to escape in the latex source +of `table-generate-source'. The head of the list, if non-nil contains a +regexp that matches all text that is to be adding a preceding backslash +to the matching text. If nil, no non-backslash charecters will be +escaped. The tail, if non-nil, escapes all the backslashes in the latex +source." + :tag "Source Latex Escape Charecters Regexp" + :type '(cons (radio (regexp :tag "regexp") + (const :tag "Off" nil)) + boolean) + :group 'table) + (defcustom table-detect-cell-alignment t "Detect cell contents alignment automatically. When non-nil cell alignment is automatically determined by the @@ -3264,19 +3277,29 @@ table--generate-source-scan-lines (lambda (from to) (let ((line (table--buffer-substring-and-trim (table--goto-coordinate (cons from y)) - (table--goto-coordinate (cons to y))))) + (table--goto-coordinate (cons to y)))) + (escape-char-reg + (apply 'concat (append (and (car table-source-latex-escape-characters) + (list "\\(" + (car table-source-latex-escape-characters) + "\\)" + (and (cdr table-source-latex-escape-characters) + "\\|"))) + (and (cdr table-source-latex-escape-characters) + (list"\\(\\\\\\)")))))) ;; escape special characters (with-temp-buffer (insert line) (goto-char (point-min)) - (while (re-search-forward "\\([#$~_^%{}&]\\)\\|\\(\\\\\\)\\|\\([<>|]\\)" nil t) - (if (match-beginning 1) - (save-excursion - (goto-char (match-beginning 1)) - (insert "\\")) - (if (match-beginning 2) - (replace-match "$\\backslash$" t t) - (replace-match (concat "$" (match-string 3) "$")) t t))) + (when (or (car table-source-latex-escape-characters) + (cdr table-source-latex-escape-characters)) + (while (re-search-forward escape-char-reg nil t) + (if (and (car table-source-latex-escape-characters) + (match-beginning 1)) + (save-excursion + (goto-char (match-beginning 1)) + (insert "\\")) + (replace-match "$\\backslash$" t t)))) (setq line (buffer-substring (point-min) (point-max)))) ;; insert a column separator and column/multicolumn contents (with-current-buffer dest-buffer --=-=-= Content-Type: text/plain When table.el tables are exported to latex, stuff like the dollar sign is all escaped, so that you cannot make a table of latex equations. This diff just adds a variable that works adding a variable that let's the user control what is escaped and what is not. Since backslashes cannot be escaped the same way as charecters like '$', instead of making 2 vairbales( one for backslash and other for chars), I just added one cons cell. Instead of using string, I think using regexp better choice as it allows for more complex escaping, such as turning mentions of "LaTeX" to "\Latex". Overall, this fixes the problem of being able to have column wrapped paragraphs which include tex equations in some org exports. --=-=-=--