centos 7 安装latex

服务器   发布日期:2025年07月13日   浏览次数:253

这里介绍两种不同的配置方法,一种是通过docker,一种是直接ISO进行安装,一种是直接yum install 安装,三种安装方法均需要使用root权限

参考博客:http://yxnchen.github.io/technique/Docker部署ShareLaTeX并简单配置中文环境/

参考博客 https://blog.csdn.net/com_stu_zhang/article/details/81381608

首先安装docker

  1. yum install docker
  2. systemctl start docker

安装docker镜像

  1. docker pull ubuntu:18.04

查看下载镜像

  1. docker image ls

docker run -it --rm ubuntu:18.04 bash

安装latex

  1. sudo apt-get install texlive texlive-science

安装中文语言包

  1. sudo apt-get install latex-cjk-chinese
  • 制作镜像

基于container

  1. exit 退出伪终端后
  2. docker container ls -a
  3. docker commit container-name image-name
  4. docker image ls

基于dockerfile

  1. FROM ubuntu:18.04
  2. MAINTAINER jeffray zhang
  3. RUN apt update
  4. RUN apt install -y vim
  5. RUN apt install -y texlive texlive-science latex-cjk-chinese

保存后执行命令生成新image
docker build -t jeffray/latex .

创建docker容器,将host的路径挂载到容器的目录下
docker run -it -v /home/jeffray/latex-workspace:/latex jeffray/latex /bin/bash

在host创建测试文件
/home/jeffray/latex-workspace/test/test.tex
文件内容

  1. \documentclass{article}
  2. \usepackage{CJK}
  3. \begin{document}
  4. \begin{CJK*}{UTF8}{gkai}
  5. 测试中文显示
  6. \end{CJK*}
  7. \end{document}

在容器中进行编译
启动容器 然后进去容器使用

  1. pdflatex test.tex

在centos 7 直接使用root安装texlive

  1. yum -y install texlive texlive-latex texlive-xetex
  2. yum -y install texlive-collection-latex
  3. yum -y install texlive-collection-latexrecommended
  4. yum -y install texlive-xetex-def
  5. yum -y install texlive-collection-xetex
  6. Only if needed:
  7. yum -y install texlive-collection-latexextra

参考博客https://www.cnblogs.com/dezheng/p/3874434.html

测试latex是否可用,创建文件test.tex

  1. \documentclass{article}
  2. \usepackage{CJKutf8}
  3. \begin{document}
  4. \begin{CJK}{UTF8}{gbsn}
  5. 这是一个CJKutf8的例子,使用的字体是gbsn
  6. \end{CJK}
  7. \end{document}

使用命令pdflatex可以进行编译,自带的字体只有gbsn(宋体)和gkai(楷体)

  1. pdflatex test.tex

本来想测试CTEX宏包,发现yum安装的texlive版本太低,不包含这些包,因此使用ISO镜像重新安装新版本

删除yum安装的texlive

  1. yum remove texlive texlive-latex texlive-xetex
  2. yum remove texlive-collection-latex
  3. yum remove texlive-collection-latexrecommended
  4. yum remove texlive-xetex-def
  5. yum remove texlive-collection-xetex
  6. Only if needed:
  7. yum remove texlive-collection-latexextra

下载ISO镜像

  1. wget http://mirrors.hust.edu.cn/CTAN/systems/texlive/Images/texlive2019-20190410.iso
  2. mount -o loop texlive2017-20170524.iso /mnt/
  3. cd /mnt
  4. ./install-t1

添加环境变量

  1. PATH=/usr/local/texlive/2017/bin/x86_64-linux:$PATH; export PATH
  2. MANPATH=/usr/local/texlive/2017/texmf-dist/doc/man:$MANPATH; export MANPATH
  3. INFOPATH=/usr/local/texlive/2017/texmf-dist/doc/info:$INFOPATH; export INFOPATH

xelatex编译测试

  1. \documentclass{article}
  2. \usepackage{CTEX}
  3. \begin{document}
  4. 这是一个CTEXutf-8编码例子,{\kaishu 这里是楷体显示},{\songti 这里是宋体显示},{\heiti 这里是黑体显示},{\fangsong 这里是仿宋显示}。
  5. \end{document}

pdflatex编译测试

  1. \documentclass[UTF8]{article}
  2. \usepackage{CTEX}
  3. \begin{document}
  4. 这是一个CTEXutf-8编码例子,{\kaishu 这里是楷体显示},{\songti 这里是宋体显示},{\heiti 这里是黑体显示},{\fangsong 这里是仿宋显示},{\lishu 这里是隶书显示},{\youyuan 这里是幼圆显示}。
  5. \end{document}

以上就是centos 7 安装latex的详细内容,更多关于centos 7 安装latex的资料请关注九品源码其它相关文章!