emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Subject: [Patch] Pre-/postpend arbitrary LaTeX code to a section
Date: Sun, 18 Sep 2022 12:27:53 +0000	[thread overview]
Message-ID: <87o7vcsw8m.fsf@posteo.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 1168 bytes --]

Hi all,

I don't know if the following scenario usually appears in the workflow
of other Org users as well. Otherwise, I think this patch could be
ignored.

In my workflow I often need to pre- or postpend some LaTeX code
immediately before or after a section. Consider the following example:

------------------
* A section

Lorem ipsum

#+latex: \foo

* Another section

Lorem ipsum
-----------------

The \foo command affects the second section, but for Org it belongs to
the content of the first section. If I comment this section out or mark
it as non-exportable, then the LaTeX code has no effect. I think a
simple solution could be to have the PRESEC AND POSTSEC properties to
prepend or postpend arbitrary code to a section. These properties could be
extended with PRESEC+ and POSTSEC+. An example of use:

* Section
 :PROPERTIES:
 :presec:  \begingroup\foo
 :postsec: \endgroup
 :END:
...

Best regards,

Juan Manuel 

-- 
--
------------------------------------------------------
Juan Manuel Macías 

https://juanmanuelmacias.com

https://lunotipia.juanmanuelmacias.com

https://gnutas.juanmanuelmacias.com


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-ox-latex.el-Add-properties-for-arbitrary-LaTeX-.patch --]
[-- Type: text/x-patch, Size: 2844 bytes --]

From 56924d69a2090dfeedf4b35ca33e10a48cbc42b5 Mon Sep 17 00:00:00 2001
From: Juan Manuel Macias <maciaschain@posteo.net>
Date: Sun, 18 Sep 2022 13:56:05 +0200
Subject: [PATCH] lisp/ox-latex.el: Add properties for arbitrary LaTeX code.

* (org-latex-headline): The `PRESEC' and `POSTSEC' properties prepend
and postpend arbitrary LaTeX code to a section, respectively.
---
 lisp/ox-latex.el | 42 ++++++++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 16 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 1eb70ab20..a8c9aecd2 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2322,22 +2322,32 @@ holding contextual information."
 			     (and (string-match-p "\\<headlines\\>" v)
 				  (string-match-p "\\<local\\>" v)
 				  (format "\\stopcontents[level-%d]" level)))))
-		    info t)))))
-	  (if (and opt-title
-		   (not (equal opt-title full-text))
-		   (string-match "\\`\\\\\\(.+?\\){" section-fmt))
-	      (format (replace-match "\\1[%s]" nil nil section-fmt 1)
-		      ;; Replace square brackets with parenthesis
-		      ;; since square brackets are not supported in
-		      ;; optional arguments.
-		      (replace-regexp-in-string
-		       "\\[" "(" (replace-regexp-in-string "\\]" ")" opt-title))
-		      full-text
-		      (concat headline-label pre-blanks contents))
-	    ;; Impossible to add an alternative heading.  Fallback to
-	    ;; regular sectioning format string.
-	    (format section-fmt full-text
-		    (concat headline-label pre-blanks contents))))))))
+		    info t))))
+              ;; `PRESEC' and `POSTSEC' properties for arbitrary LaTeX code.
+              (pre-sec (let ((beg (org-element-property :begin headline)))
+			 (goto-char beg)
+			 (org-entry-get nil "PRESEC")))
+	      (post-sec (let ((beg (org-element-property :begin headline)))
+			  (goto-char beg)
+			  (org-entry-get nil "POSTSEC"))))
+          (concat
+	   (when pre-sec (format "%s\n\n" pre-sec))
+	   (if (and opt-title
+		    (not (equal opt-title full-text))
+		    (string-match "\\`\\\\\\(.+?\\){" section-fmt))
+	       (format (replace-match "\\1[%s]" nil nil section-fmt 1)
+		       ;; Replace square brackets with parenthesis
+		       ;; since square brackets are not supported in
+		       ;; optional arguments.
+		       (replace-regexp-in-string
+		        "\\[" "(" (replace-regexp-in-string "\\]" ")" opt-title))
+		       full-text
+		       (concat headline-label pre-blanks contents))
+	     ;; Impossible to add an alternative heading.  Fallback to
+	     ;; regular sectioning format string.
+	     (format section-fmt full-text
+		     (concat headline-label pre-blanks contents)))
+           (when post-sec (format "%s\n\n" post-sec))))))))
 
 (defun org-latex-format-headline-default-function
     (todo _todo-type priority text tags _info)
-- 
2.37.3


             reply	other threads:[~2022-09-18 12:29 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-18 12:27 Juan Manuel Macías [this message]
2022-09-18 16:14 ` [Patch] Pre-/postpend arbitrary LaTeX code to a section Max Nikulin
2022-09-19 10:04 ` Fraga, Eric
2022-09-20 13:26 ` Ihor Radchenko
2022-09-20 17:18   ` Juan Manuel Macías
2022-09-21  8:55     ` Ihor Radchenko
2022-09-21  9:32       ` Fraga, Eric
2022-09-21  9:49         ` Timothy
2022-09-22 13:50         ` Ihor Radchenko
2022-09-21 13:55       ` Daniel Fleischer
2022-09-21 14:51         ` Juan Manuel Macías
2022-09-21 15:21         ` Fraga, Eric
2022-09-22 13:51         ` Ihor Radchenko
2022-09-21 14:42       ` Max Nikulin
2022-09-21 14:43       ` Juan Manuel Macías
2022-09-22 14:08         ` Ihor Radchenko
2022-09-24 14:50           ` Juan Manuel Macías
2022-09-25  3:33             ` Ihor Radchenko
2022-09-25 12:06               ` Juan Manuel Macías
2022-09-26  3:56                 ` Ihor Radchenko
2022-09-26  7:47                   ` Juan Manuel Macías

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=87o7vcsw8m.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@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 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).