LaTeX之一:macos上latex环境搭建(homebrew安装+vscode配置+ MacTex)和B ...

农民  金牌会员 | 2025-2-21 07:00:17 | 来自手机 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 871|帖子 871|积分 2613

安装及配置

本机环境

本人为macos,已经安装了homebrew和vscode。希望得到的效果是在vscode中编辑并预览latex文件
MacTex安装

安装mactex

首先,使用brew安装MacTex(新版本的brew已经将install和install --cask合并了)
  1. brew install mactex
复制代码
安装后一样寻常会置于如下路径下:
  1. /usr/local/Caskroom/mactex/2024.xx.xx
复制代码
进入该路径看到一个pkg包,手动安装一下。
然后打开应用步伐的文件夹,看是否会出现TeX目录,目录下为如下软件:

也有可能不出现这个目录,目录下也不一定是这几个软件和文件。反正有TeXShop和LaTeXiT即可。
那么代表在本机安装LaTex乐成。
添加至系统路径

然后我们进入~/Library下看是否有TeX目录,目录下是否存在textbin。
假如存在,我们在终端的zshrc文件中加入该路径
  1. export PATH="/Library/TeX/texbin:$PATH"
复制代码
随后重启终端后分别输入如下命令。
  1. xelatex --version
  2. pdflatex --version
复制代码
能分别看到输出,即阐明我们将latex加入了系统路径中。
vscode配置

然后打开vscode,安装LaTex Workshop拓展并重启。
按住command + shift + p,选择首选项:打开用户设置(JSON) Preferences:Open User Settings (JSON)。添加如下内容:
  1. {
  2.         以前的内容...,
  3. "latex-workshop.latex.autoBuild.run": "never",
  4.     "latex-workshop.showContextMenu": true,
  5.     "latex-workshop.intellisense.package.enabled": true,
  6.     "latex-workshop.message.error.show": false,
  7.     "latex-workshop.message.warning.show": false,
  8.     "latex-workshop.latex.tools": [
  9.         {
  10.             "name": "xelatex",
  11.             "command": "xelatex",
  12.             "args": [
  13.                 "-synctex=1",
  14.                 "-interaction=nonstopmode",
  15.                 "-file-line-error",
  16.                 "%DOCFILE%"
  17.             ]
  18.         },
  19.         {
  20.             "name": "pdflatex",
  21.             "command": "pdflatex",
  22.             "args": [
  23.                 "-synctex=1",
  24.                 "-interaction=nonstopmode",
  25.                 "-file-line-error",
  26.                 "%DOCFILE%"
  27.             ]
  28.         },
  29.         {
  30.             "name": "latexmk",
  31.             "command": "latexmk",
  32.             "args": [
  33.                 "-synctex=1",
  34.                 "-interaction=nonstopmode",
  35.                 "-file-line-error",
  36.                 "-pdf",
  37.                 "-outdir=%OUTDIR%",
  38.                 "%DOCFILE%"
  39.             ]
  40.         },
  41.         {
  42.             "name": "bibtex",
  43.             "command": "bibtex",
  44.             "args": [
  45.                 "%DOCFILE%"
  46.             ]
  47.         }
  48.     ],
  49.     "latex-workshop.latex.recipes": [
  50.         {
  51.             "name": "XeLaTeX",
  52.             "tools": [
  53.                 "xelatex"
  54.             ]
  55.         },
  56.         {
  57.             "name": "PDFLaTeX",
  58.             "tools": [
  59.                 "pdflatex"
  60.             ]
  61.         },
  62.         {
  63.             "name": "BibTeX",
  64.             "tools": [
  65.                 "bibtex"
  66.             ]
  67.         },
  68.         {
  69.             "name": "LaTeXmk",
  70.             "tools": [
  71.                 "latexmk"
  72.             ]
  73.         },
  74.         {
  75.             "name": "xelatex -> bibtex -> xelatex*2",
  76.             "tools": [
  77.                 "xelatex",
  78.                 "bibtex",
  79.                 "xelatex",
  80.                 "xelatex"
  81.             ]
  82.         },
  83.         {
  84.             "name": "pdflatex -> bibtex -> pdflatex*2",
  85.             "tools": [
  86.                 "pdflatex",
  87.                 "bibtex",
  88.                 "pdflatex",
  89.                 "pdflatex"
  90.             ]
  91.         },
  92.     ],
  93.     "latex-workshop.latex.clean.fileTypes": [
  94.         "*.aux",
  95.         "*.bbl",
  96.         "*.blg",
  97.         "*.idx",
  98.         "*.ind",
  99.         "*.lof",
  100.         "*.lot",
  101.         "*.out",
  102.         "*.toc",
  103.         "*.acn",
  104.         "*.acr",
  105.         "*.alg",
  106.         "*.glg",
  107.         "*.glo",
  108.         "*.gls",
  109.         "*.ist",
  110.         "*.fls",
  111.         "*.log",
  112.         "*.fdb_latexmk"
  113.     ],
  114.     "latex-workshop.latex.autoClean.run": "onFailed",
  115.     "latex-workshop.latex.recipe.default": "lastUsed",
  116.     "latex-workshop.view.pdf.internal.synctex.keybinding": "double-click",
  117. }
复制代码
ctrl+s保存后我们重新打开vscode。
tex编写和验证

新建一个test.tex,输入一下内容
  1. \documentclass{article}
  2. \usepackage{amsmath}
  3. \title{A Simple \LaTeX{} Document}
  4. \author{Your Name}
  5. \date{\today}
  6. \begin{document}
  7. \maketitle
  8. \section{Introduction}
  9. Welcome to the world of \LaTeX{}! With \LaTeX{}, you can create beautifully formatted documents with ease. Here's a simple example of a \LaTeX{} document.
  10. \section{Mathematics}
  11. \LaTeX{} excels at typesetting mathematical equations. For example, here's the quadratic formula:
  12. \begin{equation}
  13.   x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
  14. \end{equation}
  15. \end{document}
复制代码
然后点击文件右上角的绿色三角形图标,意味着编译该文件。随后点击绿色三角形右边的图标,意味着检察编译后的pdf文件。

末了团体效果如下:

左边侧栏中的TEX还有更多功能和对应的图标,有爱好的话可以去看看。
(假如你已经打开了PDF预览窗口,LaTeX Workshop插件通常会在编译完成后自动革新PDF预览窗口)

此外,譬如点击了“构建LaTeX项目”后怎样看到什么时间构建完成,构建效果是什么,是否构建非常呢?
可以见页面最下方,会有命令执行的状态。譬如如下是“正在构建中”。

更详细的信息,可以见“输出”

假如显示类似于Process finished with exit code 0的消息,表示编译乐成完成。
相干推荐

B站入门视频

因为本人有编程基础,所以只看了一个视频(

网站

Overleaf:
https://www.overleaf.com/
简历模板:
https://www.overleaf.com/latex/templates/tagged/cv/page/6
公式预览:
https://latex.codecogs.com/eqneditor/editor.php
教程

入手Overleaf的教程:
https://blog.csdn.net/weixin_43301333/article/details/114374854

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

农民

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表