This question is related to "Using sageTeX to define a variable for a TikZ picture" . To simplify the answer I want to introduce in my LaTeX code the new command "\def \crt{6.00000000000000}" where the number 6 is the result of a sage computation. But the string is simply ignored and I get an error.
The MWE follows:
\documentclass{article}
\usepackage{sagetex}
\usepackage{tikz}
\begin{document}
Begin sagesilent, \ldots
\begin{sagesilent}
reset()
var('rd')
def def4tikz(rd):
ret = [r'\def \crt{']
ret.append(str(rd))
ret.append(r'}')
return '\n'.join(ret)
rd=6.
## The next line is for checking purpose only
print def4tikz(rd)
\end{sagesilent}
\sagestr{def4tikz(rd)}
%% What follows is a cut and paste of the result last line of the sage silent block copied from the terminal, comment it in and the code works, the \sagestr instruction is ignored.
%\def \crt{
%6.00000000000000
%}
After sagesilent we print $\sage{rd}$
and we should also get $\crt$.
\end{document}
So if we take the output directly from the terminal we get the \def correctly but if we use the instruction \sagestr we get the "Undefined control sequence" error for \crt.
It looks strange and it is not consistent with the related question where the code for the TikZ picture is pulled in and correctly executed.
\sagestr{def4tikz(rd)}doesn't define\crtas you wanted; it's effectively pulling in the\defusing a LaTeX\ref, and I wouldn't expect a\definside a\newlabelto work. – Dan Drake Sep 15 '16 at 03:25reset()(there's nothing to reset), and after defining the symbolic variable "rd", you overwrite it with the integer 6. If you just wantrdto be 6, there's no need for thevar('rd')line. – Dan Drake Sep 15 '16 at 03:27