WolframResearch / WolframLanguageForJupyter

Wolfram Language kernel for Jupyter notebooks
MIT License
1.03k stars 124 forks source link

TeXForm Output in JupyterLab #83

Closed PhyX-Meow closed 3 years ago

PhyX-Meow commented 4 years ago

Hello, I am using Jupyterlab, and I found that if use TeXForm[] for the cell output, it looks just great.

Snipaste_2020-03-05_13-59-54 Snipaste_2020-03-05_14-00-44

I guess it's because jupyter lab automatically renders the tex expressions.

However there's still some ploblem with this method. If the output expression is too long, something bad happens. Here's a short code in my homework: f[z_] := (z + I)/(I*z + 1);x = Re@f@a; y = Im@f@a;xi = f@Exp[I theta]; FullSimplify[y / ((x - xi)^2 + y^2) * f'@Exp[I theta]]

it should output someting like this Snipaste_2020-03-05_14-10-48 But actually it looks like this Snipaste_2020-03-05_14-12-13 An unexpected '>' in the expression I turn to the source file of this notebook and found Snipaste_2020-03-05_14-15-33 It seems the '>' occurs when the output wrap to a new line. I tried in my shell and get the same wrap.

My question is, is there any method to get the right result or simplily disable the line warpping

PhyX-Meow commented 4 years ago

Thanks Everyone!

jfultz commented 4 years ago

I'm not set up with the Jupyter+Wolfram kernel to test this right now, but in Wolfram Language, one would typically solve line-wrapping problems like this by doing:

SetOptions["stdout",PageWidth->Infinity]

It certainly works to stop the WL language from imposing line-wrapping onto TeXForm output on the command-line, and I suspect it'll work similarly in Jupyter, unless the WL plugin overrides your change (which it might in some circumstances).

You might be interested to know that you can also set the default FormatType to TeXForm by doing something similar:

SetOptions["stdout",FormatType->TeXForm]

But I don't think most people would appreciate this as a default. This would, for example, deeply break default graphics output.

PhyX-Meow commented 4 years ago

@jfultz Thanks, it works, but in a strange way. I tried pagewidth infinity but nothing changed. Then I tried a small pagewidth and get more '>' in the expression Finally I tried a large pagewidth but not infinity (such as 200), and get the right output. It looks really strange, seems the infinity pagewidth is not processed correctly?

By the way, in shell, pagewidth->infinity does as expected.

arnoudbuzing commented 4 years ago

Note that the Wolfram Language is case-sensitive.

So pagewidth->infinity is meaningless. It should be PageWidth->Infinity.

PhyX-Meow commented 4 years ago

@arnoudbuzing Thanks, but I know it. I just use the lowercase in the comment for convenience, or I would not get the expected behavior when I set pagewidth 200. And here's the case PageWidth ->Infinity, just the same as default, in which PageWidth is 89. image

cc-wr commented 4 years ago

@PhyX-Meow, sorry, this is a bug. WolframLanguageForJupyter should not be inserting line breaks in text/html results that contain TeX source, and WolframLanguageForJupyter should not be rejecting Infinity as a page width. #84 should resolve both of these issues.

With #84, line breaks in text/html results that contain TeX source are now disallowed, and you should not have to run SetOptions["stdout", PageWidth -> Infinity] for this purpose.

glennhanks commented 4 years ago

One more problem: ToExpression[" \\frac{1}{2} ", TeXForm] does not work. According to the source of ipynb, it shows:
"source": [ "ToExpression[\" \\\\frac{1}{2} \", TeXForm]" ]

cc-wr commented 3 years ago

One more problem: ToExpression[" \\frac{1}{2} ", TeXForm] does not work. According to the source of ipynb, it shows: "source": [ "ToExpression[\" \\\\frac{1}{2} \", TeXForm]" ]

@glennhanks, this is a separate issue that the pull request #102 attempts to address.

cc-wr commented 3 years ago

A general request for comments on the pull request #84 (which addresses @PhyX-Meow's issue) and the pull request #102 (which should address @glennhanks' issue) is at #103.