这里提供一种简单的latex绘图环境配置。
1.说明
-
使用tex绘图优势:
- 对于LLM来说,tex代码其实在日常训练里面能看到很多,所以我认为通过prompt让LLM生成tex代码的效果,应该比直接调用LLM绘图方便。(具体效果要看模型能力是code更好还是画图更好)
- 修改已完成的绘图,直接在tex上修改,比调整prompt让模型绘图,方便很多。
-
环境配置思路:
借助Tectonic,(conda环境配置)环境隔离,方便。
2.环境配置
-
创建基础环境:
1
conda create -n tikz_env python=3.9 -y
-
激活并安装
Tectonic:1
2
3
4
5# 2. 激活环境
conda activate tikz_env
# 3. 强制使用清华源直接安装 Tectonic (Rust 重写的现代 LaTeX 引擎)
conda install -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ tectonic -y -
验证:
1
2# 检查版本,确认安装成功
tectonic --version -
简单测试:
创建简单的tex文件,比如ex.tex:1
2
3
4
5
6
7
8
9
10
11
12\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{positioning, arrows.meta}
\begin{document}
\begin{tikzpicture}[
box/.style={draw, minimum width=2cm, minimum height=1cm, fill=blue!10, rounded corners},
arrow/.style={-Stealth, thick}
]
\node[box] (input) {Input};
\node[box, right=1cm of input] (output) {Output};
\draw[arrow] (input) -- (output);
\end{tikzpicture}
\end{document} -
编译命令:
1
tectonic ex.tex
会在当前目录下生成
ex.pdf
3.Prompt
这里提供我日常使用的prompt,正常的流程是使用下面的prompt+具体图像内容prompt。
1 | 你是一个顶级的 LaTeX 和 TikZ 绘图专家。请根据我提供的结构描述或 ASCII 草图,为我编写一版高质量、排版整洁的流程/架构图代码。 |