Skip to content
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

Add support for latex output in VSCode Jupyter notebook #136

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions WolframLanguageForJupyter/Resources/OutputHandlingUtilities.wl
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,29 @@ If[
(* generate the textual form of a result using the current PageWidth setting for $Output *)
toText[result_] := toText[result, $truePageWidth];

toTeX[result_] :=
Module[
{
(* if the result should be marked as TeX *)
isTeX
},
(* check if the result should be marked as TeX *)
isTeX = ((Head[result] === TeXForm) || ($outputSetToTeXForm));
Return[
If[
!isTeX,
(* if not TeX, return $Failed *)
$Failed,
StringJoin[
(* wrap the result with latex symbol *)
"$$",
toText[result, Infinity],
"$$"
]
]
];
];

(* generate HTML for the textual form of a result *)
toOutTextHTML[result_] :=
Module[
Expand Down
39 changes: 38 additions & 1 deletion WolframLanguageForJupyter/Resources/RequestHandlers.wl
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ If[
(* the data representing the results and messages *)
"data" ->
{
(* "text/plain" ->
StringJoin[
toText[totalResult]
]
, *)
(* generate HTML for the results and messages *)
"text/html" ->
If[
Expand Down Expand Up @@ -360,10 +365,42 @@ If[
},
{outIndex, 1, Length[totalResult["EvaluationResult"]]}
]
],
Module[
(* list of the results in the TeX form *)
{
results
},
results = If[
loopState["isCompleteRequestSent"],
(* if an is_complete_request has been sent, assume jupyter-console is running the kernel,
and do not generate HTML *)
"",
If[
Length[totalResult["EvaluationResult"]] > 1,
(* If there are multiple results, display it line by line *)
Table[
toTeX[totalResult["EvaluationResult"][[outIndex]]],
{outIndex, 1, Length[totalResult["EvaluationResult"]]}
],
(* Otherwise for single result, display the first one *)
If[
Length[totalResult["EvaluationResult"]] == 0,
{$Failed},
{toTeX[First[totalResult["EvaluationResult"]]]}
]
]
];
(* check if any of the result is not in the TeXForm, if so, do not display TeX output *)
If[
MemberQ[results, $Failed],
Nothing,
"text/latex" -> results
]
]
},
(* no metadata *)
"metadata" -> {"text/html" -> {}, "text/plain" -> {}}
"metadata" -> {"text/html" -> {}, "text/plain" -> {}, "text/latex" -> {}}
],
"JSON",
"Compact" -> True
Expand Down