# \sagestr(output) does not insert “output” in the LaTeX code.

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.

• I'm not surprised that \sagestr{def4tikz(rd)} doesn't define \crt as you wanted; it's effectively pulling in the \def using a LaTeX \ref, and I wouldn't expect a \def inside a \newlabel to work. – Dan Drake Sep 15 '16 at 3:25
• Also, it's unnecessary to begin your Sage code with reset() (there's nothing to reset), and after defining the symbolic variable "rd", you overwrite it with the integer 6. If you just want rd to be 6, there's no need for the var('rd') line. – Dan Drake Sep 15 '16 at 3:27
• In fact rd is the result of a computation, it is written as 6 for the MWE only. – c05772 Sep 15 '16 at 15:03
• The question is why would \sagestr{def4tikz} fails here when the \sagestr{mytikz(rd)} works in the related question (tex.stackexchange.com/questions/329456/…). – c05772 Sep 15 '16 at 15:08