njpipeorgan / wolfram-language-notebook

Notebook support for Wolfram Language in VS Code
Apache License 2.0
159 stars 11 forks source link

I cannot export my notebook as PDF. #16

Closed yfzhao20 closed 2 years ago

yfzhao20 commented 2 years ago

Describe the bug I can not export my notebook as PDF. It tells me "Failed to export the notebook."

5jfgfd

Environment (please complete the following information):

njpipeorgan commented 2 years ago

Thanks for the feedback. I did the same test in the same environment, but I was not able to replicate this issue.

Can you export as a Wolfram notebook in this case? If so, could you attach the content of the exported Wolfram notebook so that I can investigate the issue?

yfzhao20 commented 2 years ago

Here is it. I have disabled all other extensions, but it failed as well.

Notebook[{
Cell[BoxData[{"$Version"}],"Input"],
Cell[BoxData["\"12.3.1 for Microsoft Windows (64-bit) (June 24, 2021)\""],"Output",CellLabel->"Out[1]= "],
Cell[BoxData[{RowBox[{RowBox[{"Integrate", "[", RowBox[{RowBox[{"E", "^", RowBox[{"(", RowBox[{"-", RowBox[{"x", "^", "2"}]}], ")"}]}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "Infinity"}], "}"}]}], "]"}], "//", "TeXForm"}]}],"Input"],
Cell[BoxData["\"\\\\frac{\\\\sqrt{\\\\pi }}{2}\""],"Output",CellLabel->"Out[3]//TeXForm= "]
}]
njpipeorgan commented 2 years ago

Thanks. It seems that kernel did not convert the notebook into PDF as expected. Could you run the following code (in the session where export as PDF fails) that tests this functionality?

notebook = Import[".../test.nb", "Text"]; (*replace ... with the path to the exported Wolfram notebook*)
pdf = BaseEncode[ExportByteArray[ToExpression[notebook, InputForm], "PDF"], "Base64"];
{Head[pdf], StringLength[pdf]}

If everything is normal, the result should be {String, ~70,000}.

yfzhao20 commented 2 years ago

I copied the code into test.wlnb and then it threw 'file not found' error:

https://user-images.githubusercontent.com/80528249/151347297-a6f0679a-11a8-492a-a9b3-77860c3c6b61.mp4

However when I tested it in exported test.nb file, it seemed okay:

https://user-images.githubusercontent.com/80528249/151347567-03f8b42a-c8f8-428b-9a92-927c47aa4544.mp4

njpipeorgan commented 2 years ago

Thanks for doing the tests! The error in the wlnb showed that the kernel somehow failed to execute ExportByteArray, which is beyond the control of the extension, so there is very little I can do with it. The complication here is that the "kernel" alone is not able to do the entire export--it needs to launch a front-end to do the printing (even for products without an explicit front-end like Wolfram Engine). That might explain why it worked in a Wolfram notebook.

The final thing I want to check is what would happen if you run this code from the text-based kernel program (or running WolframKernel from the terminal), because it is close to how everything works in wlnb.

Since the same problem does not occur on my end, reinstalling Mathematica may help.

yfzhao20 commented 2 years ago

I test it in terminal and the error still exists. So I think it is the problem of wolfram kernel.

Then I reinstall wolfram engine (upgrade to 13.0) and everything goes back to normal!

image

and here is PDF file 👇(TeXForm disappears, but it doesn't matter)

image

Thank you 👏!