网上有教程怎么在vscode里安装macTex以及插件,然后就可以在latex里写代码了,这里需要修改的是对应的json文件,输入command + P,可以看到最近打开的json设置文件,结果如下
然后设置这个json文件,我的json文件设置如下
{
"terminal.integrated.inheritEnv": false,
"workbench.colorTheme": "Visual Studio Light",
"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": "latexmk",
"command": "latexmk",
//"args": [
//"-synctex=1",
//"-interaction=nonstopmode",
//"-file-line-error",
//"-pdf",
//"-outdir=%OUTDIR%",
//"%DOC%"
//],
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-xelatex",
"-outdir=%OUTDIR%",
"%DOC%"
],
"env": {}
},
{
"name": "lualatexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-lualatex",
"-outdir=%OUTDIR%",
"%DOC%"
],
"env": {}
},
{
"name": "xelatexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-xelatex",
"-outdir=%OUTDIR%",
"%DOC%"
],
"env": {}
},
{
"name": "latexmk_rconly",
"command": "latexmk",
"args": [
"%DOC%"
],
"env": {}
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
],
"env": {}
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
],
"env": {}
},
{
"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": {}
}
],
}
中文案例
\documentclass{article}
\usepackage[UTF8]{ctex}
\begin{document}
this is very story
这是中英混合混合形式的
这是使用啥的字体
一的第七章
中文输入
\end{document}
注意这里使用的是最简单的,没有进行任何字体的设置,因为接下来的是mac里面最重要的一个问题,字体和windows下不匹配的问题,这个需要我来尝试解决
中文案例2
\documentclass[12pt,UTF8]{ctexart}
%ctexrep - report ; ctexbook - book ; ctexart - article
\usepackage{xeCJK}
\setCJKmainfont{NotoSerifCJKsc-Bold}
\author{匿名}
\title{诗经}
\begin{document}
\maketitle
\begin{center}
\begin{Large}
\begin{verse}
关关雎鸠,在河之洲。窈窕淑女,君子好逑。\\
参差荇菜,左右流之。窈窕淑女,寤寐求之。\\
求之不得,寤寐思服。悠哉悠哉,辗转反侧。\\
参差荇菜,左右采之。窈窕淑女,琴瑟友之。\\
参差荇菜,左右芼之。窈窕淑女,钟鼓乐之。\\
\end{verse}
\end{Large}
\end{center}
\end{document}
结果如下
解决问题如下
安装字体
https://www.jianshu.com/p/fd96fb3daea1
然后需要修改第一句话,很奇怪
\documentclass{article}
%ctexrep - report ; ctexbook - book ; ctexart - article
\usepackage{xeCJK}
\setCJKmainfont{NotoSerifCJKsc-Bold}
\author{匿名}
\title{诗经}
\begin{document}
\maketitle
\begin{center}
\begin{Large}
\begin{verse}
关关雎鸠,在河之洲。窈窕淑女,君子好逑。\\
参差荇菜,左右流之。窈窕淑女,寤寐求之。\\
求之不得,寤寐思服。悠哉悠哉,辗转反侧。\\
参差荇菜,左右采之。窈窕淑女,琴瑟友之。\\
参差荇菜,左右芼之。窈窕淑女,钟鼓乐之。\\
\end{verse}
\end{Large}
\end{center}
\end{document}
但是结果是有的
所以目前有一个问题就是如果我换成
\documentclass[fontset=windows]{ctexart}
%ctexrep - report ; ctexbook - book ; ctexart - article
\usepackage{xeCJK}
\setCJKmainfont{NotoSerifCJKsc-Bold}
\author{匿名}
\title{诗经}
\begin{document}
\maketitle
\begin{center}
\begin{Large}
\begin{verse}
关关雎鸠,在河之洲。窈窕淑女,君子好逑。\\
参差荇菜,左右流之。窈窕淑女,寤寐求之。\\
求之不得,寤寐思服。悠哉悠哉,辗转反侧。\\
参差荇菜,左右采之。窈窕淑女,琴瑟友之。\\
参差荇菜,左右芼之。窈窕淑女,钟鼓乐之。\\
\end{verse}
\end{Large}
\end{center}
\end{document}
注意第一行我把\documentclass{article} 换成了\documentclass[fontset=windows]{ctexart}这个就会出现以下错误
Package fontspec: The font “SimSun” cannot be found.
首先注意下面这个文件,我看到很多教程里都提到这个ctex-fontset-windows.def和cls文件,但是都不说这些文件在哪里找,真的是说话说一半,我这里展示一下我找到的位置
https://blog.csdn.net/deng_sai/article/details/111383257
且备份一下这个ctex-fontset-windows.def文件,我的ctex-fontset-windows.def的原始内容是
%%
%% This is file `ctex-fontset-windows.def',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% ctex.dtx (with options: `fontset,windows')
%%
%% Copyright (C) 2003--2022
%% CTEX.ORG and any individual authors listed in the documentation.
%% ---------------------------------------------------------------------
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version. This version of this license is in
%% http://www.latex-project.org/lppl/lppl-1-3c.txt
%% and the latest version of this license is in
%% http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status "maintained".
%%
%% ---------------------------------------------------------------------
%%
\GetIdInfo$Id: ctex.dtx 13a2256 2022-07-14 18:54:09 +0800 Qing Lee <sobenlee@gmail.com> $
{Windows fonts definition (CTEX)}
\ProvidesExplFile{ctex-fontset-windows.def}
{\ExplFileDate}{2.5.10}{\ExplFileDescription}
\file_if_exist:nTF { \c_dollar_str WINDIR/Fonts/msyh.ttc }
{ \tl_const:Nn \c__ctex_msyh_suffix_tl { ttc } }
{
\file_if_exist:nTF { msyh.ttc }
{ \tl_const:Nn \c__ctex_msyh_suffix_tl { ttc } }
{ \tl_const:Nn \c__ctex_msyh_suffix_tl { ttf } }
}
\ctex_fontset_case:nnn
{
\ctex_zhmap_case:nnn
{
\ctex_punct_set:n { windows }
\setCJKmainfont { simsun.ttc }
[ BoldFont = simhei.ttf, ItalicFont = simkai.ttf ]
\setCJKsansfont { msyh.\c__ctex_msyh_suffix_tl }
[ BoldFont = msyhbd.\c__ctex_msyh_suffix_tl ]
\setCJKmonofont { simfang.ttf }
\setCJKfamilyfont { zhsong } { simsun.ttc }
\setCJKfamilyfont { zhhei } { simhei.ttf }
\setCJKfamilyfont { zhfs } { simfang.ttf }
\setCJKfamilyfont { zhkai } { simkai.ttf }
\setCJKfamilyfont { zhyahei } { msyh.\c__ctex_msyh_suffix_tl }
[ BoldFont = msyhbd.\c__ctex_msyh_suffix_tl ]
\setCJKfamilyfont { zhli } { simli.ttf }
\setCJKfamilyfont { zhyou } { simyou.ttf }
\ctex_punct_map_family:nn { \CJKrmdefault } { zhsong }
\ctex_punct_map_bfseries:nn { \CJKrmdefault } { zhhei }
\ctex_punct_map_itshape:nn { \CJKrmdefault } { zhkai }
\ctex_punct_map_family:nn { \CJKsfdefault } { zhyahei }
\ctex_punct_map_bfseries:nn { \CJKsfdefault, zhyahei } { zhyaheib }
\ctex_punct_map_family:nn { \CJKttdefault } { zhfs }
}
{
\ctex_load_zhmap:nnnn { rm } { zhhei } { zhfs } { windows }
\ctex_punct_set:n { windows }
\ctex_punct_map_family:nn { \CJKrmdefault } { zhsong }
\ctex_punct_map_bfseries:nn { \CJKrmdefault } { zhhei }
\ctex_punct_map_itshape:nn { \CJKrmdefault } { zhkai }
}
{ }
}
{
\ctex_set_upfonts:nnnnnn
{ simsun.ttc }
{ simhei.ttf }
{ simkai.ttf }
{ msyh.\c__ctex_msyh_suffix_tl }
{ msyhbd.\c__ctex_msyh_suffix_tl }
{ simfang.ttf }
\ctex_set_upfamily:nnn { zhsong } { upzhserif } {}
\ctex_set_upfamily:nnn { zhhei } { upzhserifb } {}
\ctex_set_upfamily:nnn { zhfs } { upzhmono } {}
\ctex_set_upfamily:nnn { zhkai } { upzhserifit } {}
\ctex_set_upfamily:nnn { zhyahei } { upzhsans } { upzhsansb }
\ctex_set_upfamily:nnn { zhli } { upschrm } {}
\ctex_set_upfamily:nnn { zhyou } { upschgt } {}
\ctex_set_upmap:nnn { upstsl } { simli.ttf } {}
\ctex_set_upmap:nnn { upstht } { simyou.ttf } {}
}
{
\setCJKmainfont { SimSun } [ BoldFont = SimHei , ItalicFont = KaiTi ]
\setCJKsansfont { Microsoft~YaHei } [ BoldFont = *~Bold ]
\setCJKmonofont { FangSong }
\setCJKfamilyfont { zhsong } { SimSun }
\setCJKfamilyfont { zhhei } { SimHei }
\setCJKfamilyfont { zhfs } { FangSong }
\setCJKfamilyfont { zhkai } { KaiTi }
\setCJKfamilyfont { zhyahei } { Microsoft~YaHei } [ BoldFont = *~Bold ]
\setCJKfamilyfont { zhli } { LiSu }
\setCJKfamilyfont { zhyou } { YouYuan }
}
\NewDocumentCommand \songti { } { \CJKfamily { zhsong } }
\NewDocumentCommand \heiti { } { \CJKfamily { zhhei } }
\NewDocumentCommand \fangsong { } { \CJKfamily { zhfs } }
\NewDocumentCommand \kaishu { } { \CJKfamily { zhkai } }
\NewDocumentCommand \lishu { } { \CJKfamily { zhli } }
\NewDocumentCommand \youyuan { } { \CJKfamily { zhyou } }
\NewDocumentCommand \yahei { } { \CJKfamily { zhyahei } }
%%
%%
%% End of file `ctex-fontset-windows.def'.
设置字体案例2
\documentclass[UTF8,nofonts]{ctexart}
\usepackage{xeCJK}
\title{中文测试}
\author{测试}
\date{\today}
% use buildin Chinese font in linux and Mac
\setCJKmainfont[BoldFont=FandolSong-Bold.otf,ItalicFont=FandolKai-Regular.otf]{FandolSong-Regular.otf}
\setCJKsansfont[BoldFont=FandolHei-Bold.otf]{FandolHei-Regular.otf}
\setCJKmonofont{FandolFang-Regular.otf}
\begin{document}\large
\section{中文}
中文测试,中文测试,中文测试。
\end{document}
结果如下
设置字体3
如果在tex文字中遇到以下代码
\setCJKmainfont{SimSun}
\setCJKsansfont{SimHei}
\setCJKmonofont{FangSong}
这种写法是windows下的,直接搬到mac下会报错的,我将这三行改成了文章来源:https://www.toymoban.com/news/detail-801540.html
\setCJKmainfont{STSong}%{SimSun}
\setCJKsansfont{STHeitiSC-Light}%{SimHei}
\setCJKmonofont{STFangsong}%{FangSong}
就可以在mac中正式运行了文章来源地址https://www.toymoban.com/news/detail-801540.html
到了这里,关于mac vscode latex实用的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!