ipynb_to_pdf脚本
用于将
ipynb
文件转化为
- 需要自行安装依赖
- 仅适用于
ubuntu
,且ubuntu
安装了字体lmmono12-regular.otf
运行
仅支持在
ipynb
文件所在目录下运行
#添加运行权限
chmod +x ipynb_to_pdf.sh
./ipynb_to_pdf.sh ${your_ipynb_file_name}
# 假如你的文件为t.ipynb
./ipynb_to_pdf.sh t.ipynb
shell 源码
# /bin/bash
jupyter nbconvert --to latex $1
ipynb_path=$1
echo ${ipynb_path}
name_len=${#ipynb_path}
echo ${name_len}
name=${ipynb_path:0:name_len-6}
tex_path="${ipynb_path:0:name_len-6}".tex""
echo ${tex_path}
search_string="{article}" # 替换为要查找的字符串
text_to_append=" \usepackage{fontspec, xunicode, xltxtra}
\setmainfont{Ubuntu-R.ttf}
\usepackage{ctex}" # 替换为要添加的文字
awk -v search="$search_string" -v text="$text_to_append" '{
print
if ($0 ~ search && !added) {
print text
added = 1
}
}' "$tex_path" > temp && mv temp "$tex_path"
xelatex ${tex_path}
rm "${name}".log""
rm "${name}".out""
rm "${name}".tex""
rm "${name}".aux""
rm -rf "${name}"_files""