emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rodrigo Morales <moralesrodrigo1100@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [bug] :prologue and :epilogue header arguments don't work in latex code blocks
Date: Sat, 13 Mar 2021 06:30:30 -0500	[thread overview]
Message-ID: <87ft0zl295.fsf@gmail.com> (raw)


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.


             reply	other threads:[~2021-03-13 11:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-13 11:30 Rodrigo Morales [this message]
2021-03-14 14:56 ` [bug] :prologue and :epilogue header arguments don't work in latex code blocks Eric S Fraga

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=87ft0zl295.fsf@gmail.com \
    --to=moralesrodrigo1100@gmail.com \
    --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).