emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: hugo@heagren.com
Cc: emacs-orgmode@gnu.org
Subject: Re: Can :packages and :headers arguments in latex SRC blocks be made affect EXPORT blocks of results?
Date: Wed, 09 Nov 2022 17:30:59 +0000	[thread overview]
Message-ID: <87sfisf31o.fsf@posteo.net> (raw)
In-Reply-To: <c975ac5b3923b0c25d5bb7c3cc330acd@heagren.com> (hugo@heagren.com's message of "Tue, 08 Nov 2022 23:04:22 +0000")

hugo@heagren.com writes:

> Is there a way around this? Either to export the src block another way,
> or to add metadata to the to the resulting EXPORT block (or just text,
> though I'm not sure how that would work for `:packages', since they
> require text to be added to the resulting exported LaTeX file in a
> different place from where the text of the block goes).

If I have understood correctly what you want to do, maybe a solution
would be this. You can starting from a single block that includes
the preamble for both preview and export:

#+NAME: preamble
#+begin_src latex :exports none
\usepackage{tikz}
\usetikzlibrary{calc,positioning,patterns}
#+end_src

This block returns the above as a simple string:

#+NAME: pre
#+begin_src emacs-lisp :exports none :results silent :var x = preamble
  (with-temp-buffer
    (insert x)
    (LaTeX-mode)
    (setq preamble-prev (buffer-string)))
#+end_src

And this one adds the necessary LaTeX headers when you export the
document, so LaTeX doesn't crash when compiling.

#+begin_src latex :noweb yes :results raw
,#+LaTeX_HEADER: <<preamble>>
#+end_src

And the final block:

#+header: :results (if (org-export-derived-backend-p  org-export-current-backend 'latex) "latex" "file raw")
#+header: :file (if (org-export-derived-backend-p  org-export-current-backend 'latex) nil "foo.png")
#+header: :imagemagick t :fit t
#+header: :headers `(,(progn (org-babel-ref-resolve "pre") preamble-prev))
#+begin_src latex
 \begin{tikzpicture}[on grid,
   font=\footnotesize,
   level distance=2.5cm,
   sibling distance=2.5cm,
   every node/.style={circle,draw,fill=white},
   touch/.style={circle,draw=red!100,fill=red!40,thick},
   invirtueof/.style={circle,draw=red!50,fill=red!20,very thick}]

   \node [invirtueof] {Car}
   child {node {wheel}}
   child {node [invirtueof] {body}
     child {node {driver door}}
     child {node [invirtueof] {passenger door}
       child {node [touch] {region of door}}}};
 \end{tikzpicture}
#+end_src

#+RESULTS:
[[file:foo.png]]

Best regards,

Juan Manuel 


      parent reply	other threads:[~2022-11-09 17:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-08 23:04 Can :packages and :headers arguments in latex SRC blocks be made affect EXPORT blocks of results? hugo
2022-11-09  4:53 ` Ihor Radchenko
2022-11-09 17:30 ` Juan Manuel Macías [this message]

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=87sfisf31o.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=hugo@heagren.com \
    /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).