如何在VS Code中为Jupyter Notebook(Windows)设置Latex。

huangapple go评论67阅读模式
英文:

How to set up Latex in VS Code for Jupyter Notebook (Windows)

问题

我已经开始学习Python,我想通过在VS Code中使用Jupyter Notebooks记录我的会话,并将它们导出为PDF。然而,我无法这样做,因为它需要Latex,而且似乎不像常规库(如numpy)那样容易安装。

通过VS界面导出PDF时,我收到以下消息:

[error] 如果您尚未安装xelatex(TeX),您需要在导出为PDF之前安装它。有关更多说明,请参阅 https://nbconvert.readthedocs.io/en/latest/install.html#installing-tex。为了避免安装xelatex(TeX),您可以尝试导出为HTML,然后使用浏览器的“打印为PDF”功能。

它还说我缺少Pandoc,尽管我已经通过pip安装了它(我认为这与没有安装TeX有关)。我已经检查了显示的链接,但不知道如何在Windows上设置Latex。我已经安装了MikTex,并在VS中安装了一些扩展(Latex和Latex Workshop)。我如何成功安装它以便能够成功导出为PDF?

当我打开Miktex packages时,只会看到一个空的控制台。

另外,我之前在Overleaf上在线使用Latex,每次我想包含一个包时,我只需使用\includepackage{...}。在VS中是否可以以相同的方式工作?由于它不是在线的,我不确定是否能够轻松下载包。

英文:

I have started learning Python and I want to record my sessions through Jupyter Notebooks used in VS Code, as well as to export them to PDF. However, I am unable to do so because it requires Latex and it does not seem to be so easy to install as a regular library such as numpy.

I get the following message when exporting to PDF via VS interface:

[error] If you have not installed xelatex (TeX) you will need to do so before you can export to PDF, for further instructions please look https://nbconvert.readthedocs.io/en/latest/install.html#installing-tex.To avoid installing xelatex (TeX) you might want to try exporting to HTML and using your browsers "Print to PDF" feature.

It also says I'm missing Pandoc although I have installed it via pip. (I believe this has to do with not having TeX). I have checked the link that shows up, but I don't know how to set up Latex in Windows. I have installed MikTex, and a couple extensions in VS (Latex and Latex Workshop). How can I install it successfully to be able to export to PDF?

When I open Miktex packages, I just get an empty console.

Also, I have used Latex online with Overleaf, and every time I wanted to include a package, I just used \includepackage{...}. Would this work in the same way in VS? Since it's not online I'm not sure if it would be that easy to download packages.

答案1

得分: 1

最后我不得不从官方网站安装Pandoc,然后将其位置添加到PATH。现在它可以工作了。

英文:

In the end I had to install Pandoc not from pip but from the official site, and then add its location to PATH. Now it works.

答案2

得分: 0

你是否已安装了正确的TeX库?

请按照文档中的步骤进行操作。

如果您使用的是Windows,您可以在这里下载。

如果您熟悉Git,还可以使用命令行或您喜欢的Git前端工具克隆存储库:

git clone https://github.com/latex3/latex2e.git
英文:

Do you have the correct tex library installed?

Please follow the step according to the document.

If you are using windows, you can download here.

If you are familiar with Git you can also clone the repository using the command line or your favorite Git fontend tool:

git clone  https://github.com/latex3/latex2e.git

答案3

得分: 0

> 为了避免安装 xelatex(TeX),您可以尝试将文件导出为HTML,然后使用浏览器的“打印为PDF”功能。

  • 在导出时选择HTML

    如何在VS Code中为Jupyter Notebook(Windows)设置Latex。

  • 用浏览器打开导出的 name.html 文件

  • 使用<kbd>Ctrl</kbd>+<kbd>P</kbd> 打开打印页面,然后使用 打印为PDF 选项导出为PDF文件

如果您仍然希望在Visual Studio Code中直接导出为PDF,您可以查看此答案,其中提供了详细的步骤。

英文:

> To avoid installing xelatex (TeX) you might want to try exporting to HTML and using your browsers "Print to PDF" feature.

  • select html when exporting

    如何在VS Code中为Jupyter Notebook(Windows)设置Latex。

  • Open the exported name.html file with a browser

  • <kbd>Ctrl</kbd>+<kbd>P</kbd> to open the printed page, use Print to PDF to export it as a pdf file

If you still want to export to pdf directly in vscode, you can check this answer, there are detailed steps.

huangapple
  • 本文由 发表于 2023年6月2日 13:18:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76387311.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定