I wrote some luacode in my main.tex and I'm a adding several other files due to \input{code.tex}
I already asked this question here
and it works on a standalone environment but not in my case. I can't figure out why. There is no problem in plotting a function due to tikz with
declare function = {test(\x)=\x*\x;}
but it is neither drawing anything nor using the correct samples on the axis when I use
declare function = {nbin(\t) = \directlua{tex.sprint(nbin(\t))};}
Here are parts of the files:
main.tex:
\documentclass[14pt]{book}
\usepackage[german]{babel}
\usepackage{graphicx}
\usepackage{float}
\usepackage{hyperref}
\emergencystretch=0em
\usepackage{marginnote}
\usepackage{amsmath}
\usepackage{multicol}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{stmaryrd}
\usepackage{amstext}
\usepackage{siunitx}
\usepackage{tikz}
\usetikzlibrary{trees}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{enumerate}
\usepackage{dsfont}
\usepackage{calrsfs}
\usepackage{calligra}
\usepackage{verbatim}
\usepackage{mathpazo}
\usepackage{mathptmx}
\usepackage[autostyle=true]{csquotes}
\usepackage{currvita}
\usetikzlibrary{matrix}
\usetikzlibrary{calc}
\usetikzlibrary{positioning,shapes}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{delarray}
\usepackage{pifont}
\usepackage{polynom}
\usepackage{stmaryrd}
\usepackage{varwidth}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{pdfpages}
\usepackage{pgf}
\usetikzlibrary{tikzmark}
\usetikzlibrary{arrows}
\usetikzlibrary{intersections}
\usepackage{extarrows}
\usepackage{cancel}
\usepackage{calc}
\usepackage{caption}
\captionsetup{
font={ sc, bf, footnotesize},
skip=0pt,
justification=centering,
}
\usetikzlibrary{decorations.pathreplacing}
\tikzstyle{abstract}=[rectangle, draw=black, rounded corners,
text centered, anchor=north, text=black, text width=2.7 cm]
\tikzstyle{comment}=[rectangle, draw=black, rounded corners, fill=green,
text centered, anchor=north, text=white, text width=3cm]
\tikzstyle{myarrow}=[->, >=open triangle 90, thick]
\tikzstyle{line}=[-, thick]
\usepackage{luacode}
\begin{luacode}
function factorial(n)
if (n == 0) then
return 1
else
return nfactorial(n-1)
end
end
function binom(n,k)
return factorial(n) / (factorial(n-k) * factorial(k))
end
function nbin(t)
local res = 0
for k = 0, math.floor(t), 1 do
res = res + (binom(k+2,2) * 1/8 * (1/2)^k)
end
return res
end
\end{luacode*}
\begin{document}
\setcounter{secnumdepth}{4}
\tableofcontents
\input{code.tex}\fontsize{12pt}{16pt}\selectfont
\setlength{\parindent}{0cm}
\setlength{\parskip}{3mm plus1mm minus1mm}
\sloppy
\end{document}
And here is the part of code.tex
\begin{center}
\begin{tikzpicture}[
declare function={nbin(\t) = \directlua{tex.sprint(nbin(\t))};}
]
\begin{axis}[
use fpu=false,
height=8 cm,
width = 8 cm,
samples at={0,1,...,40},
]
\addplot[no markers]{nbin(x)};
\end{axis}
\end{tikzpicture}
\end{center}
It doesn't give any errors, just a clear Diagram with both axis going from 0 to 1 in 0.2 steps.
\documentclass{...}and ending with\end{document}. – DG' Jan 05 '21 at 15:15