Repository navigation
feat: render formula outputs from code-lab cells - #64
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
latexoutput kind to code-lab, rendered with KaTeX (lazy-loaded, so plain cells never download it). All four languages can produce it.How each language produces it — only the cell's final value counts;
print/console.log/displaystay plain text:_repr_latex_(SymPy implements it, sodiff(x*sin(x), x)just renders). DataFrame HTML still wins; classes are skipped.toLatex(): string, next to the existingtoHtml()(latex "\\frac{1}{2}")— for the SICP material(latex "..."), defined in theusernamespace at startup (user/latexafter annsswitch);#js {:toLatex (fn [] ...)}also works. Cells are now wrapped so a value withtoLatexis returned as-is and everything else still goes throughpr-str.LatexOutputsets KaTeX'srenderToStringmarkup throughdangerouslySetInnerHTML, with abiome-ignore: KaTeX's defaulttrust: falsealready rejects\hrefand\html*commands.One small change from the agreed plan: Python ignores
_repr_latex_on class objects, so evaluatingSymbolprints<class ...>instead of a traceback.Verification
typecheckpasses for code-lab, web and playground; code-lab tests andbiome checkpass.print(...),Symbol,42and'abc'stay text; a DataFrame is still a table.toLatex()renders; malformed TeX shows KaTeX's red source instead of crashing;21 * 2stays text.(latex ...)renders, including from inside adefined procedure;(+ 1 2)stays text.(latex ...), adefnreturninglatex,#js {:toLatex ...}anduser/latexafter(ns sicp.ch1)render;(+ 1 2)and(map inc ...)stay text;nilprints nothing;(latex 42)reportslatex expects a string, got 42.Known issue (pre-existing, not fixed here)
In Scheme,
(latex 42)fails as intended, but the cell showsBiwaScheme interpreter error { "form": null }instead of the message. Every Scheme runtime error looks like that today ((car 1),(string-length 42)), so it belongs in a separate fix.