ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 23 Jan 2012 04:01:58 -0600Generating dynamic latexhttp://ask.sagemath.org/question/8084/generating-dynamic-latex/Is there any way to dynamically generate $\LaTeX$ code in a block preceeded by `%latex`? This could be useful for taking a data structure and iterating through it to create a data table using the corresponding data.
Thanks!Fri, 20 Jan 2012 14:58:31 -0600http://ask.sagemath.org/question/8084/generating-dynamic-latex/Answer by pang for <p>Is there any way to dynamically generate $\LaTeX$ code in a block preceeded by <code>%latex</code>? This could be useful for taking a data structure and iterating through it to create a data table using the corresponding data.</p>
<p>Thanks!</p>
http://ask.sagemath.org/question/8084/generating-dynamic-latex/?answer=13176#post-id-13176You can use
Latex().eval(my_string, globals=globals)
as explained in [this answer](http://ask.sagemath.org/question/301/what-is-the-function-for-latex-on-a-notebook-cell?answer=569#569) to a similar question.
Sun, 22 Jan 2012 22:54:07 -0600http://ask.sagemath.org/question/8084/generating-dynamic-latex/?answer=13176#post-id-13176Comment by stef for <p>You can use </p>
<pre><code>Latex().eval(my_string, globals=globals)
</code></pre>
<p>as explained in <a href="http://ask.sagemath.org/question/301/what-is-the-function-for-latex-on-a-notebook-cell?answer=569#569">this answer</a> to a similar question.</p>
http://ask.sagemath.org/question/8084/generating-dynamic-latex/?comment=20462#post-id-20462That's it! Thanks! I was able to dynamically generate a table by iterating over data and constructing the corresponding formatting. I was able to use the globals dictionary to pass data in so that it can be rendered inside of `\sage{}` calls, but what purpose does the `locals` argument serve?Mon, 23 Jan 2012 04:00:51 -0600http://ask.sagemath.org/question/8084/generating-dynamic-latex/?comment=20462#post-id-20462Answer by Shashank for <p>Is there any way to dynamically generate $\LaTeX$ code in a block preceeded by <code>%latex</code>? This could be useful for taking a data structure and iterating through it to create a data table using the corresponding data.</p>
<p>Thanks!</p>
http://ask.sagemath.org/question/8084/generating-dynamic-latex/?answer=13156#post-id-13156Have you tried sagetex? What you can do is install sagetex and then when you latex your .tex file you can include sage commands inside the tex file. Sagetex will solve the equations and latex them for you.
Edit:
Also there is a command latex. For eg.
alpha=var('alpha')
latex(sin(alpha))
gives you the latex output for the expression which you can copy paste in to you latex document.Fri, 20 Jan 2012 17:54:49 -0600http://ask.sagemath.org/question/8084/generating-dynamic-latex/?answer=13156#post-id-13156Comment by stef for <p>Have you tried sagetex? What you can do is install sagetex and then when you latex your .tex file you can include sage commands inside the tex file. Sagetex will solve the equations and latex them for you.</p>
<p>Edit:</p>
<p>Also there is a command latex. For eg.</p>
<pre><code>alpha=var('alpha')
latex(sin(alpha))
</code></pre>
<p>gives you the latex output for the expression which you can copy paste in to you latex document.</p>
http://ask.sagemath.org/question/8084/generating-dynamic-latex/?comment=20478#post-id-20478Oh - I'd like to try and do it within the context of notebook. I'm just trying to demo Sage for use in connecting to Apache Hive to generate summary reports on data. I've been able to generate some limited success by calling `latex.eval("...")` where the string can be dynamically constructed with data. It also helps to pass in data via the `locals` construct, allowing for that data to be referenced inside `\sage{}` blocks. However, the rendering of `latex.eval()` has been somewhat subpar. For example:
latex.eval(r"""
\documentclass[12pt]{article}
\usepackage[margin=0.20in,landscape]{geometry}
\usepackage{colortbl}
\usepackage[table]{xcolor}
\begin{document}
\begin{tabular}{ cccccccccc }
\hline
\rowcolor[rgb]{0.21,0.37,0.58}...
\end{tabular}
\end{document}""",{})Fri, 20 Jan 2012 20:51:10 -0600http://ask.sagemath.org/question/8084/generating-dynamic-latex/?comment=20478#post-id-20478Answer by John Palmieri for <p>Is there any way to dynamically generate $\LaTeX$ code in a block preceeded by <code>%latex</code>? This could be useful for taking a data structure and iterating through it to create a data table using the corresponding data.</p>
<p>Thanks!</p>
http://ask.sagemath.org/question/8084/generating-dynamic-latex/?answer=13157#post-id-13157Does the `\sage` command do what you want?
%latex
Did you know that $20! = \sage{factorial(20)}$?
Sat, 21 Jan 2012 03:44:54 -0600http://ask.sagemath.org/question/8084/generating-dynamic-latex/?answer=13157#post-id-13157Comment by stef for <p>Does the <code>\sage</code> command do what you want?</p>
<pre><code>%latex
Did you know that $20! = \sage{factorial(20)}$?
</code></pre>
http://ask.sagemath.org/question/8084/generating-dynamic-latex/?comment=20461#post-id-20461This was close, however you can't generate arbitrary LaTeX code with the `\sage` command. `latex.eval()` ended up being what I was looking for. Thanks for your input though!Mon, 23 Jan 2012 04:01:58 -0600http://ask.sagemath.org/question/8084/generating-dynamic-latex/?comment=20461#post-id-20461