这里写目录标题
之前百度试过很多次都没有解决,后来有机会在Google上搜索了下,终于解决,现在记录如下
1. 下载和安装TexLive
2.安装VSCode
3.安装Latex Workshop插件
4.修改Late Workshop配置
使用 ctrl+shift+P 打开搜索,输入 “setting。json”。粘贴模板。
Ctrl+,打开VSCode设置页面,修改settings.json设置,下面是记录我使用的设置,能够使用,但是还是有一点问题,不想解决了可以直接复制过去,具体也不想分析了,后面提供相关链接
{
// Latex workshop
"latex-workshop.latex.tools": [
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOC%"
]
},
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],
"latex-workshop.latex.recipes": [
{
"name": "xelatex",
"tools": [
"xelatex"
]
},
{
"name": "latexmk",
"tools": [
"latexmk"
]
},
{
"name": "pdflatex -> bibtex -> pdflatex*2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
}
],
"latex-workshop.view.pdf.viewer": "tab",
"latex-workshop.latex.clean.fileTypes": [
"*.aux",
"*.bbl",
"*.blg",
"*.idx",
"*.ind",
"*.lof",
"*.lot",
"*.out",
"*.toc",
"*.acn",
"*.acr",
"*.alg",
"*.glg",
"*.glo",
"*.gls",
"*.ist",
"*.fls",
"*.log",
"*.fdb_latexmk"
]
}
注意这个虽然能使用,但是编译时还是会报错,此外这个配置也不涉及使用外部PDF打开文档,因为我懒的搞,等我用的多的时候在弄吧
设置内容解读参考
VSCode配置LaTeX Workstation以支持中文
文末有最新的配置文件,另外记得重启 电脑。
5.文档实例
我之前一直配置完成不能输出中文,很可能是因为**文档开头没有使用 \usepackage[UTF8]{ctex} **
%!TEX program = pdflatex
\documentclass{article}
\usepackage[UTF8]{ctex}
% 这里是导言区
\begin{document}
Hello, world !
fuck you latex
你好
中文呢
\end{document}
修改后的版本
{
// Latex workshop
"latex-workshop.latex.tools": [
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOC%"
]
},
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],
"latex-workshop.latex.recipes": [
{
"name": "xelatex",
"tools": [
"xelatex"
]
},
{
"name": "latexmk",
"tools": [
"latexmk"
]
},
{
"name": "pdflatex -> bibtex -> pdflatex*2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
}
],
"latex-workshop.view.pdf.viewer": "tab",
"latex-workshop.latex.clean.fileTypes": [
"*.aux",
"*.bbl",
"*.blg",
"*.idx",
"*.ind",
"*.lof",
"*.lot",
"*.out",
"*.toc",
"*.acn",
"*.acr",
"*.alg",
"*.glg",
"*.glo",
"*.gls",
"*.ist",
"*.fls",
"*.log",
"*.fdb_latexmk"
],
}
同样没有成功使用外部PDF阅读器
设置好用PDF阅读器打开生成文件
终于把PDF预览软件设置成外置的SumatraPDF, 2020年10月15日。
注意:
之前主要错误应该在于软件安装文件夹地址错误。直接复制过来的地址上使用的是 ‘\’,感觉这个在VScode中是转义字符标志,所以没有正确设置地址。应该使用 ‘/’, 或者使用‘\\’。此外有的教程中提到在SumatraPDF软件中进行设置,具体自行百度。
"latex-workshop.view.pdf.viewer": "external",
"latex-workshop.view.pdf.external.viewer.command": "C:/Program Files/SumatraPDF/SumatraPDF.exe", // 注意修改路径,这是SumatraPDF安装目录,注意使用‘/’, 在Windows中复制过来的地址是使用'/',这个会出问题,我觉得也可以使用'//'
"latex-workshop.view.pdf.external.viewer.args": [
"%PDF%"
],
"latex-workshop.view.pdf.external.synctex.command": "C:/Program Files/SumatraPDF/SumatraPDF.exe", // 注意修改路径
"latex-workshop.view.pdf.external.synctex.args": [
"-forward-search",
"%TEX%",
"%LINE%",
"-reuse-instance",
"-inverse-search",
"code \"C:\\Users\\CHEN\\AppData\\Local\\Programs\\Microsoft VS Code\\resources\\app\\out\\cli.js\" -r -g \"%f:%l\"", // 注意修改路径,注意文件路径中的‘\\’
"%PDF%",
],
配置文件20210129
打开配置文件: ctrl+shift+P
{
// Latex workshop
"latex-workshop.latex.tools": [
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOC%"
]
},
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],
"latex-workshop.latex.recipes": [
{
"name": "xelatex",
"tools": [
"xelatex"
]
},
{
"name": "latexmk",
"tools": [
"latexmk"
]
},
{
"name": "pdflatex",
"tools": [
"pdflatex"
]
},
{
"name": "bibtex",
"tools": [
"bibtex"
]
},
{
"name": "xelatex->bibtex->xelatex->xelatex",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex",
]
},
{
"name": "pdflatex -> bibtex -> pdflatex*2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
}
],
"latex-workshop.view.pdf.viewer": "external",
"latex-workshop.latex.clean.fileTypes": [
"*.aux",
"*.bbl",
"*.blg",
"*.idx",
"*.ind",
"*.lof",
"*.lot",
"*.out",
"*.toc",
"*.acn",
"*.acr",
"*.alg",
"*.glg",
"*.glo",
"*.gls",
"*.ist",
"*.fls",
"*.log",
"*.fdb_latexmk"
],
"editor.fontSize": 18,
"window.zoomLevel": -1,
"editor.wordWrap": "wordWrapColumn",
"ltex.dictionary": {
"en-US": [
"Acknowledgements",
"momerized"
]
},
"terminal.integrated.fontSize": 16,
// external pdf
"latex-workshop.view.pdf.viewer": "external",
"latex-workshop.view.pdf.external.viewer.command": "C:/Program Files/SumatraPDF/SumatraPDF.exe", // 注意修改路径
"latex-workshop.view.pdf.external.viewer.args": [
"%PDF%"
],
"latex-workshop.view.pdf.external.synctex.command": "C:/Program Files/SumatraPDF/SumatraPDF.exe", // 注意修改路径
"latex-workshop.view.pdf.external.synctex.args": [
"-forward-search",
"%TEX%",
"%LINE%",
"-reuse-instance",
"-inverse-search",
"code \"C:\\Users\\CHEN\\AppData\\Local\\Programs\\Microsoft VS Code\\resources\\app\\out\\cli.js\" -r -g \"%f:%l\"", // 注意修改路径
"%PDF%",
],
// English grammer check
"ltex.enabled": true, // 启用插件
"ltex.language": "en-US",// 设置语言,这里是德语
// 要英语就下载对应 English Support,然后这里填 en, 或者 en-US,en-GB 等*/
}
别人的
别人的一份设置
使用VSCode编写LaTeX
如果编译出错,插件会弹出两个很烦人的气泡,不喜欢的话可以在设置中添加以下代码:
"latex-workshop.message.error.show": false,
"latex-workshop.message.warning.show": false,
主设置
// LaTeX
"latex-workshop.latex.autoBuild.run": "never",
"latex-workshop.message.error.show": false,
"latex-workshop.message.warning.show": false,
"latex-workshop.latex.tools": [
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOCFILE%"
]
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOCFILE%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],
"latex-workshop.latex.recipes": [
{
"name": "xelatex",
"tools": [
"xelatex"
],
},
{
"name": "pdflatex",
"tools": [
"pdflatex"
]
},
{
"name": "xe->bib->xe->xe",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex"
]
},
{
"name": "pdf->bib->pdf->pdf",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
}
],
"latex-workshop.view.pdf.viewer": "external",
"latex-workshop.view.pdf.external.viewer.command": "C:/.../SumatraPDF.exe",
"latex-workshop.view.pdf.external.viewer.args": [
"-forward-search",
"%TEX%",
"%LINE%",
"-reuse-instance",
"-inverse-search",
"\"C:/.../Microsoft VS Code/Code.exe\" \"C:/.../Microsoft VS Code/resources/app/out/cli.js\" -gr \"%f\":\"%l\"",
"%PDF%"
],
"latex-workshop.view.pdf.external.synctex.command": "C:/.../SumatraPDF.exe",
"latex-workshop.view.pdf.external.synctex.args": [
"-forward-search",
"%TEX%",
"%LINE%",
"-reuse-instance",
"-inverse-search",
"\"C:/.../Microsoft VS Code/Code.exe\" \"C:/.../Microsoft VS Code/resources/app/out/cli.js\" -gr \"%f\":\"%l\"",
"%PDF%",
],
配置文件20220112
前面的反向搜索失败,感觉应该是VScode更新的原因,找了好久,需要在反向搜索中添加 --ms-enable-electron-run-as-node
{
// Latex workshop
"latex-workshop.latex.tools": [
// 编译工具和命令
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOCFILE%"
]
},
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOCFILE%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],
"latex-workshop.latex.recipes": [
{
"name": "pdflatex",
"tools": [
"pdflatex"
]
},
{
"name": "pdf->bib->pdf->pdf",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
},
{
"name": "xelatex",
"tools": [
"xelatex"
],
},
{
"name": "xe->bib->xe->xe",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex"
]
}
],
//文件清理。此属性必须是字符串数组
"latex-workshop.latex.clean.fileTypes": [
"*.aux",
"*.bbl",
"*.blg",
"*.idx",
"*.ind",
"*.lof",
"*.lot",
"*.out",
"*.toc",
"*.acn",
"*.acr",
"*.alg",
"*.glg",
"*.glo",
"*.gls",
"*.ist",
"*.fls",
"*.log",
"*.fdb_latexmk"
],
//设置为onFaild 在构建失败后清除辅助文件
// "latex-workshop.latex.autoClean.run": "onFailed",
"latex-workshop.latex.autoClean.run": "onBuilt",
// 使用上次的recipe编译组合
"latex-workshop.latex.recipe.default": "lastUsed",
// 用于反向同步的内部查看器的键绑定。ctrl/cmd +点击(默认)或双击
"latex-workshop.view.pdf.internal.synctex.keybinding": "double-click",
"latex-workshop.view.pdf.viewer": "external",
"latex-workshop.view.pdf.external.viewer.command": "D:\\Program Files\\SumatraPDF\\SumatraPDF.exe",
"latex-workshop.view.pdf.external.viewer.args": [
"-forward-search",
"%TEX%",
"%LINE%",
"-reuse-instance",
"-inverse-search",
"\"D:/Program Files/Microsoft VS Code/Code.exe\" \"D:/Program Files/Microsoft VS Code/resources/app/out/cli.js\" -gr \"%f\":\"%l\"",
"%PDF%"
],
// "latex-workshop.view.pdf.external.viewer.args": [
// "-forward-search",
// "%TEX%",
// "%LINE%",
// "-reuse-instance",
// "-inverse-search",
// "\"D:\\Program Files\\Microsoft VS Code\\Code.exe\" \"D:\\Program Files\\Microsoft VS Code\\resources\\app\\out\\cli.js\" -gr \"%f\":\"%l\"",
// "%PDF%"
// ],
"latex-workshop.view.pdf.external.synctex.command": "D:\\Program Files\\SumatraPDF\\SumatraPDF.exe",
"latex-workshop.view.pdf.external.synctex.args": [
"-forward-search",
"%TEX%",
"%LINE%",
"-reuse-instance",
"-inverse-search",
"\"D:\\Program Files\\Microsoft VS Code\\Code.exe\" \"D:\\Program Files\\Microsoft VS Code\\resources\\app\\out\\cli.js\" --ms-enable-electron-run-as-node -r -g \"%f:%l\"",
"%PDF%"
],
// English grammer check
"ltex.enabled": true, // 启用插件
"ltex.language": "en-US",
"workbench.colorTheme": "Monokai High Contrast", // 设置语言,这里是德语
// 要英语就下载对应 English Support,然后这里填 en, 或者 en-US,en-GB 等*/
// 取消右下角错误报警弹窗
"latex-workshop.message.error.show": false,
"latex-workshop.message.warning.show": false,
"diffEditor.wordWrap": "off",
"editor.fontSize": 17,
"security.workspace.trust.untrustedFiles": "open",
"editor.wordWrap": "on",
"update.mode": "none",
"extensions.autoUpdate": false,
"update.showReleaseNotes": false,
"update.enableWindowsBackgroundUpdates": false,
"javascript.updateImportsOnFileMove.enabled": "never",
"typescript.updateImportsOnFileMove.enabled": "never",
"extensions.autoCheckUpdates": false,
"markdown.preview.scrollPreviewWithEditor": false,
"markdown.preview.scrollEditorWithPreview": false,
"latex-workshop.intellisense.update.aggressive.enabled": true,
}
20240129 配置文件
新增 错误警告等底色
{
// Latex workshop
"latex-workshop.latex.tools": [
// compile
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOCFILE%"
]
},
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOCFILE%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],
"latex-workshop.latex.recipes": [
{
"name": "pdflatex",
"tools": [
"pdflatex"
]
},
{
"name": "pdf->bib->pdf->pdf",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
},
{
"name": "xelatex",
"tools": [
"xelatex"
],
},
{
"name": "xe->bib->xe->xe",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex"
]
}
],
//clean
"latex-workshop.latex.clean.fileTypes": [
"*.aux",
"*.bbl",
"*.blg",
"*.idx",
"*.ind",
"*.lof",
"*.lot",
"*.out",
"*.toc",
"*.acn",
"*.acr",
"*.alg",
"*.glg",
"*.glo",
"*.gls",
"*.ist",
"*.fls",
"*.log",
"*.fdb_latexmk"
],
//clean files on failed
"latex-workshop.latex.autoClean.run": "onFailed",
// "latex-workshop.latex.autoClean.run": "onBuilt",
// adopt last recipt
"latex-workshop.latex.recipe.default": "lastUsed",
//
"latex-workshop.view.pdf.internal.synctex.keybinding": "double-click",
"latex-workshop.view.pdf.viewer": "external",
"latex-workshop.view.pdf.external.viewer.command": "D:\\Program Files\\SumatraPDF\\SumatraPDF.exe",
"latex-workshop.view.pdf.external.viewer.args": [
"-forward-search",
"%TEX%",
"%LINE%",
"-reuse-instance",
"-inverse-search",
"\"D:/Program Files/Microsoft VS Code/Code.exe\" \"D:/Program Files/Microsoft VS Code/resources/app/out/cli.js\" -gr \"%f\":\"%l\"",
"%PDF%"
],
// "latex-workshop.view.pdf.external.viewer.args": [
// "-forward-search",
// "%TEX%",
// "%LINE%",
// "-reuse-instance",
// "-inverse-search",
// "\"D:\\Program Files\\Microsoft VS Code\\Code.exe\" \"D:\\Program Files\\Microsoft VS Code\\resources\\app\\out\\cli.js\" -gr \"%f\":\"%l\"",
// "%PDF%"
// ],
"latex-workshop.view.pdf.external.synctex.command": "D:\\Program Files\\SumatraPDF\\SumatraPDF.exe",
"latex-workshop.view.pdf.external.synctex.args": [
"-forward-search",
"%TEX%",
"%LINE%",
"-reuse-instance",
"-inverse-search",
"\"D:\\Program Files\\Microsoft VS Code\\Code.exe\" \"D:\\Program Files\\Microsoft VS Code\\resources\\app\\out\\cli.js\" --ms-enable-electron-run-as-node -r -g \"%f:%l\"",
"%PDF%"
],
// foxit
// "latex-workshop.view.pdf.viewer": "external",
// "latex-workshop.view.pdf.external.viewer.command":"D:\\Program Files (x86)\\Foxit Software\\Foxit PhantomPDF\\FoxitPhantomPDF.exe",
// "latex-workshop.view.pdf.external.viewer.args": ["%PDF%","/A", "nolock=1"],
// English grammer check
"ltex.enabled": true,
"ltex.language": "en-US",
"workbench.colorTheme": "Monokai High Contrast",
// cancel pop up message box
"latex-workshop.message.error.show": false,
"latex-workshop.message.warning.show": false,
"latex-workshop.showContextMenu": true,
"latex-workshop.intellisense.update.aggressive.enabled": true,
"diffEditor.wordWrap": "off",
"editor.fontSize": 19,
"security.workspace.trust.untrustedFiles": "open",
"editor.wordWrap": "on",
"update.mode": "none",
"extensions.autoUpdate": "onlySelectedExtensions",
"update.showReleaseNotes": false,
"update.enableWindowsBackgroundUpdates": false,
"javascript.updateImportsOnFileMove.enabled": "never",
"typescript.updateImportsOnFileMove.enabled": "never",
"extensions.autoCheckUpdates": false,
"markdown.preview.scrollPreviewWithEditor": false,
"markdown.preview.scrollEditorWithPreview": false,
"editor.accessibilitySupport": "off",
// highlight
"workbench.colorCustomizations": {
// highlight
"editor.selectionBackground": "#f0f70e" ,
"editor.selectionHighlightBackground": "#b8a621",
//
"editor.lineHighlightBackground": "#282828",
// "editor.lineHighlightBorder": "#FFFF00",
// "editor.wordHighlightBackground": "#ff0000",
// "editor.wordHighlightBorder": "#ff0000",
// "editor.worldHighlightStrongBackground": "#ff0000",
// "editor.wordHighlightStrongBorder": "#ff0000",
// errors, warnings, infos
"editorError.background": "#ffff0097",
"editorError.foreground": "#ff0000",
"editorWarning.background": "#181818",
"editorWarning.foreground": "#FFFF00",
"editorInfo.background": "#181818",
"editorInfo.foreground": "#73ff00",
"list.errorForeground": "#ff0000",
// "minimap.warningHighlight": "#ff0000"
// "editorOverviewRuler.warningForeground": "#ff0000"
// "statusBarItem.warningBackground": "#ff0000"
// "editor.inlineValuesBackground": "#ff0000"
// "editorMarkerNavigation.background": "#ff0000"
// "testing.message.info.decorationForeground": "#ff0000",
// "testing.message.error.lineBackground": "#ff0000"
// "descriptionForeground": "#ff0000"
},
"window.zoomLevel": 1,
"editor.scrollPredominantAxis": false,
"editor.quickSuggestions": {
"comments": "inline",
"strings": "inline"
},
"editor.quickSuggestionsDelay": 5,
"terminal.integrated.shellIntegration.suggestEnabled": true,
"editor.inlineSuggest.suppressSuggestions": true,
"editor.suggest.shareSuggestSelections": true,
"git.openRepositoryInParentFolders": "never",
"emmet.showSuggestionsAsSnippets": true,
"editor.snippetSuggestions": "top",
}