在 VS Code 的 Polyglot (.NET Interactive) 笔记本中,代码单元是否可以创建或显示 Markdown 输出?
let myMd = "## Title\nText"
myMd |> displayAsMarkdown
有人似乎能够用美人鱼做到这一点:在多语言笔记本中显示来自 C# 变量的美人鱼图 其他人使用 Python 库来格式化程序化降价:https://data-dive.com/jupyterlab-markdown-cells-include-variables/#:~:text=Surprisingly%2C%20Jupyter%20Notebooks%20do%20not,轻松%20到%20安装%20和%20配置.
我想使用 Notebook markdown 的全部功能,包括 LaTex 数学。由于存在渲染降价的功能,因此无法访问它似乎很反常。 我找不到任何示例或文档。
Kernel.Root.SendAsync(new SubmitCode("markdown", "My markdown text"))
路线似乎行不通。
一个 hacky 解决方案,灵感来自: 如何将 LaTeX 与 Markdown 混合?
我使用 MarkdownSharp 和 MathJax 来综合我想要的行为:
#r "nuget: MarkdownSharp"
open Microsoft.DotNet.Interactive
open Microsoft.DotNet.Interactive.Commands
let jax =
"""
<style TYPE="text/css">
code.has-jax {font: inherit; font-size: 100%; background: inherit; border: inherit;}
</style>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']],
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'] // removed 'code' entry
}
});
MathJax.Hub.Queue(function() {
var all = MathJax.Hub.getAllJax(), i;
for(i = 0; i < all.length; i += 1) {
all[i].SourceElement().parentNode.className += ' has-jax';
}
});
</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML-full"></script>
"""
let formula = @"$$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)$$"
let text =
$"## Agency fixed default rate\nAgencies have a fixed annual default probability of {100.0 * assumptions.agencyDefaultRate}%%, designed to capture unmodelled risk including fraud, operational risk, regulatory risk, and so forth.\n"
let html = MarkdownSharp.Markdown().Transform(text)
Kernel.Root.SendAsync(new SubmitCode(jax+html+formula, "html"))
|> Async.AwaitTask
|> Async.RunSynchronously
|> ignore