emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] English and Dutch version of a Graphviz picture


From: Robert Klein
Subject: Re: [O] English and Dutch version of a Graphviz picture
Date: Sat, 1 Sep 2018 17:04:06 +0200

Hi Cecil,

On Sat, 1 Sep 2018 12:38:54 +0200
Cecil Westerhof <address@hidden> wrote:

> I have the following:
> #+BEGIN_SRC dot :file Graphviz/habitLoop.png :cmdline -Kfdp -Tpng
> digraph habitLoop {
>     bgcolor = steelblue
>     edge [penwidth = 4.0 ]
>     node [fontcolor = white, fontsize = 60, style = filled]
> 
>     spur   [pos = "4,4!" color = red]
>     habit  [pos = "7,1!" color = darkgreen]
>     reward [pos = "1,1!" color = blue]
> 
>     spur:e   -> habit:n
>     habit:w  -> reward:e
>     reward:n -> spur:w
> 
>     copyright [
>                 pos       = "4,.75!"
>                 color     = steelblue,
>                 fontcolor = black,
>                 fontsize  = 14,
>                 label     = "© Cecil
> address@hidden", shape     = plaintext
>               ]
> 
>     spur   [label = "Spur"]
>     habit  [label = "Habit"]
>     reward [label = "Reward"]
> }
> #+END_SRC
> 
> But I also want to have a Dutch version. So I also have:
> #+BEGIN_SRC dot :file Graphviz/gewoonteLoop.png :cmdline -Kfdp -Tpng
> digraph habitLoop {
>     bgcolor = steelblue
>     edge [penwidth = 4.0 ]
>     node [fontcolor = white, fontsize = 60, style = filled]
> 
>     spur   [pos = "4,4!" color = red]
>     habit  [pos = "7,1!" color = darkgreen]
>     reward [pos = "1,1!" color = blue]
> 
>     spur:e   -> habit:n
>     habit:w  -> reward:e
>     reward:n -> spur:w
> 
>     copyright [
>                 pos       = "4,.75!"
>                 color     = steelblue,
>                 fontcolor = black,
>                 fontsize  = 14,
>                 label     = "© Cecil
> address@hidden", shape     = plaintext
>               ]
> 
>     spur   [label = "Prikkel"]
>     habit  [label = "Gewoonte"]
>     reward [label = "Beloning"]
> }
> #+END_SRC
> 
> The only difference are the three label statements. Can this be done
> more efficient? Because now I need to do updates at two places. That
> is an accident waiting to happen.
> 


There's a complicated solution (like, using variables from tables) at
https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-dot.html

In your case you might want to use noweb (see
https://orgmode.org/org.html#Noweb-reference-syntax).  Then your code
might look like this:

#+Name: habitloop-main
#+BEGIN_SRC dot
    bgcolor = steelblue
    edge [penwidth = 4.0 ]
    node [fontcolor = white, fontsize = 60, style = filled]

    spur   [pos = "4,4!" color = red]
    habit  [pos = "7,1!" color = darkgreen]
    reward [pos = "1,1!" color = blue]

    spur:e   -> habit:n
    habit:w  -> reward:e
    reward:n -> spur:w

    copyright [
                pos       = "4,.75!"
                color     = steelblue,
                fontcolor = black,
                fontsize  = 14,
                label     = "© Cecil
    address@hidden",
                shape     = plaintext
              ]
#+END_SRC


#+BEGIN_SRC dot :file gewoonteLoop.png :cmdline -Kfdp -Tpng :noweb yes
digraph habitLoop {
    <<main-loop>>
    spur   [label = "Prikkel"]
    habit  [label = "Gewoonte"]
    reward [label = "Beloning"]
}
#+END_SRC

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

#+BEGIN_SRC dot :file habitLoop.png :cmdline -Kfdp -Tpng :noweb yes
digraph habitLoop {
    <<main-loop>>
    spur   [label = "Spur"]
    habit  [label = "Habit"]
    reward [label = "Reward"]
}
#+END_SRC


Note, for better looks I put the whole surrounding block in the
language-specific parts (the “digraph”-line could be in the
“habitloop-main” block, too).


When your code gets more involved this can get ugly, fast.  Then you'll
probably have to go the elisp way.

Best regards
Robert








reply via email to

[Prev in Thread] Current Thread [Next in Thread]