4

The following code works fine.

\documentclass{article}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
  input graph ;
  beginfig(0) ;
  draw begingraph(5cm,3cm)
    gdraw (0,0) for x = 1 upto 3: .. (x, x) endfor ;
  endgraph ;
  endfig ;
\end{mplibcode}
\end{document}

However the following doesn't work.

\documentclass{article}
\usepackage{luacode}
\usepackage{luamplib}
\begin{document}
\def\plot{
   \directlua{
      tex.print("\string\\begin{mplibcode}")
      tex.print("input graph ;")
      tex.print("beginfig(0)")
      tex.print("draw begingraph(5cm,3cm)")
      tex.print("   gdraw (0,0) for x = 1 upto 3: .. (x, x) endfor ;")
      tex.print("endgraph;")
      tex.sprint("endfig;")
      tex.print("\string\\end{mplibcode}")
}
}
\plot
\end{document}

There seems a problem with mplibdoreplacenewlinebr or catcode. How can this error be handled?

0

1 Answer 1

5

Since you are using luamplib from Lua, you might as well just use the Lua interface and ditch the \being...\end{mplibcode}.

\documentclass{article}
\usepackage{luamplib}
\begin{document}
\def\plot{%
  \directlua{luamplib.process_mplibcode([[
    input graph ;
    beginfig(0)
    draw begingraph(5cm,3cm)
       gdraw (0,0) for x = 1 upto 3: .. (x, x) endfor ;
    endgraph ;
    endfig ;
  ]])}%
}
\plot
\end{document}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .