PaperShow / install_tinytex.sh
JaceWei's picture
update
c643f73
#!/usr/bin/env bash
# ============================================================
# install_tinytex_xelatex.sh
# 一键安装 TinyTeX (用户级,无需 sudo)
# 适用于 beamer / fontspec / gemini / cam 海报编译
# ============================================================
set -e # 出错立即退出
WORKDIR=$(pwd)
echo "当前目录: $WORKDIR"
# ------------------------------------------------------------
# Step 0. 预清理旧残留
# ------------------------------------------------------------
echo "🧹 Step 0. 检查并清理旧 TinyTeX 安装或锁文件..."
if [ -d "$HOME/.TinyTeX" ]; then
echo "⚠️ 检测到已有 ~/.TinyTeX 目录,尝试安全删除..."
# 杀掉占用 .nfs 文件的进程
PIDS=$(lsof +D "$HOME/.TinyTeX" 2>/dev/null | awk 'NR>1 {print $2}' | sort -u)
if [ -n "$PIDS" ]; then
echo "🔪 结束占用进程: $PIDS"
kill -9 $PIDS 2>/dev/null || true
fi
# 强制删除旧目录
rm -rf "$HOME/.TinyTeX" 2>/dev/null || true
fi
# 清除当前目录下可能存在的 texlive 安装残留
rm -rf texlive install-tl* tinytex.profile 2>/dev/null || true
# ------------------------------------------------------------
# Step 1. 安装 TinyTeX
# ------------------------------------------------------------
echo "🚀 Step 1. 安装 TinyTeX 到用户目录 (~/.TinyTeX)..."
wget -qO- "https://yihui.org/tinytex/install-unx.sh" | sh
# ------------------------------------------------------------
# Step 2. 设置 PATH 环境变量
# ------------------------------------------------------------
echo "✅ 安装完成,设置 PATH 环境变量..."
export PATH=$HOME/.TinyTeX/bin/x86_64-linux:$PATH
# 写入 ~/.bashrc 方便以后使用
if ! grep -q ".TinyTeX/bin/x86_64-linux" ~/.bashrc; then
echo 'export PATH=$HOME/.TinyTeX/bin/x86_64-linux:$PATH' >> ~/.bashrc
echo "📝 已自动将 TinyTeX 路径写入 ~/.bashrc"
fi
# ------------------------------------------------------------
# Step 3. 检查 XeLaTeX 是否可用
# ------------------------------------------------------------
echo "🧩 Step 2. 检查 XeLaTeX 版本..."
if ! command -v xelatex >/dev/null 2>&1; then
echo "❌ XeLaTeX 未找到,安装可能失败,请检查 ~/.TinyTeX/bin 是否存在。"
exit 1
else
xelatex --version | head -n 2
fi
# ------------------------------------------------------------
# Step 4. 安装常用包
# ------------------------------------------------------------
echo "📦 Step 3. 安装必要的 LaTeX 包 (无 sudo)..."
tlmgr option repository http://mirror.ctan.org/systems/texlive/tlnet
tlmgr update --self --all --reinstall-forcibly-removed
tlmgr install \
beamer beamerposter fontspec xcolor pgfplots anyfontsize type1cm \
ragged2e changepage geometry booktabs natbib tikz fp
echo "✅ 所有包已安装。TinyTeX 可正常用于 XeLaTeX 海报编译。"
echo "👉 现在你可以运行:"
echo " xelatex poster_output.tex"