all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* change font-size in python plots depending on context
@ 2019-08-19  8:50 johanna.may
  2019-08-19 11:10 ` Fraga, Eric
  0 siblings, 1 reply; 4+ messages in thread
From: johanna.may @ 2019-08-19  8:50 UTC (permalink / raw)
  To: emacs-orgmode

Dear org-mode fans,

I have various files that go together in one document, either
chapterwise or the whole book. And just as with tikz (latex) I want the font
size of python plots to change automatically when the context changes.

So I tried to define a variable in one of the header files like this:

#+name: fs
#+BEGIN_SRC emacs-lisp
10
#+END_SRC

I also tried to define it like this

#+name: fs
#+begin_src python :results output :session :exports none
fontsize=10
return fontsize
#+end_src

And then, in another file (that is being included by the header file) I
added :var fontsize=fs to the header and replaced the number by this
variable. I understand it complained that fs could not be found if I
used C-c C-c directly to test, since apparently the variable fs only
belongs to the other buffer (This is the first problem).

However, it doesn't work either when I compile everything (the second problem). Probably it
is also possible to solve this with some function in elisp. But, I have
to admit, that I haven't started learning elisp yet.

Does anyone have a solution to this problem? Any hints to helpful blogs
or stackexchange pages would be appreciated. I did a search but probably
not using the right keywords.

Thanks!

J

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

* Re: change font-size in python plots depending on context
  2019-08-19  8:50 change font-size in python plots depending on context johanna.may
@ 2019-08-19 11:10 ` Fraga, Eric
  0 siblings, 0 replies; 4+ messages in thread
From: Fraga, Eric @ 2019-08-19 11:10 UTC (permalink / raw)
  To: johanna.may@th-koeln.de; +Cc: emacs-orgmode@gnu.org

Hi Johanna,

> I have various files that go together in one document, either
> chapterwise or the whole book. And just as with tikz (latex) I want the font
> size of python plots to change automatically when the context changes.

What I do, for a similar use case, is to define values using properties
and then extract these values with a little function I wrote (see
below).  For example,

#+begin_src org
,#+property: myvariable 10
...
,#+begin_src ... :var v=(esf/get-parameter "myvariable")
... (use v in here)
,#+end_src
#+end_src

The esf/get-parameter function is:

#+begin_src emacs-lisp
  (defun esf/get-parameter (p)
    (let ((value (org-entry-get (point) p 'inherit)))
      (message "parameter %s value obtained %s" p value)
      (if value
          (if (string-match-p "^[-+ ]*[[:digit:].]+$" value)
              (string-to-number value)
            value)
        (error "Property parameter \"%s\" not known." p))))
#+end_src

I'm sure there are better ways but this is what I have developed
organically over the years...

HTH,
eric

-- 
Eric S Fraga via Emacs 27.0.50, Org release_9.2.4-401-gfabd6d

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

* Re: change font-size in python plots depending on context
@ 2019-08-19 16:50 Thomas S. Dye
  2019-08-20  9:25 ` johanna.may
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas S. Dye @ 2019-08-19 16:50 UTC (permalink / raw)
  To: johanna.may; +Cc: emacs-org list

Aloha Johanna May,

This works:

#+name: fs
#+BEGIN_SRC emacs-lisp
10
#+END_SRC

#+RESULTS: fs
: 10

#+header: :var fontsize=fs() :results output
#+begin_src python
print(fontsize)
#+end_src

#+RESULTS:
: 10

Note "fs()" instead of "fs".

All the best,
Tom

--
Thomas S. Dye
http://tsdye.online/tsdye

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

* Re: change font-size in python plots depending on context
  2019-08-19 16:50 Thomas S. Dye
@ 2019-08-20  9:25 ` johanna.may
  0 siblings, 0 replies; 4+ messages in thread
From: johanna.may @ 2019-08-20  9:25 UTC (permalink / raw)
  To: emacs-org list


Hi there,

thanks to Thomas and Eric.
I actually found a rather stupid mistake: I was already using a var (for
the png filename generation) and the header did not read the next
:var. So I added ,fs=fontsize to the first :var and now it works.

I will have a look Eric's function of how to get the value of
e.g. fontsize and so on (btw, I also need textwidth and textheight from
somewhere). I also found a python pgf package but I couldn't figure out
fast how to implement that (it sounds as if instead of png a pgf is
generated and then everything has the right latex layout, so pretty
cool, but it seemed not so easy to implement).

So long, cheers!

J

Thomas S. Dye writes:

> Aloha Johanna May,
>
> This works:
>
> #+name: fs
> #+BEGIN_SRC emacs-lisp
> 10
> #+END_SRC
>
> #+RESULTS: fs
> : 10
>
> #+header: :var fontsize=fs() :results output
> #+begin_src python
> print(fontsize)
> #+end_src
>
> #+RESULTS:
> : 10
>
> Note "fs()" instead of "fs".
>
> All the best,
> Tom


-- 
Prof. Dr. Johanna May
Stellvertretende Institutsleiterin CIRE
Fakultät für Informations-, Medien- und Elektrotechnik (F07)
Institut für Elektrische Energietechnik (IET)
Cologne Institute for Renewable Energy (CIRE)
Lehrgebiete: Energieeffizienz und Grundlagen Elektrotechnik

T: +49 221-8275-2697
M: +49 174 891 9002
E: johanna.may@th-koeln.de

Technische Hochschule Köln
Campus Deutz
Betzdorfer Str. 2
50679 Köln
Raum: HW2-40

www.th-koeln.de

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

end of thread, other threads:[~2019-08-20  9:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-19  8:50 change font-size in python plots depending on context johanna.may
2019-08-19 11:10 ` Fraga, Eric
  -- strict thread matches above, loose matches on Subject: below --
2019-08-19 16:50 Thomas S. Dye
2019-08-20  9:25 ` johanna.may

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.