jupyter notebook 目录配置、导出 tex 和 pdf 及中文支持

本文介绍如何在Mac环境中使用Mactex和Pandoc实现Jupyter Notebook与LaTeX的格式转换,包括中文支持的配置过程。通过修改LaTeX模板和设置Jupyter Notebook的默认目录,可以方便地将Notebook导出为PDF或LaTeX文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境:macbook pro, mactex, jupyter notebook, brew

安装pandoc从而支持格式转换为tex:

brew install pandoc

修改tex article 模板,添加中文支持:

find / -name 'article.tplx' 2>/dev/null | xargs vi
# like .../nbconvert/templates/latex/article.tplx
# 或者分两条命令运行

修改Latex Article头部为:

%===============================================================================
% Latex Article
%===============================================================================

((* block docclass *))
\documentclass[11pt,adobefonts,fancyhdr,hyperref,UTF8]{article}
\usepackage{fontspec, xunicode, xltxtra}
\usepackage{ctex}      %中文支持
\setCJKmainfont{苹方-简}   %中文字体
((* endblock docclass *))

 (notebook标题似乎仍然不支持中文)

然后在jupyter notebook中直接下载为 pdf via LaTex即可自动得到pdf文件。或者下载为 latex(.tex) 再用 texshop -> xlatex 编译 亦可。

 

PS1: mark down 新手指南

PS2:jupyter notebook 设置默认目录方法

关闭notebook, 然后运行:

jupyter notebook --generate-config

# 生成config 文件, like /Users/xxx/.jupyter/jupyter_notebook_config.py

修改jupyter_notebook_config.py文件中 c.NotebookApp.notebook_dir 配置行:

## 用于笔记本和内核的目录。
c.NotebookApp.notebook_dir = '/Users/xxx/Projects/jupyter_workspace'

重启notebook即可

 

转载于:https://www.cnblogs.com/squirrel2300/p/9927679.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值