Comments (8)
Thank you. I think adding pysub
and overcoming those limitations will be tremendously useful.
from codebraid.
It looks like Pandoc won't parse Markdown inside LaTeX math. So I'd suggest something like this, using a format string:
```{.python .cb.run}
from math import *
var = 123
```
Note that `rf"$\sqrt{{{var}}} = {sqrt(var)}$"`{.python .cb.expr}.
And then compile with something like
codebraid pandoc -f markdown -t html --mathjax -s -o temp.html temp.md
If this sort of situation comes up a lot, I suppose I might consider creating a string template command similar to the pysub
I created in PythonTeX. Maybe something like
`$\sqrt{!{var}} = !{sqrt(var)}$`{.python .cb.sub}
Basically, everything inside backticks could be treated as a template string, with substitution fields denoted by !{<code>}
, and an option to use multiple braces as delimiters (similar to Markdown backticks) to escape any literal braces within <code>
. This would eliminate string quoting, string backslash escapes for non-raw strings, and LaTeX brace escaping.
from codebraid.
Thank you for the helpful suggestion.
Any chance that the string template could become a command-line option for CodeBraid?
from 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?
from codebraid.
I was thinking of an option (say -s) that will make the following syntax
`$\sqrt{!{var}} = !{sqrt(var)}$`{.python .cb.sub}
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.
from codebraid.
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.
from codebraid.
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.
from codebraid.
You might look into Pandoc filters.
For example, create inline_cb.lua
:
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 temp.md
:
`py 1+1`
Run pandoc -L inline_cb.lua -f markdown -t markdown -o intermediate.md temp.md
to create intermediate.md
:
`1+1`{.python .cb.expr}
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.
from codebraid.
Related Issues (20)
- Pandoc Version Read Incorrectly HOT 1
- Errors with pandoc 2.11 HOT 3
- Search path for Python executable on Windows
- --citeproc Pandoc option HOT 1
- Failure when specifying local MathJax HOT 2
- Use of inline html code characters appears to break source file parsing HOT 2
- Working with multiple source files w/ .cb.nb HOT 2
- can't run codebraid with new version of jupyter-client HOT 4
- What is the status of per-chunk caching? Is it supported/planned? HOT 8
- `codebraid` can't handle raw latex HOT 8
- Custom executable / custom language HOT 4
- How to use the Julia jupyter kernel to generate plots in output HOT 4
- Does codebraid work with Python Anaconda environments? Trouble plotting with python from jupyter notebook HOT 7
- Question about removing extraneous markdown characters from output HOT 2
- --only-code-output doesn't support example=true
- Overly aggressive caching HOT 3
- Markdown strings don't render normally HOT 2
- Feature request: Force execution of all code cells without adding `.cb-run` and `.cb-nb` HOT 3
- Feature request: override stdout code block language HOT 2
- host a website HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codebraid.