I was trying to input/import a standalone document containing a tikz image, which was made using the help of luacode. I was able to compile the standalone document containing the image, however, luacode being used in the premble of the document (even when unused) caused nothing to be inputted resulting in following error message (among others) in the logs:
"Package standalone Warning: Sub-preamble of file 'diagram.tex' has changed. Content will be ignored. Please rerun LaTeX! on input line 36."
This line contained begin{document}
.
I wasn't quite sure how to nicely give an example, since the problem spans multiple files, so I opted so show the code of each file separately. Note that the files. Note: I'm using LuaLaTeX as a compiler.
main.tex:
\documentclass{article}
\usepackage[subpreambles=true]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{import}
\RequirePackage{luatex85}
\begin{document}
\import{../}{diagram.tex}
\end{document}
dragram.tex:
\documentclass{standalone}
\RequirePackage{luatex85}
\usepackage{pgfplots}
\usepackage{luacode}
%the lua code:
\begin{luacode*}
function myfunc(x)
if x==0 then
return 0
else
x=3-(x-math.sqrt(3))^2
return x
end
end
function cobweb(x,n) --x is the starting point, n is the number of iterations
y1=0
for t=1,n,1 do
y2=myfunc(x)
tex.sprint("\\draw[very thin, color=red, smooth] ("..x.."cm,"..y1.."cm)-- " .. "("..x.."cm,"..y2.."cm);")
y1=myfunc(x)
tex.sprint("\\draw[very thin, color=red, smooth] ("..x.."cm,"..y2.."cm)-- " .. "("..y2.."cm,"..y2.."cm);")
x=y2
end
end
\end{luacode*}
\pgfmathdeclarefunction{Myfunc}{1}{%
\edef\pgfmathresult{%
\directlua{tex.print("" .. myfunc(#1))}%
}%
}
\begin{document}
\begin{tikzpicture}[
x = 1cm,
scale = 2,
myfunc/.style = {domain = 0:5, ymax=5, samples = 100}
]
\draw[->,thick] (0,0)--(5,0) node[right]{$x$};
\draw[->,thick] (0,0)--(0,5) node[above]{$y$};
\clip (0,0) rectangle (5,5);
\color{red}\directlua{cobweb(.01,10)}
\draw[thick, blue] (0,0)--(5,5);
\draw[black, thick] plot [myfunc] (\x, {Myfunc(\x)});
\end{tikzpicture}
\end{document}
Does anyone know/have suggestions for what the problem might be, and how I could possibly solve it? Or maybe you know of a different way to reach a similar, but working result?