> 技术文档 > MacTex+Vscode数学建模排版_mactex vscode

MacTex+Vscode数学建模排版_mactex vscode


MacTex+Vscode数学建模排版

#CUMCM
数学建模之前是word排版,感觉Latex还是更高级和好看一些(虽然不熟练刚开始还是很费劲),再加上本人Mac小白,所以有了这篇文章,希望能解决一些MacTex环境配置问题。

参考了https://blog.csdn.net/Absurdaaa/article/details/142642404?spm=1001.2014.3001.5506,加了一些数模常用功能和测试样例,感恩原作者大大

涉及功能

  1. 字体配置符合国赛论文要求
  2. 实时预览
  3. 参考文献,图,三线表,代码框自动编号

下载链接

  • vscode:https://code.visualstudio.com/

  • MacTex: https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/mac/mactex/ (清华镜像园下载更快)
    MacTex+Vscode数学建模排版_mactex vscode

  • vscode插件:拓展LaTeX Workshop
    MacTex+Vscode数学建模排版_mactex vscode

JSON文档配置

  1. Command+option+p,搜索,settings.json
    MacTex+Vscode数学建模排版_mactex vscode

  2. 替换配置文件

    { \"terminal.integrated.inheritEnv\": false, //主题颜色修改 \"workbench.colorTheme\": \"Visual Studio Dark\", \"security.workspace.trust.untrustedFiles\": \"open\", \"python.defaultInterpreterPath\": \"/Users/yxk/anaconda3/bin/python\", \"notebook.output.textLineLimit\": 500, \"notebook.output.scrolling\": true, \"jupyter.askForKernelRestart\": false, \"explorer.compactFolders\": false, \"editor.language.brackets\": [], \"files.autoSave\": \"afterDelay\", \"[latex]\": { \"editor.quickSuggestions\": { \"comments\": \"on\", \"strings\": \"on\", \"other\": \"on\" } }, \"latex-workshop.latex.tools\": [ { \"name\": \"xelatex\", \"command\": \"xelatex\", \"args\": [ \"-synctex=1\", \"-interaction=nonstopmode\", \"-file-line-error\", \"-outdir=%OUTDIR%\", \"%DOC%\" ] }, { \"name\": \"bibtex\", \"command\": \"bibtex\", \"args\": [ \"%DOCFILE%\" ] }, { \"name\": \"rnw2tex\", \"command\": \"Rscript\", \"args\": [ \"-e\", \"knitr::opts_knit$set(concordance = TRUE); knitr::knit(\'%DOCFILE_EXT%\')\" ], \"env\": {} }, { \"name\": \"jnw2tex\", \"command\": \"julia\", \"args\": [ \"-e\", \"using Weave; weave(\\\"%DOC_EXT%\\\", doctype=\\\"tex\\\")\" ], \"env\": {} }, { \"name\": \"jnw2texminted\", \"command\": \"julia\", \"args\": [ \"-e\", \"using Weave; weave(\\\"%DOC_EXT%\\\", doctype=\\\"texminted\\\")\" ], \"env\": {} }, { \"name\": \"pnw2tex\", \"command\": \"pweave\", \"args\": [ \"-f\", \"tex\", \"%DOC_EXT%\" ], \"env\": {} }, { \"name\": \"pnw2texminted\", \"command\": \"pweave\", \"args\": [ \"-f\", \"texminted\", \"%DOC_EXT%\" ], \"env\": {} }, { \"name\": \"tectonic\", \"command\": \"tectonic\", \"args\": [ \"--synctex\", \"--keep-logs\", \"%DOC%.tex\" ], \"env\": {} } ], \"latex-workshop.latex.recipes\": [ { \"name\": \"xelatex -> bibtex -> xelatex*2\", \"tools\": [ \"xelatex\", \"bibtex\", \"xelatex\", \"xelatex\" ] } ], \"latex-workshop.latex.recipe.default\": \"xelatex -> bibtex -> xelatex*2\", \"workbench.editorAssociations\": { \"*.pdf\": \"latex-workshop-pdf-hook\" }, }
  3. 基础测试样例,在当前文件夹中创建test0.tex,绿箭头运行

    \\documentclass{article} \\usepackage[UTF8]{ctex} \\begin{document} this is very story 这是中英混合混合形式的 这是使用啥的字体 乱七八糟的 中文输入 \\end{document}

    MacTex+Vscode数学建模排版_mactex vscode

功能样例

  1. 参考文献的相关内容需要在当前文件夹新建一个refs.bib

    @book{lamport1994latex, title={LaTeX: A Document Preparation System}, author={Lamport, Leslie}, year={1994}, publisher={Addison-Wesley}}
  2. 替换test.tex,代码准备完成

    \\documentclass{article}\\usepackage[UTF8]{ctex}\\usepackage{cite}\\usepackage{graphicx}\\usepackage{float}\\usepackage{booktabs} % 三线表宏包\\usepackage{listings}\\usepackage{xcolor}\\renewcommand{\\lstlistingname}{代码} % 改为“代码”\\renewcommand{\\lstlistlistingname}{代码目录}% 代码样式设置\\lstset{ language=Python, basicstyle=\\ttfamily\\small, keywordstyle=\\color{blue}, commentstyle=\\color{gray}, stringstyle=\\color{red!70!black}, showstringspaces=false, numbers=left, numberstyle=\\tiny, breaklines=true, frame=single, captionpos=b}\\title{简单的中文 LaTeX 测试文档}\\author{作者姓名}\\date{\\today}\\begin{document}\\maketitle\\begin{abstract}本文是一个用于测试的简单 LaTeX 文档,包含摘要、二级标题、表格、图片和参考文献的示例。\\end{abstract}\\section{引言}这是引言部分。LaTeX 非常适合撰写学术论文,尤其是在需要中英文混排和公式编辑时。\\section{相关工作}\\subsection{二级标题示例}这里是一个二级标题的内容。我们可以在文中引用文献,例如~\\cite{lamport1994latex}。\\section{表格示例}表~\\ref{tab:sample} 展示了一个三线表。\\begin{table}[H] \\centering \\caption{三线表示例} \\label{tab:sample} \\begin{tabular}{ccc} \\toprule 姓名 & 年龄 & 城市 \\\\ \\midrule 张三 & 25 & 北京 \\\\ 李四 & 30 & 上海 \\\\ 王五 & 28 & 广州 \\\\ \\bottomrule \\end{tabular}\\end{table}\\section{图片示例}如图~\\ref{fig:sample} 所示,这是一张示例图片。\\begin{figure}[H] \\centering \\includegraphics[width=0.4\\textwidth]{example-image-a} \\caption{示例图片} \\label{fig:sample}\\end{figure}\\section{Python 代码示例}如代码~\\ref{lst:pyexample} 所示,这是一个简单的 Python 函数。\\begin{lstlisting}[language=Python, caption={计算斐波那契数列的函数}, label={lst:pyexample}]def fibonacci(n): \"\"\"返回斐波那契数列的前 n 项\"\"\" a, b = 0, 1 result = [] for _ in range(n): result.append(a) a, b = b, a + b return resultprint(fibonacci(10))\\end{lstlisting}\\section{结论}本文展示了一个简单的 LaTeX 文档结构。\\bibliographystyle{plain}\\bibliography{refs}\\end{document}
  3. command+option+p,检查一下,LaTeX Workshop是否是xelatex->bibtex->xelatex*2
    MacTex+Vscode数学建模排版_mactex vscode

  4. 测试结果
    MacTex+Vscode数学建模排版_mactex vscode