unofficial mirror of emacs-orgmode@gnu.org
 help / color / mirror / Atom feed
* [question] lisp code in :results header arg.?
@ 2021-02-16 16:30 Juan Manuel Macías
  2021-02-16 17:58 ` Berry, Charles via General discussions about Org-mode.
  0 siblings, 1 reply; 3+ messages in thread
From: Juan Manuel Macías @ 2021-02-16 16:30 UTC (permalink / raw)
  To: orgmode

Hi,

I'm exploring some ways to include a complex LaTeX preamble using source
blocks. Consider this (code at the end of this message), that works fine.

My question is: In order to do it all in a single block, would there be
any way to pass the output of the first block as an argument to a
function, and put that function as a header arg (results)...?

Best Regards,

Juan Manuel 

#+NAME:preamble
#+begin_src latex :results silent :exports results
  \usepackage{luacode}
  \usepackage{fontspec}
  \directlua
  {
  fonts.handlers.otf.addfeature 
  {
     name = "ktest",
     type = "kern",
     data = 
	{
	   ["A"] = { ["V"] = -45 },
	},
  }
  }
  \setmainfont{Linux Libertine O}
  [RawFeature={+ktest}]
#+end_src

#+begin_src emacs-lisp :var x=preamble :results raw :exports results
  (let* ((lines (split-string x "\n" nil))
	 (headers (mapconcat (lambda
			   (line)
			   (unless (equal line "")
			     (format "#+LaTeX_Header: %s" line)))
			 lines "\n")))
    headers)
#+end_src

#+RESULTS:
#+LaTeX_Header: \usepackage{luacode}
#+LaTeX_Header: \usepackage{fontspec}
#+LaTeX_Header: \directlua
#+LaTeX_Header: {
#+LaTeX_Header: fonts.handlers.otf.addfeature 
#+LaTeX_Header: {
#+LaTeX_Header:    name = "ktest",
#+LaTeX_Header:    type = "kern",
#+LaTeX_Header:    data = 
#+LaTeX_Header:       {
#+LaTeX_Header: 	 ["A"] = { ["V"] = -45 },
#+LaTeX_Header:       },
#+LaTeX_Header: }
#+LaTeX_Header: }
#+LaTeX_Header: \setmainfont{Linux Libertine O}
#+LaTeX_Header: [RawFeature={+ktest}]



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

* Re: [question] lisp code in :results header arg.?
  2021-02-16 16:30 [question] lisp code in :results header arg.? Juan Manuel Macías
@ 2021-02-16 17:58 ` Berry, Charles via General discussions about Org-mode.
  2021-02-16 18:25   ` Juan Manuel Macías
  0 siblings, 1 reply; 3+ messages in thread
From: Berry, Charles via General discussions about Org-mode. @ 2021-02-16 17:58 UTC (permalink / raw)
  To: Juan Manuel Macías; +Cc: orgmode



> On Feb 16, 2021, at 8:30 AM, Juan Manuel Macías <maciaschain@posteo.net> wrote:
> 
> Hi,
> 
> I'm exploring some ways to include a complex LaTeX preamble using source
> blocks. Consider this (code at the end of this message), that works fine.
> 
> My question is: In order to do it all in a single block, would there be
> any way to pass the output of the first block as an argument to a
> function, and put that function as a header arg (results)...?


[rest deleted]

I think you might do better to use noweb chunks, viz.

#+name: pre-amble
#+begin_src latex :exports none
  \usepackage{luacode}
  \usepackage{fontspec}
  \directlua
  {
  [...]
  }
  }
  \setmainfont{Linux Libertine O}
  [RawFeature={+ktest}]
#+end_src


#+begin_src latex :noweb yes :results drawer
,#+LaTeX_HEADER: <<pre-amble>>
#+end_src


Evaluating the latter chunk (assuming `org-babel-load-languages' has (latex . t)) gives what I suspect you want.

Note that using a drawer allows replacement of the result.

HTH,
Chuck



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

* Re: [question] lisp code in :results header arg.?
  2021-02-16 17:58 ` Berry, Charles via General discussions about Org-mode.
@ 2021-02-16 18:25   ` Juan Manuel Macías
  0 siblings, 0 replies; 3+ messages in thread
From: Juan Manuel Macías @ 2021-02-16 18:25 UTC (permalink / raw)
  To: Berry, Charles; +Cc: orgmode

"Berry, Charles" <ccberry@health.ucsd.edu> writes:

> I think you might do better to use noweb chunks, viz.
>
> #+name: pre-amble
> #+begin_src latex :exports none
>
>   \usepackage{luacode}
>   \usepackage{fontspec}
>   \directlua
>   {
>   [...]
>   }
>   }
>   \setmainfont{Linux Libertine O}
>   [RawFeature={+ktest}]
> #+end_src
>
> #+begin_src latex :noweb yes :results drawer
> ,#+LaTeX_HEADER: <<pre-amble>>
> #+end_src
>
>
> Evaluating the latter chunk (assuming `org-babel-load-languages' has (latex . t)) gives what I suspect you want.

wow, it works great! Many thanks. I did not know this use of noweb ...

Best regards,

Juan Manuel 


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

end of thread, other threads:[~2021-02-16 18:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-16 16:30 [question] lisp code in :results header arg.? Juan Manuel Macías
2021-02-16 17:58 ` Berry, Charles via General discussions about Org-mode.
2021-02-16 18:25   ` Juan Manuel Macías

unofficial mirror of emacs-orgmode@gnu.org

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/orgmode/0 orgmode/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 orgmode orgmode/ https://yhetil.org/orgmode \
		emacs-orgmode@gnu.org
	public-inbox-index orgmode

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git