Ihor Radchenko writes:

>>> #+ATTR_BACKEND: :export_template "can also work on non-headings"
>>> Paragraph.
>>
>> In this case I would not see it necessary, IMHO. For simple things (of
>> the begin/end style) there are the special blocks. And for more complex
>> pre- and/or post- code we have export blocks and export snippets. Since
>> there is no heading involved here, there would be no danger of the
>> pre-code leaving with the content of the previous header.
>
> I do not insist on this. I just see supporting this easier (it will work
> automatically) compared to explicitly limiting :export_template to
> headings/inlinetasks.
>
> Also, some people prefer to have such option (Pedro Andres Aranda
> Gutierrez in off-list reply to
> https://orgmode.org/list/87fsgmyyhw.fsf@localhost)

Well, it's evident that your idea of the export_template attribute is
very productive and can be consistently extended to more situations. One
scenario where I think it would be very useful is also in tables and
figures, but in this case to insert arbitrary code *inside* the table,
figure, etc. environments. This is something that gets asked on the list
from time to time and the solutions provided are usually a bit tricky.

Going back to the earlier :ATTR_BACKEND: issue as a property for
headings, I've been doing some testing and scribbled down a possible
function[1] whose code is almost entirely stolen from
org-export-read-attribute, with some modifications. Evaluated at the
headline, it returns the value of the ATTR_BACKEND property as a plist.
And then that plist could be easily manipulated on each backend to
format export_template conveniently. For example:

* headline
:PROPERTIES:
:ATTR_LaTeX: :export_template \begin{myenv}\n%s\n\end{myenv}
:ATTR_LaTeX+: blah blah blah
:END:

==> (:export_template "\\begin{myenv}\\n%s\\n\\end{myenv} blah blah blah")

I don't know if that would be the way to go...

Best regards,

Juan Manuel

[1]
(defun possible-function (attribute)
  "TODO"
  (let* ((prepare-value
          (lambda (str)
            (save-match-data
              (cond ((member str '(nil "" "nil")) nil)
                    ((string-match "^\"\\(\"+\\)?\"$" str)
                     (or (match-string 1 str) ""))
                    (t str)))))
         (attributes
          (let ((value (org-entry-get nil attribute)))
            (when value
              (let ((s value) result)
                (while (string-match
                        "\\(?:^\\|[ \t]+\\)\\(:[-a-zA-Z0-9_]+\\)\\([ 
\t]+\\|$\\)"
                        s)
                  (let ((value (substring s 0 (match-beginning 0))))
                    (push (funcall prepare-value value) result))
                  (push (intern (match-string 1 s)) result)
                  (setq s (substring s (match-end 0))))
                ;; Ignore any string before first property with `cdr'.
                (cdr (nreverse (cons (funcall prepare-value s) result))))))))
    attributes))


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

https://juanmanuelmacias.com

https://lunotipia.juanmanuelmacias.com

https://gnutas.juanmanuelmacias.com


Reply via email to