-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Executing python code within $...$? [enhancement: add cb.sub command] #27
Comments
It looks like Pandoc won't parse Markdown inside LaTeX math. So I'd suggest something like this, using a format string:
And then compile with something like
If this sort of situation comes up a lot, I suppose I might consider creating a string template command similar to the
Basically, everything inside backticks could be treated as a template string, with substitution fields denoted by |
Thank you for the helpful suggestion. Any chance that the string template could become a command-line option for CodeBraid? |
I was thinking about a string template as another command that could be applied to code blocks. What are you thinking about in terms of a command-line option? How might that work? |
I was thinking of an option (say -s) that will make the following syntax
become automatic for the entire file. EDIT: I probably haven't articulated myself very well. I am new to CodeBraid and I was just hoping that inlining would be as simple as Knitr. I do hope to use CodeBraid whenever possible since it's so much more powerful. |
It sounds like you're interested in a more compact, less verbose syntax, especially for inline code. I'm interested in adding alternate syntax eventually. So far I've limited everything to Pandoc's built-in attribute syntax. That can be verbose and isn't ideal in some respects, but it does allow all of the Markdown processing to be delegated to Pandoc, which has a lot of advantages. |
That would be a fair assessment of my interest. But I now do understand the philosophy behind CodeBraid. Perhaps one could just write a preprocessor that turns a compact syntax into the full-blown syntax that CodeBraid accepts. I should take a stab at this, perhaps mimicking what Knitr does to ease my own transition. |
You might look into Pandoc filters. For example, create Code = function(elem)
if string.sub(elem.text, 1, 3) == "py " then
elem.text = string.sub(elem.text, 4, string.len(elem.text)):match("^%s*(.*)")
elem.classes:insert("python")
elem.classes:insert("cb.expr")
end
return elem
end Create a file
Run
Then send that through Codebraid. Codebraid can use filters, but I don't yet have a way to run filters before code execution, which is what would be needed in this case. Also, I'm using an intermediate file instead of piping since I just realized that there isn't yet support for reading from stdin. Both of those limitations should be easy to fix in future releases, so that you could just use a filter when running Codebraid directly. |
Thank you. I think adding |
In knitr, one could have something like this
The last line will get rendered to html as
Note that \(\sqrt{123} = 11.0905365\).
Does CodeBraid allow executing the python code within$...$ to accomplish the same thing? My initial experiment suggests that it doesn't. Any help is greatly appreciated.
The text was updated successfully, but these errors were encountered: