From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id mBvLIXBf1mUoSAEAqHPOHw:P1 (envelope-from ) for ; Wed, 21 Feb 2024 21:39:12 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id mBvLIXBf1mUoSAEAqHPOHw (envelope-from ) for ; Wed, 21 Feb 2024 21:39:12 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=E7nphRAL; 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"; dmarc=pass (policy=none) header.from=posteo.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1708547599; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=He9nVqvzokyvxDB+bXVXQ83GD0Fr3p30hB5OnaFMkgA=; b=ELMmcsARBv1MZLzOq7ZpqoAzXJVZ/Jys5Ilwv5Gp6exqP+5dLefoIuxg9EEaDT936mjZ3H iYPOvWbd/8XDH/HU1ephbLCUIEndNua6ZJXgOQyvZ5CI8dgrHq/tK3r8kVk+bHbWYoLFrA zsZfrMNog2nAWvFHwx9Fizkv4mEvScd/gMEFZ+1mEX+3dz1f/T9yO7diiCKGg/Aj043C2U UDT0BEjSyizEuBcqHisKZjTNBH6tmHT1oJ+ybes8gk8bOVrUPD7btzeY8vopX7exEy3oGw L5Dvxu1zgGID1a4qn8l1YuTC9mQSTZWpql0n5Bq5gzto5TRkeZTYC0AzAEPbXg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=E7nphRAL; 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"; dmarc=pass (policy=none) header.from=posteo.net ARC-Seal: i=1; s=key1; d=yhetil.org; t=1708547599; a=rsa-sha256; cv=none; b=eLnUxDZ4s5Ts0F3x/x7g1sER3yIrvOCAsI8QEHC6E/qFiexXSefrymv+ohEvxbX+6m0ray neA9NUdyzyeXpKz/Pn9nJs93NEGoxyMq/HKD/JBPAYFEXzCGrSbXf2UxRxSX6KGyBEoO9x Jbb3FgKwqeDCaLFM9pOnHYhwpaQUxQkGLv2+xK2NuH9yc9/Xnbc0DjAhoVVJT6Bww3PSQu i7brBPg09xfFUjQGI7gN7hs/uFoFYUcBxVM0Fydttu0N4MqGVfvlMmsbJY/kxVYFyuTy1q 0X9tzhkPzrwoSHspUmHv05L4MD2tba0F+onG/Cj/GpUqQ5rL1epDicudEmxN1g== 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 6B7F7689B7 for ; Wed, 21 Feb 2024 21:33:19 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctGP-0007Wb-6g; Wed, 21 Feb 2024 15:32:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctGL-0007WA-KQ for emacs-orgmode@gnu.org; Wed, 21 Feb 2024 15:32:18 -0500 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctGJ-0000ka-3L for emacs-orgmode@gnu.org; Wed, 21 Feb 2024 15:32:17 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id DC1CA240103 for ; Wed, 21 Feb 2024 21:32:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1708547531; bh=ckxvvbUooETeRzsbqC60cegdTGWWEe74CPvOp2VlDUQ=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=E7nphRALeO8BMCPK9/A15oUMwj6MSZHTL4lZpujEwrYBbJ5S7Mnsn5LJi53n81yd6 j2+DL0yLFKZ0Wk9+DtRBrjIEaItL8J0MKV+ETQR70MDcwN8VfVz77Z9H3s8EAT3I+f KHSnLqtYqLJzY0HNc+lxmjvdVd9jOHQ60JxnfBx1qvMPqO98N5o17ELog5dimAZoup yaGyl0JDR9YAAE23PIdtLm/Ie424m6HFel7O3zjTPyHbzS0Iy4avuQlCi/OgbctGjJ x6CUeVi5Rg1+wemhPxAD4zcUGvVKJ9eYZyiXxjHQs412pJXBFBIup61FTReHTQs+HG G6baA/f2gZvCA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Tg7HH3FXzz6trs for ; Wed, 21 Feb 2024 21:32:11 +0100 (CET) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: orgmode Subject: [proof of concept] inline-special-block (was: [proof of concept] inline language blocks) In-Reply-To: <875xyhzyzl.fsf@posteo.net> ("Juan Manuel =?utf-8?Q?Mac=C3=AD?= =?utf-8?Q?as=22's?= message of "Wed, 21 Feb 2024 14:13:50 +0000") References: <87msrudgcn.fsf@posteo.net> <8734tmmcnv.fsf@localhost> <87edd6ytiy.fsf@posteo.net> <87sf1mrpr6.fsf@localhost> <87a5nuyo4w.fsf@posteo.net> <87frxmrmjb.fsf@localhost> <875xyhzyzl.fsf@posteo.net> Date: Wed, 21 Feb 2024 20:32:09 +0000 Message-ID: <87v86h4kza.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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -9.98 X-Spam-Score: -9.98 X-Migadu-Queue-Id: 6B7F7689B7 X-Migadu-Scanner: mx11.migadu.com X-TUID: WB9rLt/gHckY --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable I am attaching a patch in case anyone wants to try this proposal. A function for ox-latex is included. Syntax: &[optional parameters]{contents} With this patch, something like &foo{lorem ipsum dolor} is exported to LaTeX as \foo{lorem ipsum dolor}. Blocks can be nested, e.g.: &foo{lorem ipsum &bar{dolor}}. Regarding the "optional parameters", there is nothing defined, although I think they should be adapted to each backend. A possible use that occurs to me: &foo[prelatex: [lorem] postlatex: {ipsum} html: style=3D"color:red;"]{blah = blah} This should produce in LaTeX: \foo[lorem]{blah blah}{ipsum} and in HTML: blah blah Best regards, Juan Manuel=20 --=20 Juan Manuel Mac=C3=ADas -- Composici=C3=B3n tipogr=C3=A1fica, tratamiento d= e datos, dise=C3=B1o editorial y ortotipograf=C3=ADa --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org-element.el-New-element-Inline-Special-Block-proo.patch >From 587e77feb1c4e6881d527d1fd3a6e541efb596d4 Mon Sep 17 00:00:00 2001 From: Juan Manuel Macias Date: Wed, 21 Feb 2024 20:44:58 +0100 Subject: [PATCH] org-element.el: New element: Inline Special Block (proof of concept). * lisp/ox-latex.el (org-latex-inline-special-block): A possible function for the LaTeX backend. --- lisp/org-element.el | 55 ++++++++++++++++++++++++++++++++++++++++++++- lisp/ox-latex.el | 10 +++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 6691ea44e..2f9436df2 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -272,6 +272,8 @@ specially in `org-element--object-lex'.") "\\|")) ;; Objects starting with "@": export snippets. "@@" + ;; Objects starting with "&": inline-special-blocks. + "&" ;; Objects starting with "{": macro. "{{{" ;; Objects starting with "<" : timestamp @@ -313,7 +315,7 @@ specially in `org-element--object-lex'.") "List of recursive element types aka Greater Elements.") (defconst org-element-all-objects - '(bold citation citation-reference code entity export-snippet + '(bold citation citation-reference code entity export-snippet inline-special-block footnote-reference inline-babel-call inline-src-block italic line-break latex-fragment link macro radio-target statistics-cookie strike-through subscript superscript table-cell target timestamp underline verbatim) @@ -440,6 +442,7 @@ Don't modify it, set `org-element-affiliated-keywords' instead.") ;; Ignore inline babel call and inline source block as formulas ;; are possible. Also ignore line breaks and statistics ;; cookies. + (inline-special-block ,@standard-set) (table-cell citation export-snippet footnote-reference link macro radio-target target timestamp ,@minimal-set) (table-row table-cell) @@ -3535,6 +3538,54 @@ Assume point is at the beginning of the entity." (org-element-property :name entity) (when (org-element-property :use-brackets-p entity) "{}"))) +;;;; inline special block + +(defun org-element-inline-special-block-parser () + "Parse inline special block at point. + +When at an inline special block, return a new syntax node of +`inline-special-block' type containing `:begin', `:end', `:type', +`:parameters', `:contents-begin', `:contents-end' and +`:post-blank' as properties. Otherwise, return nil. + +Assume point is at the beginning of the block." + (save-excursion + (when (looking-at "&\\([A-Za-z]+\\)[{[]") + (goto-char (- (match-end 0) 1)) + (let* ((begin (match-beginning 0)) + (parameters + (let ((p (org-element--parse-paired-brackets ?\[))) + (and (org-string-nw-p p) + (replace-regexp-in-string "\n[ \t]*" " " (org-trim p))))) + (contents-begin (when (looking-at-p "{") (+ (point) 1))) + (type (org-element--get-cached-string + (match-string-no-properties 1))) + (contents-end + (progn + (goto-char (- contents-begin 1)) + (org-element--parse-paired-brackets ?\{) + (- (point) 1))) + (post-blank (skip-chars-forward " \t")) + (end (point))) + (when contents-end + (org-element-create + 'inline-special-block + (list :type type + :parameters parameters + :contents-begin contents-begin + :contents-end contents-end + :begin begin + :end end + :post-blank post-blank))))))) + +(defun org-element-inline-special-block-interpreter (inline-special-block contents) + "Interpret INLINE SPECIAL BLOCK object as Org syntax." + (let ((type (org-element-property :type inline-special-block)) + (opts (org-element-property :parameters inline-special-block))) + (format "&%s%s{%s}" + type + (if opts (format "[%s]" opts) "") + contents))) ;;;; Export Snippet @@ -5260,6 +5311,8 @@ to an appropriate container (e.g., a paragraph)." (org-element-strike-through-parser))) (?@ (and (memq 'export-snippet restriction) (org-element-export-snippet-parser))) + (?& (and (memq 'inline-special-block restriction) + (org-element-inline-special-block-parser))) (?{ (and (memq 'macro restriction) (org-element-macro-parser))) (?$ (and (memq 'latex-fragment restriction) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index cfa2b8178..a303d54a6 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -101,6 +101,7 @@ (underline . org-latex-underline) (verbatim . org-latex-verbatim) (verse-block . org-latex-verse-block) + (inline-special-block . org-latex-inline-special-block) ;; Pseudo objects and elements. (latex-math-block . org-latex-math-block) (latex-matrices . org-latex-matrices)) @@ -2095,6 +2096,15 @@ holding contextual information." center-block (format "\\begin{center}\n%s\\end{center}" contents) info)) +;;;; Inline Special Block + +(defun org-latex-inline-special-block (inline-special-block contents info) + "Transcode an INLINE SPECIAL BLOCK element from Org to LaTeX. +CONTENTS holds the contents of the block. INFO is a plist +holding contextual information." + (let ((type (org-element-property :type inline-special-block))) + (format "\\%s{%s}" type contents))) + ;;;; Clock (defun org-latex-clock (clock _contents info) -- 2.43.1 --=-=-=--