TeX - LaTeX Asked by riddleculous on February 10, 2021
Having solved my previous problem involving savebox
and tikzexternalize
I am already facing the next one. I would like to use a function that I have defined either in or after the preamble with pgfmathdeclarefunction
in a savebox
. It works nicely when using it outside of a tikzpicture
, but inside it will get optimized away (see comments in the example below). Why is that so? Or: How can I get TikZ not to optimize the figure away? Note that this solution doesn’t help.
documentclass{article}
usepackage[english]{babel}
usepackage{tikz,pgfplots}
usetikzlibrary{positioning}
usepgfplotslibrary{external}
tikzexternalize
begin{document}
pgfmathdeclarefunction{gauss}{2}{%
pgfmathparse{1*exp(-(#2)^2/(#1^2))}%
}
newsaveboxboxCPAin
saveboxboxCPAin{
begin{tikzpicture}
tikzset{external/optimize=false}%
draw[domain=-1:1,samples=200] plot(x,{gauss(.33,x)});
end{tikzpicture}
}
useboxboxCPAin % works!
begin{tikzpicture}
node (test) {useboxboxCPAin}; % tikzpicture optimized away because it does not contribute to exported PDF
end{tikzpicture}
end{document}
Interestingly, it works, when I put the savebox
declaration in my tikzpicture
environment:
documentclass{article}
usepackage[english]{babel}
usepackage{tikz,pgfplots}
usetikzlibrary{positioning}
usepgfplotslibrary{external}
tikzexternalize
begin{document}
pgfmathdeclarefunction{gauss}{2}{%
pgfmathparse{1*exp(-(#2)^2/(#1^2))}%
}
begin{tikzpicture}
newsaveboxboxCPAin
saveboxboxCPAin{
begin{tikzpicture}
tikzset{external/optimize=false}%
draw[domain=-1:1,samples=200] plot(x,{gauss(.33,x)});
end{tikzpicture}
}
node (test) {useboxboxCPAin}; % works!
end{tikzpicture}
end{document}
Apparently TikZ can't optimize away the savebox
since it has just been created in the same tikzpicture
.
Answered by riddleculous on February 10, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP