Use the current PageWidth setting for $Output when converting a result into a string

This commit is contained in:
cc-wr 2019-12-22 23:45:06 -05:00
parent 3523e815e6
commit 1717628fc8
2 changed files with 24 additions and 3 deletions

View File

@ -5,12 +5,14 @@ Description:
Initialization for
WolframLanguageForJupyter
Symbols defined:
$defaultPageWidth,
loopState,
applyHook,
$canUseFrontEnd,
$outputSetToTraditionalForm,
$outputSetToTeXForm,
$trueFormatType,
$truePageWidth,
connectionAssoc,
bannerWarning,
keyString,
@ -57,7 +59,8 @@ If[
*************************************)
(* make Short[] work *)
SetOptions[$Output, PageWidth -> 89];
$defaultPageWidth = 89;
SetOptions[$Output, PageWidth -> $defaultPageWidth];
(* do not output messages to the jupyter notebook invocation
$Messages = {};
@ -224,6 +227,14 @@ If[
TraditionalForm,
If[$outputSetToTeXForm, TeXForm, #&]
];
$truePageWidth :=
Replace[
Lookup[Options[$Output], PageWidth],
Except[
pageWidth_ /; ((IntegerQ[pageWidth]) && (pageWidth > 0))
] ->
$defaultPageWidth
];
(* hard-coded base64 rasterization of $Failed *)
failedInBase64 = "iVBORw0KGgoAAAANSUhEUgAAADcAAAARCAIAAAD2TKM6AAAAhXpUWHRSYXcgcHJvZmlsZSB0eXBlIGV4aWYAAHjaVYvBDcMwDAP/mqIjyLJM2uMYiQNkg45fuu0n9yApgbT1vi97felp2dgxABc5csRU6P6juNciDXn+X9MfZGWgoRhTluEkhnJXkqKFN+LCAahYcIbnIV8gNQN3o86928QyPusLVffpbh/5eCey76LuBgAAAAlwSFlzAAALEwAACxMBAJqcGAAAADx0RVh0U29mdHdhcmUAQ3JlYXRlZCB3aXRoIHRoZSBXb2xmcmFtIExhbmd1YWdlIDogd3d3LndvbGZyYW0uY29tXKKmhQAAACF0RVh0Q3JlYXRpb24gVGltZQAyMDE5OjA3OjAyIDAzOjExOjExSFD8JQAAA8xJREFUSInVlk9IKl8Ux68ajjThLynMwCKLICSDjBbRxpVSFhFkCtFfBMMKAhcu3GXhQopaJBEFISjhsn9YUGE6zSJq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VTK/POVSuX4+LjBYODxeE6ns6am5m19ZqKtVuvMzAydAwRBhEIhiqJyCc5AUVQoFEomk9lOHMfD4fB3qRKJxNPTU7aHRb/fiY6Ojng8nkwmy7GJv5MPlX8z/4+b2zdkknhkRbjZsAAAAABJRU5ErkJggg==";

View File

@ -32,7 +32,8 @@ If[
Get[FileNameJoin[{DirectoryName[$InputFileName], "Initialization.wl"}]]; (* $canUseFrontEnd, $outputSetToTeXForm,
$outputSetToTraditionalForm,
$trueFormatType, failedInBase64 *)
$trueFormatType, $truePageWidth,
failedInBase64 *)
(************************************
private symbols
@ -182,7 +183,16 @@ If[
(* generate the textual form of a 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 *)
toText[result_] := ToString[If[Head[result] =!= TeXForm, $trueFormatType[result], result]];
toText[result_] :=
ToString[
If[
Head[result] =!= TeXForm,
$trueFormatType[result],
result
],
(* also, use the current PageWidth setting for $Output *)
PageWidth -> $truePageWidth
];
(* generate HTML for the textual form of a result *)
toOutTextHTML[result_] :=