2

I am trying to compile tree diagrams using the mptrees package (I like this) with LuaLaTeX and luamplib. On TeX Stack Exchange, I found only one question on this topic,

background color with \mpcolor

but it does not clarify what minimal code is required to compile the drawings of mptrees package to compile correctly.

I have downloaded the mptrees package's ZIP file and I am trying to understand what to add or remove to the following code to get the tree diagrams to compile successfully, starting from:

\documentclass[10pt]{article}
\begin{document}
\mplibforcehmode
\begin{exampleblock}{}\centering
    \extractcolorspecs{block body example.bg}\modelcmd\colorcmd
    \begin{mplibcode}
      input mptrees;
      beginfig(1)
      dirtree:=-90;
      typeprob:=2;
      background:=(\colorcmd);
      draw tree[1][1](1.25cm,5cm)("P","$\frac{1}{2}$","F","$\frac{1}{2}$");
      draw tree[2][1](1.25cm,1.5cm)("R","$\frac{1}{5}$","B","$\frac{1}{5}$","N","$\frac{3}{5}$");
      draw tree[2][2](1.25cm,1.5cm)("R","$\frac{1}{5}$","B","$\frac{1}{5}$","N","$\frac{3}{5}$");
      endfig;
    \end{mplibcode}
  \end{exampleblock}
\end{document}

Hence:

What is the minimal working example (MWE) to get the mptrees drawings to compile?

Any guidance or example codes would be greatly appreciated.

4
  • 1
    "I have downloaded the mptrees package's ZIP file " mptrees is in texlive and miktex, you shouldn't need anything from ctan Commented 23 hours ago
  • where have you got that code from? neither \mplibforcehmode nor exampleblock are mentioned in the mptrees manual. Commented 23 hours ago
  • @DavidCarlisle Yes, but I have seen the .tex of the mptrees's documentation to understand if there was a MWE.
    – Sebastiano
    Commented 22 hours ago
  • 1
    everything that you could get from ctan is already in the tex distributions eg the tex doc is /usr/local/texlive/2025/texmf-dist/doc/metapost/mptrees/mptrees-doc.tex in texlive and will be somewhere similar in miktex Commented 22 hours ago

2 Answers 2

3

You have not loaded luamplib to use mplib commands, and the example block is a beamer command you haven't defined. here I just set the color using three rgb values

enter image description here

\documentclass[10pt]{article}
\usepackage{luamplib}
\begin{document}
\mplibforcehmode
%\begin{exampleblock}{}\centering
%    \extractcolorspecs{block body example.bg}\modelcmd\colorcmd
    \begin{mplibcode}
      input mptrees;
      beginfig(1)
      dirtree:=-90;
      typeprob:=2;
      background:=(.7,.5,0);
      draw tree[1][1](1.25cm,5cm)("P","$\frac{1}{2}$","F","$\frac{1}{2}$");
      draw tree[2][1](1.25cm,1.5cm)("R","$\frac{1}{5}$","B","$\frac{1}{5}$","N","$\frac{3}{5}$");
      draw tree[2][2](1.25cm,1.5cm)("R","$\frac{1}{5}$","B","$\frac{1}{5}$","N","$\frac{3}{5}$");
      endfig;
    \end{mplibcode}
%  \end{exampleblock}
\end{document}
3
  • Excuse me. I have deleted it unknowingly. Infact in the link tex.stackexchange.com/questions/511346/… into my question there is luamplib package. If I want to use beginfig(1); draw tree[1][1](4cm,2.5cm)("$A_1$","$\nicefrac{1}{3}$","$A_2$","$\nicefrac{2}{3}$"); draw tree[2][1](3cm,1.5cm)("$B$","$\nicefrac{1}{4}$","$C$","$\nicefrac{3}{4}$"); draw tree[2][2](3cm,1cm)("$D$","$p$","$E$","$q$","$F$","$r$"); endfig; what I should do? Thank you.
    – Sebastiano
    Commented 22 hours ago
  • 1
    well at least you'll need the nicefrac package to define \nicefrac @Sebastiano Commented 22 hours ago
  • Yes, of course. I was interesting only to understand the stuff starting begin ..> endfig;
    – Sebastiano
    Commented 22 hours ago
3

The exampleblock environment and the block body example.bg colour are beamer specific things. They will work if you use the beamer class like in the linked answer:

% !TeX TS-program = lualatex -interaction=nonstopmode % | txs:///view-pdf | txs:///view-log
\documentclass[10pt]{beamer}
\usepackage{luamplib}
\usecolortheme{orchid}
\begin{document}
\mplibforcehmode
\begin{frame}
  \begin{exampleblock}{}\centering
    \extractcolorspecs{block body example.bg}\modelcmd\colorcmd
    \begin{mplibcode}
      input mptrees;
      beginfig(1)
      dirtree:=-90;
      typeprob:=2;
      background:=(\colorcmd);
      draw tree[1][1](1.25cm,5cm)("P","$\frac{1}{2}$","F","$\frac{1}{2}$");
      draw tree[2][1](1.25cm,1.5cm)("R","$\frac{1}{5}$","B","$\frac{1}{5}$","N","$\frac{3}{5}$");
      draw tree[2][2](1.25cm,1.5cm)("R","$\frac{1}{5}$","B","$\frac{1}{5}$","N","$\frac{3}{5}$");
      endfig;
    \end{mplibcode}
  \end{exampleblock}
\end{frame}
\end{document}

enter image description here

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.