On Mon, 16 Jan 2012 at 03:10AM -0800, jplab wrote: > But since I'm a lazy guy, I want tex to do the work for me. That's why > I thought of a tex command that would: > > 1) take all the needed arguments; > 2) run a sagesilent block; > 3) include the produced tikz picture (produced in the sagesilent > block, included in a file). > > All that in a very nice tex command. > > Something like (replacing the polytope things by a matrix for > simplication reasons...): > > \newcommand{\tikzimage}[1]{\begin{sagesilent} > M=matrix([[1,1], > [2,2]]) > Image=latex(M) > > open('dessin.tex', 'w').write(Image); > \end{sagesilent} > \input{dessin.tex} > }
My first thought is, why do you need to write to an external file? It looks like you could just do \newcommand{\tikzimage}[1]{\sage{matrix([1,1],[2,2])}} Another (untested!) idea is: use a regular sagesilent block to set up a function that does what you want, and then use \sagestr to pull in the code you want. Something like \begin{sagesilent} def foo(x): return 'some tikz code with {0} in it'.format(x) \end{sagesilent} \newcommand{\tikzimage}[1]{\sagestr{#1}} The \sagestr macro just pulls in a string, it doesn't run latex() on its argument -- see the "Make Sage write your LaTeX for you" and the "Plotting functions in TikZ with SageTeX" sections of the example file: https://bitbucket.org/ddrake/sagetex/src/tip/example.tex (and the typeset version: https://bitbucket.org/ddrake/sagetex/downloads/example.pdf. Do any of these ideas work for you? Dan -- --- Dan Drake ----- http://mathsci.kaist.ac.kr/~drake -------
signature.asc
Description: Digital signature