mirror of
https://github.com/WolframResearch/WolframLanguageForJupyter.git
synced 2025-04-18 12:46:06 +00:00
Add handling of TeXForm
This commit is contained in:
parent
b63c459fa3
commit
f5bcdbe765
@ -9,6 +9,7 @@ Symbols defined:
|
||||
applyHook,
|
||||
$canUseFrontEnd,
|
||||
$outputSetToTraditionalForm,
|
||||
$outputSetToTeXForm,
|
||||
$trueFormatType,
|
||||
connectionAssoc,
|
||||
bannerWarning,
|
||||
@ -98,7 +99,16 @@ If[
|
||||
$canUseFrontEnd := (UsingFrontEnd[$FrontEnd] =!= Null);
|
||||
|
||||
$outputSetToTraditionalForm := (Lookup[Options[$Output], FormatType] === TraditionalForm);
|
||||
$trueFormatType := If[$outputSetToTraditionalForm, TraditionalForm, #&];
|
||||
$outputSetToTeXForm := (Lookup[Options[$Output], FormatType] === TeXForm);
|
||||
$trueFormatType :=
|
||||
Which[
|
||||
$outputSetToTraditionalForm,
|
||||
TraditionalForm,
|
||||
$outputSetToTeXForm,
|
||||
TeXForm,
|
||||
True,
|
||||
Identity
|
||||
];
|
||||
|
||||
(* obtain details on how to connect to Jupyter, from Jupyter's invocation of "KernelForWolframLanguageForJupyter.wl" *)
|
||||
connectionAssoc = ToString /@ Association[Import[$CommandLine[[4]], "JSON"]];
|
||||
|
@ -28,7 +28,8 @@ If[
|
||||
files
|
||||
*************************************)
|
||||
|
||||
Get[FileNameJoin[{DirectoryName[$InputFileName], "Initialization.wl"}]]; (* $canUseFrontEnd, $outputSetToTraditionalForm
|
||||
Get[FileNameJoin[{DirectoryName[$InputFileName], "Initialization.wl"}]]; (* $canUseFrontEnd, $outputSetToTeXForm,
|
||||
$outputSetToTraditionalForm,
|
||||
$trueFormatType *)
|
||||
|
||||
(************************************
|
||||
@ -105,6 +106,12 @@ If[
|
||||
Return[True]
|
||||
];
|
||||
|
||||
(* if the FormatType of $Output is set to TeXForm, or if the expression is wrapped with TeXForm,
|
||||
and the expression has an acceptable textual form, format as text *)
|
||||
If[($outputSetToTeXForm || exprHead == TeXForm) && !containsPUAQ[ToString[expr]],
|
||||
Return[True];
|
||||
];
|
||||
|
||||
(* if the FormatType of $Output is set to TraditionalForm,
|
||||
or if the expression is wrapped with TraditionalForm,
|
||||
do not use text *)
|
||||
@ -172,23 +179,57 @@ If[
|
||||
|
||||
(* generate HTML for the textual form of a result *)
|
||||
toOutText[result_] :=
|
||||
Module[
|
||||
{isTeXWrapped, isTeXFinal},
|
||||
(* check if this result is wrapped with TeXForm *)
|
||||
isTeXWrapped = (Head[result] === TeXForm);
|
||||
(* check if this result should be marked, in the end, as TeX *)
|
||||
isTeXFinal = isTeXWrapped || $outputSetToTeXForm;
|
||||
Return[
|
||||
StringJoin[
|
||||
|
||||
(* mark this result as preformatted only if it isn't TeX *)
|
||||
If[
|
||||
!isTeXFinal,
|
||||
{
|
||||
(* preformatted *)
|
||||
"<pre style=\"",
|
||||
(* use Courier *)
|
||||
StringJoin[{"&#", ToString[#1], ";"} & /@ ToCharacterCode["font-family: \"Courier New\",Courier,monospace;", "Unicode"]],
|
||||
"\">",
|
||||
"\">"
|
||||
},
|
||||
{}
|
||||
],
|
||||
|
||||
(* mark the text as TeX, if is TeX *)
|
||||
If[isTeXFinal, "$$", ""],
|
||||
|
||||
(* the textual form of the result *)
|
||||
(* NOTE: the OutputForm (which ToString uses) of any expressions wrapped with, say, InputForm should
|
||||
be identical to the string result of an InputForm-wrapped expression itself *)
|
||||
StringJoin[{"&#", ToString[#1], ";"} & /@
|
||||
({"&#", ToString[#1], ";"} & /@
|
||||
ToCharacterCode[
|
||||
(* toStringUsingOutput[result] *) ToString[result],
|
||||
"Unicode"
|
||||
]
|
||||
(* toStringUsingOutput[result] *)
|
||||
Quiet[
|
||||
ToString[If[!isTeXWrapped, $trueFormatType[result], result]]
|
||||
],
|
||||
"Unicode"
|
||||
]),
|
||||
|
||||
(* mark the text as TeX, if is TeX *)
|
||||
If[isTeXFinal, "$$", ""],
|
||||
|
||||
(* mark this result as preformatted only if it isn't TeX *)
|
||||
If[
|
||||
!isTeXFinal,
|
||||
{
|
||||
(* end the element *)
|
||||
"</pre>"
|
||||
},
|
||||
{}
|
||||
]
|
||||
]
|
||||
];
|
||||
];
|
||||
|
||||
(* generate HTML for the rasterized form of a result *)
|
||||
|
Loading…
x
Reference in New Issue
Block a user