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: Fix Table.el export Date: Sun, 02 Jun 2024 22:33:04 +1000 Message-ID: <878qznikxr.fsf@gmail.com> 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="3947"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: pranshusharma366@gmail.com Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jun 02 14:38:41 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 1sDkTv-0000vj-OF for ged-emacs-devel@m.gmane-mx.org; Sun, 02 Jun 2024 14:38:39 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sDkSy-0002RK-Bz; Sun, 02 Jun 2024 08:37:40 -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 1sDkOj-0001nl-3I for emacs-devel@gnu.org; Sun, 02 Jun 2024 08:33:17 -0400 Original-Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sDkOh-0002MG-Ck for emacs-devel@gnu.org; Sun, 02 Jun 2024 08:33:16 -0400 Original-Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-6f8d0a00a35so2005744a34.2 for ; Sun, 02 Jun 2024 05:33:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717331589; x=1717936389; darn=gnu.org; h=mime-version:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=JKVezOAKS+feufSOImRmQFmMM2ZjTPX0HC321Wc4lAk=; b=X1fwW+r/5BEAbKj6N3BDT8R0uBYqql6AOBFQ9tsuH80GaQaVMtMrCyM7i3Z7q2iNqq 4+cF38LR2Fwj5HQK3rM2dA3ZaF9wXvhf/0JdZjw35eQydFGTEPsVp20oKCPJnL8XoRuS mlEaFU85MuygrcUINeP9lkjtzYd4nrDeuZSy9RA9PGImflY73W37cvmYEqv5hx/Lq5pb Rln3Up8QRwM30Kr8jQbKW+2QkbbcreFQK2VmwZLKKp6QCY6JQqt+GrFNGRvd8o5fx5+W OjO/cqs4kVYRnD67tdIammAhFINduOS7BNQA5Gyjh4yb3zyyRIeWaafxrNMFYU9sxw4Z jdag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717331589; x=1717936389; h=mime-version:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=JKVezOAKS+feufSOImRmQFmMM2ZjTPX0HC321Wc4lAk=; b=MkL3UYUw8eahJlH8QKdj374zDhPad+meZRXMT18bYxgdaqW00oUJGHNO99Jaw5lnvN iZPpMoGB9wmyG5qG1DTjxuWhH93hDEaS3ADHwmoENY7zH6QEOICaAERO1agIxaZfK+c8 OQaRup2GnyKSDXEmbk9mBg7gv693kyTnr5twL4BO1NuP/7quqg/Mk6nYQOid7mIyRFFf OQLELC0lV+vbZDP7I32TJFOj20bCUGrdgIUsEtdGxQpySHXgaO+VTUAYUYiAp6T4Zcw/ qM9hfwkhLr4UrqAEyNAyMIoc5BohagfJnfesiHl5mL8aWj6ck/bTHK5KopfHtfn+GTyS es2w== X-Gm-Message-State: AOJu0YzjJkXOlcexaKV0Peu8vFlfSjww7HNBWpggn6IJjLvt/kBDhQcu LJfuQgq4pX4Lio5p3JbjE0K0Ig0dF6fuemXdKJ+GQju41b+g34da0elEpRX5 X-Google-Smtp-Source: AGHT+IFGAXOsy9J5OLB+2hL0U5L3s0jlCeoVrjr59PC/TgUPIorgSflyK5KbgBS+Ediju41wk3939w== X-Received: by 2002:a05:6871:291:b0:23d:45cd:ee47 with SMTP id 586e51a60fabf-2508b9bc8e5mr6787964fac.21.1717331589061; Sun, 02 Jun 2024 05:33:09 -0700 (PDT) Original-Received: from pebl ([2001:8003:7816:8300:7f15:5962:16a0:6470]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70245aa1982sm3703854b3a.163.2024.06.02.05.33.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jun 2024 05:33:08 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::331; envelope-from=pranshusharma366@gmail.com; helo=mail-ot1-x331.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: Sun, 02 Jun 2024 08:37:39 -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:319782 Archived-At: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; 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 exports to latex, charecters like '$' are all escaped. This makes table.el tables practically useless for any sorts of latex export. Attached is a diff that adds a variable that controls what should be escaped. --=-=-=--