would like to use a custom tikz library with org-mode. https://github.com/jluttine/tikz-bayesnet

The following example works fine. :)

#+begin_src latex :file fsa.pdf :packages '(("" "tikz")) :border 1em
  % Define block styles
  \tikzstyle{astate} = [circle, draw, text centered, font=\footnotesize, fill=blue!25]
  \tikzstyle{rstate} = [circle, draw, text centered, font=\footnotesize, fill=red!25]

  \begin{tikzpicture}[->,>=stealth', shorten >=1pt, auto, node distance=2.8cm, semithick]
    \node [astate] (1) at (0,0) {1};
    \node [astate] (2) at (1,0) {2};
    \node [rstate] (3) at (2,0) {3};
    \path (1) edge [bend left] node {b} (2)
          (2) edge node {b} (3)
          (2) edge [bend left] node {a} (1)
          (3) edge [loop above] node {(a, b)} (3);

but using the downloaded bayesnet library doesn't work.

#+begin_src latex :file figs/fmc_model.png :packages '(("" "tikz")) :border 1em
  % \usetikzlibrary{bayesnet}
  % \include{tikzlibrarybayesnet.code.tex}
    % Define nodes

    % Y
    \node[obs]          (y)   {$y$}; %
    \factor[above=of y] {y-f} {left:$\mathcal{N}$} {} {} ; %

    % W and X
    \node[det, above=of y]            (dot) {dot} ; % 
    \node[latent, above left=1.2 of dot]  (w)   {$\mathbf{w}$}; %
    \node[latent, above right=1.2 of dot] (x)   {$\mathbf{x}$}; %

    % W hyperparameters
    \node[const, above=1.2 of w, xshift=-0.5cm] (mw) {$\mu_w$} ; %
    \node[const, above=1.2 of w, xshift=0.5cm]  (aw) {$\alpha_w$} ; %

    % X hyperparameters
    \node[const, above=1.2 of x, xshift=-0.5cm] (mx) {$\mu_x$} ; %
    \node[const, above=1.2 of x, xshift=0.5cm]  (ax) {$\alpha_x$} ; %

    % noise
    \node[latent, right=2.5cm of y-f]         (t)   {$\tau$}; %
    \node[const, above=of t, xshift=-0.5cm] (at)  {$\alpha_\tau$} ; %
    \node[const, above=of t, xshift=0.5cm]  (bt)  {$\beta_\tau$} ; %

    % Factors
    \factor[above=of w] {w-f} {left:$\mathcal{N}$} {mw,aw} {w} ; %
    \factor[above=of x] {x-f} {left:$\mathcal{N}$} {mx,ax} {x} ; %
    \factor[above=of t] {t-f} {left:$\mathcal{G}$} {at,bt} {t} ; %
    \factoredge {dot,t} {y-f} {y} ; %

    % Connect w and x to the dot node
    \edge[-] {w,x} {dot} ;

    % Plates
    \plate {yx} { %
      (y)(y-f)(y-f-caption) %
      (x)(x-f)(x-f-caption) %
      (dot) %
    } {$N$} ;
    \plate {} {%
      (y)(y-f)(y-f-caption) %
      (w)(w-f)(w-f-caption) %
      (dot) %
      (yx.north west)(yx.south west) %
    } {$M$} ;


The result is the same as when I compile the figure in a standalone latex file without '\usetikzlibrary{bayesnet}'.

If I include the library in the org-mode fragement doesn't compile. In latex the '\usetikzlibrary{bayesnet}' command finds the library when it's located in the same folder (which it is) and produces the expected result.

So how can I make org-mode aware of the file tikzlibrarybayesnet.code.tex which is located in the project directory?

  • what command do you use to compile? – user2740 Feb 8 at 1:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.