* Removing horizontal space in latex fragments @ 2019-12-05 19:03 Matt Huszagh 2019-12-05 22:24 ` Fraga, Eric 0 siblings, 1 reply; 7+ messages in thread From: Matt Huszagh @ 2019-12-05 19:03 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 1144 bytes --] I've modified the behavior of `org-create-formula-image' so that `\definecolor' etc do not create unnecessary whitespace in the output PDF. Here's the relevant change: ``` ... ;; remove tex \par at end of line (if (string= (substring string -1 nil) "\n") (aset string (- (length string) 1) ?%) (setq string (concat string "%"))) (with-temp-file texfile (insert latex-header) (insert "\n\\begin{document}\n" "\\definecolor{fg}{rgb}{" fg "}%\n" "\\definecolor{bg}{rgb}{" bg "}%\n" "\n\\pagecolor{bg}%\n" "\n{\\color{fg}\n" string "\n}\n" "\n\\end{document}\n")) ... ``` This is useful if you (like me) have replaced the default document class with standalone and are using dvisvgm. The change removes leading left and right space, which is especially useful when using inline math mixed with normal text. It shouldn't make a difference if using Imagemagick's convert as a backend since that can get rid of whitespace boundaries. Is anyone else interested in this modification? Should I submit it as a patch? Matt [-- Attachment #2: Type: text/html, Size: 1580 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Removing horizontal space in latex fragments 2019-12-05 19:03 Removing horizontal space in latex fragments Matt Huszagh @ 2019-12-05 22:24 ` Fraga, Eric 2019-12-06 7:42 ` Matt Huszagh 0 siblings, 1 reply; 7+ messages in thread From: Fraga, Eric @ 2019-12-05 22:24 UTC (permalink / raw) To: Matt Huszagh; +Cc: emacs-orgmode@gnu.org On Thursday, 5 Dec 2019 at 11:03, Matt Huszagh wrote: > Is anyone else interested in this modification? Should I submit it as a > patch? I think so. And I am not sure all those \n's are necessary. Without them, you can probably also remove many of the %s. -- Eric S Fraga via Emacs 27.0.50, Org release_9.2.6-544-gd215c3 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Removing horizontal space in latex fragments 2019-12-05 22:24 ` Fraga, Eric @ 2019-12-06 7:42 ` Matt Huszagh 2019-12-06 13:24 ` Fraga, Eric 2019-12-14 14:57 ` Nicolas Goaziou 0 siblings, 2 replies; 7+ messages in thread From: Matt Huszagh @ 2019-12-06 7:42 UTC (permalink / raw) To: Fraga, Eric; +Cc: emacs-orgmode@gnu.org [-- Attachment #1.1: Type: text/plain, Size: 725 bytes --] Thanks for the reply Eric. The thing I like about the newlines is that the generated tex files are slightly easier to read. However, this is really minor. I've created 2 separate patches: one keeping the newlines and the other without. I'm happy to defer to you or anyone else in regard to which is preferable. On Thu, Dec 5, 2019 at 2:24 PM Fraga, Eric <e.fraga@ucl.ac.uk> wrote: > On Thursday, 5 Dec 2019 at 11:03, Matt Huszagh wrote: > > Is anyone else interested in this modification? Should I submit it as a > > patch? > > I think so. And I am not sure all those \n's are necessary. Without > them, you can probably also remove many of the %s. > -- > Eric S Fraga via Emacs 27.0.50, Org release_9.2.6-544-gd215c3 > [-- Attachment #1.2: Type: text/html, Size: 1051 bytes --] [-- Attachment #2: remove-newlines.patch --] [-- Type: application/octet-stream, Size: 1421 bytes --] From baf9812cb050c804d4d12bf3e2819bd4a5987722 Mon Sep 17 00:00:00 2001 From: Matt Huszagh <huszaghmatt@gmail.com> Date: Thu, 5 Dec 2019 23:16:39 -0800 Subject: [PATCH] org.el: Remove leading/trailing whitespace from latex fragment * lisp/org.el (org-create-formula-image): Ensure user input ends with a % character to remove trailing whitespace. Also, remove newlines from macro calls. --- lisp/org.el | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 9b84592ba..4e3dbe4c3 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -16554,13 +16554,18 @@ a HTML file." (setq bg (org-latex-color :background)) (setq bg (org-latex-color-format (if (string= bg "Transparent") "white" bg)))) + ;; remove tex \par at end of snippet to avoid trailing + ;; whitespace + (if (string= (substring string -1 nil) "\n") + (aset string (- (length string) 1) ?%) + (setq string (concat string "%"))) (with-temp-file texfile (insert latex-header) (insert "\n\\begin{document}\n" - "\\definecolor{fg}{rgb}{" fg "}\n" - "\\definecolor{bg}{rgb}{" bg "}\n" - "\n\\pagecolor{bg}\n" - "\n{\\color{fg}\n" + "\\definecolor{fg}{rgb}{" fg "}" + "\\definecolor{bg}{rgb}{" bg "}" + "\\pagecolor{bg}" + "{\\color{fg}\n" string "\n}\n" "\n\\end{document}\n")) -- 2.24.0 [-- Attachment #3: keep-newlines.patch --] [-- Type: application/octet-stream, Size: 1399 bytes --] From bdb93a13a43d90ad6e66449797111e836a67a219 Mon Sep 17 00:00:00 2001 From: Matt Huszagh <huszaghmatt@gmail.com> Date: Thu, 5 Dec 2019 23:25:32 -0800 Subject: [PATCH] org.el: Remove leading/trailing whitespace from latex fragment * lisp/org.el (org-create-formula-image): Ensure user input ends with a % character to remove trailing whitespace. Also, add % characters between macros and newlines purely visual. --- lisp/org.el | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 9b84592ba..ae686e330 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -16554,12 +16554,17 @@ a HTML file." (setq bg (org-latex-color :background)) (setq bg (org-latex-color-format (if (string= bg "Transparent") "white" bg)))) + ;; remove tex \par at end of snippet to avoid trailing + ;; whitespace + (if (string= (substring string -1 nil) "\n") + (aset string (- (length string) 1) ?%) + (setq string (concat string "%"))) (with-temp-file texfile (insert latex-header) (insert "\n\\begin{document}\n" - "\\definecolor{fg}{rgb}{" fg "}\n" - "\\definecolor{bg}{rgb}{" bg "}\n" - "\n\\pagecolor{bg}\n" + "\\definecolor{fg}{rgb}{" fg "}%\n" + "\\definecolor{bg}{rgb}{" bg "}%\n" + "\n\\pagecolor{bg}%\n" "\n{\\color{fg}\n" string "\n}\n" -- 2.24.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: Removing horizontal space in latex fragments 2019-12-06 7:42 ` Matt Huszagh @ 2019-12-06 13:24 ` Fraga, Eric 2019-12-14 14:57 ` Nicolas Goaziou 1 sibling, 0 replies; 7+ messages in thread From: Fraga, Eric @ 2019-12-06 13:24 UTC (permalink / raw) To: Matt Huszagh; +Cc: emacs-orgmode@gnu.org Not really worried about which alternative is chosen. I was just exhibiting my inner compulsive nature... ;-) -- Eric S Fraga via Emacs 27.0.50, Org release_9.2.6-544-gd215c3 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Removing horizontal space in latex fragments 2019-12-06 7:42 ` Matt Huszagh 2019-12-06 13:24 ` Fraga, Eric @ 2019-12-14 14:57 ` Nicolas Goaziou 2019-12-15 3:48 ` Matt Huszagh 1 sibling, 1 reply; 7+ messages in thread From: Nicolas Goaziou @ 2019-12-14 14:57 UTC (permalink / raw) To: Matt Huszagh; +Cc: emacs-orgmode@gnu.org, Fraga, Eric Hello, Matt Huszagh <huszaghmatt@gmail.com> writes: > Thanks for the reply Eric. The thing I like about the newlines is that the > generated tex files are slightly easier to read. However, this is really > minor. I've created 2 separate patches: one keeping the newlines and the > other without. I'm happy to defer to you or anyone else in regard to which > is preferable. So, has anyone settled on which one to apply? > + ;; remove tex \par at end of snippet to avoid trailing > + ;; whitespace Remove TeX \par at end of... trailing space. > + (if (string= (substring string -1 nil) "\n") Minor nitpick: (if (string-suffix-p string "\n") ...) is slightly less low-level. Thank you. Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Removing horizontal space in latex fragments 2019-12-14 14:57 ` Nicolas Goaziou @ 2019-12-15 3:48 ` Matt Huszagh 2019-12-15 9:04 ` Nicolas Goaziou 0 siblings, 1 reply; 7+ messages in thread From: Matt Huszagh @ 2019-12-15 3:48 UTC (permalink / raw) To: Nicolas Goaziou; +Cc: emacs-orgmode@gnu.org, Fraga, Eric [-- Attachment #1: Type: text/plain, Size: 425 bytes --] Nicolas Goaziou <mail@nicolasgoaziou.fr> writes: > So, has anyone settled on which one to apply? My vote goes for keeping the newlines to improve readability in the generated tex file. But, again, I'm more than happy to be overuled. > Minor nitpick: > > (if (string-suffix-p string "\n") ...) > > is slightly less low-level. Appreciate the nitpick; your version is better! I've attached an updated patch. Best, Matt [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: keep-newlines.patch --] [-- Type: text/x-patch, Size: 1386 bytes --] From bdb93a13a43d90ad6e66449797111e836a67a219 Mon Sep 17 00:00:00 2001 From: Matt Huszagh <huszaghmatt@gmail.com> Date: Thu, 5 Dec 2019 23:25:32 -0800 Subject: [PATCH] org.el: Remove leading/trailing whitespace from latex fragment * lisp/org.el (org-create-formula-image): Ensure user input ends with a % character to remove trailing whitespace. Also, add % characters between macros and newlines purely visual. --- lisp/org.el | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 9b84592ba..ae686e330 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -16554,12 +16554,17 @@ a HTML file." (setq bg (org-latex-color :background)) (setq bg (org-latex-color-format (if (string= bg "Transparent") "white" bg)))) + ;; remove tex \par at end of snippet to avoid trailing + ;; whitespace + (if (string-suffix-p string "\n") + (aset string (- (length string) 1) ?%) + (setq string (concat string "%"))) (with-temp-file texfile (insert latex-header) (insert "\n\\begin{document}\n" - "\\definecolor{fg}{rgb}{" fg "}\n" - "\\definecolor{bg}{rgb}{" bg "}\n" - "\n\\pagecolor{bg}\n" + "\\definecolor{fg}{rgb}{" fg "}%\n" + "\\definecolor{bg}{rgb}{" bg "}%\n" + "\n\\pagecolor{bg}%\n" "\n{\\color{fg}\n" string "\n}\n" -- 2.24.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: Removing horizontal space in latex fragments 2019-12-15 3:48 ` Matt Huszagh @ 2019-12-15 9:04 ` Nicolas Goaziou 0 siblings, 0 replies; 7+ messages in thread From: Nicolas Goaziou @ 2019-12-15 9:04 UTC (permalink / raw) To: Matt Huszagh; +Cc: emacs-orgmode@gnu.org, Fraga, Eric Hello, Matt Huszagh <huszaghmatt@gmail.com> writes: > My vote goes for keeping the newlines to improve readability in the > generated tex file. But, again, I'm more than happy to be overuled. [...] > I've attached an updated patch. Applied. Thank you. I added TINYCHANGE at the end of the commit message since I don't know if you have signed the FSF papers. If you did, please let me know. Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-12-15 9:04 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2019-12-05 19:03 Removing horizontal space in latex fragments Matt Huszagh 2019-12-05 22:24 ` Fraga, Eric 2019-12-06 7:42 ` Matt Huszagh 2019-12-06 13:24 ` Fraga, Eric 2019-12-14 14:57 ` Nicolas Goaziou 2019-12-15 3:48 ` Matt Huszagh 2019-12-15 9:04 ` Nicolas Goaziou
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).