Loading [MathJax]/jax/output/HTML-CSS/jax.js

First time here? Check out the FAQ!

Ask Your Question
0

Generating dynamic latex

asked 13 years ago

stef gravatar image

updated 13 years ago

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!

Preview: (hide)

3 Answers

Sort by » oldest newest most voted
1

answered 13 years ago

pang gravatar image

You can use

Latex().eval(my_string, globals=globals)

as explained in this answer to a similar question.

Preview: (hide)
link

Comments

That'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?

stef gravatar imagestef ( 13 years ago )
1

answered 13 years ago

Does the \sage command do what you want?

%latex
Did you know that $20! = \sage{factorial(20)}$?
Preview: (hide)
link

Comments

This 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!

stef gravatar imagestef ( 13 years ago )
0

answered 13 years ago

Shashank gravatar image

updated 13 years ago

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.

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.

Preview: (hide)
link

Comments

Oh - 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}""",{})

stef gravatar imagestef ( 13 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 13 years ago

Seen: 1,191 times

Last updated: Jan 23 '12