From: Pranshu <pranshusharma366@gmail.com>
To: emacs-devel@gnu.org
Subject: table.el, adding an option to customize escaping in latex export
Date: Wed, 29 May 2024 01:06:20 +1000 [thread overview]
Message-ID: <87r0dm9dsj.fsf@pebl> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: table.diff --]
[-- Type: text/x-diff, Size: 3649 bytes --]
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
[-- Attachment #2: Type: text/plain, Size: 715 bytes --]
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.
reply other threads:[~2024-05-28 15:06 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r0dm9dsj.fsf@pebl \
--to=pranshusharma366@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.