emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [bug] :prologue and :epilogue header arguments don't work in latex code blocks
@ 2021-03-13 11:30 Rodrigo Morales
  2021-03-14 14:56 ` Eric S Fraga
  0 siblings, 1 reply; 2+ messages in thread
From: Rodrigo Morales @ 2021-03-13 11:30 UTC (permalink / raw)
  To: emacs-orgmode


This message can be read easier with Org Mode.

* TL; DR: The issue

I've noticed that the =:prologue= and =:epilogue= header arguments
don't work in code blocks whose language is =latex=.

I usually take notes on the =latex= programming language (this is
different than taking notes using LaTeX) and having those header
arguments would be really helpful for me and, I suppose, other
LaTeX programmers.

The following lines of this message give more detail on the issue and
more information I gathered through experimentation so that Org Mode
developers that might be interested in fixing this issue have more
information.

* Terminology used in this message

The following two code blocks will be used to explain the issue.

#+begin_src elisp
(defun org-babel-tangle-previous-src-block-and-echo ()
  "Tangles the backward nearest source code block and print the
content of the tangled file."
  (save-excursion
    (goto-char
     (search-backward-regexp "^[[:space:]]*#\\+begin_src\\>"))
    (let ((current-prefix-arg '(4)))
	  (call-interactively 'org-babel-tangle))
    (let ((filename-tangled (shell-quote-argument (expand-file-name (cdr (assq :tangle (nth 2 (org-babel-get-src-block-info))))))))
      (shell-command-to-string (concat "cat " filename-tangled)))))
#+end_src

#+name: org-babel-tangle-previous-src-block-and-echo
#+begin_src elisp
(org-babel-tangle-previous-src-block-and-echo)
#+end_src

* Languages where these header argument work

The =:prologue= and =:epilogue= header argument work in =bash= code blocks.

#+begin_src bash :tangle ~/Downloads/main.txt :prologue "echo a" :epilogue "echo c"
echo This is a bash code block
#+end_src

#+RESULTS:
#+begin_example
a
This is a bash code block
c
#+end_example

#+call: org-babel-tangle-previous-src-block-and-echo()

#+RESULTS:
#+begin_example
#!/bin/bash
echo a
echo This is a bash code block
echo c
#+end_example

They also work in =python= code blocks.

#+begin_src python :tangle ~/Downloads/main.txt :prologue "print('a')" :epilogue "print('c')"
print('This is a python code block')
#+end_src

#+RESULTS:
#+begin_example
a
This is a python code block
c
#+end_example

#+call: org-babel-tangle-previous-src-block-and-echo()

#+RESULTS:
#+begin_example
print('a')
print('This is a python code block')
print('c')
#+end_example

They also work in =R= code blocks.

#+begin_src R :tangle ~/Downloads/main.txt :prologue "print('a')" :epilogue "print('b')"
print('This is a R code block')
#+end_src

#+RESULTS:
#+begin_example
[1] "a"
[1] "This is a R code block"
[1] "b"
#+end_example

#+call: org-babel-tangle-previous-src-block-and-echo()

#+RESULTS:
#+begin_example
print('a')
print('This is a R code block')
print('b')
#+end_example

They also work in =maxima= code blocks.

#+begin_src maxima :tangle ~/Downloads/main.txt :prologue "print(\"a\");" :epilogue "print(\"c\");"
print("This is a maxima code block");
#+end_src

#+RESULTS:
#+begin_example
a 
This is a maxima code block 
c 
#+end_example

#+call: org-babel-tangle-previous-src-block-and-echo()

#+RESULTS:
#+begin_example
print("a");
print("This is a maxima code block");
print("c");
#+end_example

* Languages where these header arguments don't work

However, these header argument don't work in =latex= code blocks.

#+begin_src latex :tangle ~/Downloads/main.txt :prologue "a" :epilogue "c"
This is a latex code block
#+end_src

#+RESULTS:
#+begin_example
This is a latex code block
#+end_example

#+call: org-babel-tangle-previous-src-block-and-echo()

#+RESULTS:
#+begin_example
This is a latex code block
#+end_example

They also don't work in =cpp= code blocks

#+begin_src cpp :tangle ~/Downloads/main.txt :prologue "a" :epilogue "b" :includes "<iostream>"
std::cout << "This is a C++ code block";
#+end_src

#+RESULTS:
#+begin_example
This is a C++ code block
#+end_example

#+call: org-babel-tangle-previous-src-block-and-echo()

#+RESULTS:
#+begin_example
#include <iostream>






int main() {
std::cout << "This is a C++ code block";
return 0;
}
#+end_example

* Additional information

In 2020, the user Tim Landscheidt created a [[https://orgmode.org/list/CA+G3_PNrdhx0Ejzw8UO7DgZ+ju1B7Ar_eTch5MMViEpKGwqq3w@mail.gmail.com/T/#t][thread]] in the Org Mode
mailing list asking why these header argument don't work in SQL code
blocks. In a response to this thread, the user Tom Gillespie mentioned
that he had been working in a potential solution. If anyone knows the
progress on this, I would also apppreciate some information.


-- 
Greetings,
Rodrigo Morales.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [bug] :prologue and :epilogue header arguments don't work in latex code blocks
  2021-03-13 11:30 [bug] :prologue and :epilogue header arguments don't work in latex code blocks Rodrigo Morales
@ 2021-03-14 14:56 ` Eric S Fraga
  0 siblings, 0 replies; 2+ messages in thread
From: Eric S Fraga @ 2021-03-14 14:56 UTC (permalink / raw)
  To: Rodrigo Morales; +Cc: emacs-orgmode

On Saturday, 13 Mar 2021 at 06:30, Rodrigo Morales wrote:
> I've noticed that the =:prologue= and =:epilogue= header arguments
> don't work in code blocks whose language is =latex=.

It's not that they don't work, it's that those features have not (yet)
been implemented for LaTeX src blocks.  I would guess that nobody has
found a need for them before now.

As an aside, I am not sure why there isn't a generic implementation of
prologue and epilogue.

In any case, maybe tells us a bit more about what you would like to do
with LaTeX src blocks as there may be another way (there usually is) of
achieving what you want.  I only use LaTeX src blocks to implement
specific aspects that org does not handle itself when exporting to
LaTeX, e.g. include tikz figures.

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.4.4-254-g37749c


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-14 15:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-13 11:30 [bug] :prologue and :epilogue header arguments don't work in latex code blocks Rodrigo Morales
2021-03-14 14:56 ` Eric S Fraga

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).