emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Matt Huszagh <huszaghmatt@gmail.com>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>,
	"Fraga, Eric" <e.fraga@ucl.ac.uk>
Subject: Re: Removing horizontal space in latex fragments
Date: Sat, 14 Dec 2019 19:48:53 -0800	[thread overview]
Message-ID: <87v9qiw8nu.fsf@gmail.com> (raw)
In-Reply-To: <87tv63osz9.fsf@nicolasgoaziou.fr>

[-- 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

  reply	other threads:[~2019-12-15  3:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2019-12-15  9:04         ` Nicolas Goaziou

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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v9qiw8nu.fsf@gmail.com \
    --to=huszaghmatt@gmail.com \
    --cc=e.fraga@ucl.ac.uk \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@nicolasgoaziou.fr \
    /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 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).