From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id kCShIiYPJ2MwmwAAbAwnHQ (envelope-from ) for ; Sun, 18 Sep 2022 14:29:26 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id oKSnIiYPJ2MeTgEA9RJhRA (envelope-from ) for ; Sun, 18 Sep 2022 14:29:26 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 2D6EA78C7 for ; Sun, 18 Sep 2022 14:29:26 +0200 (CEST) Received: from localhost ([::1]:38776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oZtQL-0005mH-2r for larch@yhetil.org; Sun, 18 Sep 2022 08:29:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39092) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oZtOz-0005j7-0d for emacs-orgmode@gnu.org; Sun, 18 Sep 2022 08:28:01 -0400 Received: from mout02.posteo.de ([185.67.36.66]:60801) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oZtOw-0007s4-SG for emacs-orgmode@gnu.org; Sun, 18 Sep 2022 08:28:00 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id C4B59240103 for ; Sun, 18 Sep 2022 14:27:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1663504075; bh=E+dYG49ESLwXAdSYOiAsNP/iFkVuKWmH0vno2rv3Yuw=; h=From:To:Subject:Date:From; b=Hs3vh8nVHOYI0sAscRiKqDAiVaOxp0wyih38WI9jvN7kmgxszVcpDa11xajCVqm8V y+WOmCS5ljxEegvVXs7pAdviDtIAm8s30YfLBcpHQhodBtOcXoKtlgodNy1KQgKNCM 0Sxyth1HRs53TSE5GzW504Px+VN/ThGc0cwWdfTLBON8TJzzTkefFWL00yRtTIdiHc wTWiU/RI9FBL0ty6N/5GB09zHL5vRR/rMAMz9RsEnKYjKbwPvdnv35hK7qCtB+Zriw E05pSgTF1M51fWHngMcqLxG+SlVnCVsgr7SUKyzj/1yb1v1V7rwqLwQmqP6nFA90R/ khpoXHWZP1lqA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4MVnBz1x0gz9rxM for ; Sun, 18 Sep 2022 14:27:55 +0200 (CEST) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: orgmode Subject: [Patch] Pre-/postpend arbitrary LaTeX code to a section Date: Sun, 18 Sep 2022 12:27:53 +0000 Message-ID: <87o7vcsw8m.fsf@posteo.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.66; envelope-from=maciaschain@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1663504166; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=d7dYsimYhrE54ociQ6r97AkHgjzr5gFrIYXpBb22tEQ=; b=PLVzZERunQ50PD1/ecpTZeVeHRLJ8pktSDb34b2uEDr5YzdOmOPyLDhR0KfLBdwAldnrVP CYP8OUpLK3rps1qe6PnrMHh+cWEg6afd9LhOqhe/qfFA93GXrYON3P/j3+OAYZKGTJx5+j 6xqbonV120+pJ9bLiWx6+sVfsGB33gWXntIE6hRjlZrGGk1LN9rO9kUn6XHFDOsu7JAsBy U725MkIQT7tvDNz2jhkTr8rEGWytWzxWlJxbwl0jqU6IwadsJiW6FNvsMMZwXZCoUq3/go stV9hR+he4u5Lnk0yT6cusG/97MFuZa1DCh57FnorG+iE0Pskwz7NfIxt+VcZg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1663504166; a=rsa-sha256; cv=none; b=JcHPhrLwXEgiyly9OH+A/vMLULogP/ItKiSUnDoz4Py5zDM0qOlueFuEj2PhOyeuPC50Bh /hQdxMdgoes7drucoT1b4VpwZraxXcpADp/bPa0MO0hxXccDqssldJtRCii/ri/cDjBaz0 K4373XuCtL3YpSC94TYrrqoc8bWzO4NZ3s0s2N0+jkth0Gdz/YjZ5MidVYwIDvSOt+FTD7 fYAQoS3IxBPou/Z5TF3kvhqpsCkFjvHsN8tvg7swIZ5bxYnUfUWJlWwy9g8wf/U3xOfO49 hf5+zxdxcMXeisehTkrxJQd7gsJJm3yfeOVrnvGSYM3q4waHecb5PeWLcmxehg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=Hs3vh8nV; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -7.54 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=Hs3vh8nV; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 2D6EA78C7 X-Spam-Score: -7.54 X-Migadu-Scanner: scn0.migadu.com X-TUID: O7ftNYlas6I7 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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=20 --=20 -- ------------------------------------------------------ Juan Manuel Mac=C3=ADas=20 https://juanmanuelmacias.com https://lunotipia.juanmanuelmacias.com https://gnutas.juanmanuelmacias.com --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-ox-latex.el-Add-properties-for-arbitrary-LaTeX-.patch >From 56924d69a2090dfeedf4b35ca33e10a48cbc42b5 Mon Sep 17 00:00:00 2001 From: Juan Manuel Macias 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 "\\" v) (string-match-p "\\" 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 --=-=-=--